Ver Fonte

Продолжение чистки кода и начало реализации функционала обновлений игрового клиента.

Vieraw há 6 meses atrás
pai
commit
da7e7b94b3

+ 5 - 3
LauncherIcarus/Daemon/Configuration.cs

@@ -4,9 +4,9 @@
     {
         public static readonly Configuration Default = new Configuration()
         {
-            ServerIp = "http://192.168.183.129:5000",
-            LoginUrl = "/api/LoginAction",
-            ListFileUrl = "/api/LauncherListDownloadFiles",
+            ServerIp = "https://icarus.quissa.pw",
+            LoginUrl = "/api/login",
+            ListFileUrl = "/api/GameListDownloadFiles",
             LauncherNewsUrl = "/LauncherIndex",
             CheckClientFiles = "/api/CheckClientFiles",
             GetLauncherVersion = "/api/getLauncherVersion",
@@ -15,6 +15,7 @@
             DownloadUpdateFileUrl = "/DownloadFiles/",
             GetTranslate = "/api/GetTranslate",
             LauncherDir = "./Launcher/",
+            CheckLauncherVersion = "/api/CheckLauncherVersion",
             DownloadDir = "./DownloadFiles/"
         };
 
@@ -31,6 +32,7 @@
         public string GetLauncherVersion { get; set; }
 
         public string LauncherDir { get; set; }
+        public string CheckLauncherVersion { get; set; }
 
         public string DownloadDir { get; set; }
 

+ 33 - 48
LauncherIcarus/Daemon/EncryptionHelper.cs

@@ -7,34 +7,36 @@ namespace LauncherIcarus.Daemon
 {
     public static class EncryptionHelper
     {
+        private const string Password = "N1PEUPQX";
+
+        private static Rfc2898DeriveBytes Rfc2898DeriveBytes { get; } = new Rfc2898DeriveBytes(Password, new byte[]
+        {
+            73,
+            118,
+            97,
+            110,
+            32,
+            77,
+            101,
+            100,
+            118,
+            101,
+            100,
+            101,
+            118
+        });
+
         public static string Encrypt(string clearText)
         {
-            string password = "N1PEUPQX";
-            byte[] bytes = Encoding.Unicode.GetBytes(clearText);
-            using (Aes aes = Aes.Create())
+            var bytes = Encoding.Unicode.GetBytes(clearText);
+            using (var aes = Aes.Create())
             {
-                Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, new byte[13]
+                aes.Key = Rfc2898DeriveBytes.GetBytes(32);
+                aes.IV = Rfc2898DeriveBytes.GetBytes(16);
+                using (var memoryStream = new MemoryStream())
                 {
-                    (byte) 73,
-                    (byte) 118,
-                    (byte) 97,
-                    (byte) 110,
-                    (byte) 32,
-                    (byte) 77,
-                    (byte) 101,
-                    (byte) 100,
-                    (byte) 118,
-                    (byte) 101,
-                    (byte) 100,
-                    (byte) 101,
-                    (byte) 118
-                });
-                aes.Key = rfc2898DeriveBytes.GetBytes(32);
-                aes.IV = rfc2898DeriveBytes.GetBytes(16);
-                using (MemoryStream memoryStream = new MemoryStream())
-                {
-                    using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, aes.CreateEncryptor(),
-                               CryptoStreamMode.Write))
+                    using (var cryptoStream =
+                           new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
                     {
                         cryptoStream.Write(bytes, 0, bytes.Length);
                         cryptoStream.Close();
@@ -49,33 +51,16 @@ namespace LauncherIcarus.Daemon
 
         public static string Decrypt(string cipherText)
         {
-            string password = "N1PEUPQX";
             cipherText = cipherText.Replace(" ", "+");
-            byte[] buffer = Convert.FromBase64String(cipherText);
-            using (Aes aes = Aes.Create())
+            var buffer = Convert.FromBase64String(cipherText);
+            using (var aes = Aes.Create())
             {
-                Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, new byte[13]
-                {
-                    (byte) 73,
-                    (byte) 118,
-                    (byte) 97,
-                    (byte) 110,
-                    (byte) 32,
-                    (byte) 77,
-                    (byte) 101,
-                    (byte) 100,
-                    (byte) 118,
-                    (byte) 101,
-                    (byte) 100,
-                    (byte) 101,
-                    (byte) 118
-                });
-                aes.Key = rfc2898DeriveBytes.GetBytes(32);
-                aes.IV = rfc2898DeriveBytes.GetBytes(16);
-                using (MemoryStream memoryStream = new MemoryStream())
+                aes.Key = Rfc2898DeriveBytes.GetBytes(32);
+                aes.IV = Rfc2898DeriveBytes.GetBytes(16);
+                using (var memoryStream = new MemoryStream())
                 {
-                    using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, aes.CreateDecryptor(),
-                               CryptoStreamMode.Write))
+                    using (var cryptoStream =
+                           new CryptoStream(memoryStream, aes.CreateDecryptor(), CryptoStreamMode.Write))
                     {
                         cryptoStream.Write(buffer, 0, buffer.Length);
                         cryptoStream.Close();

+ 1 - 1
LauncherIcarus/Daemon/FileConfig.cs

@@ -19,7 +19,7 @@ namespace LauncherIcarus.Daemon
         public void SetLauncherIsChecked(string text) =>
             File.WriteAllText(_launcherVersionSetting, text + Environment.NewLine);
 
-        public string GetLauncherIsChecked() => File.Exists(this._launcherVersionSetting)
+        public string GetLauncherIsChecked() => File.Exists(_launcherVersionSetting)
             ? File.ReadAllText(_launcherVersionSetting).Replace("\r\n", string.Empty)
             : "FALSE";
 

+ 72 - 75
LauncherIcarus/Daemon/HTTP/HttpRequest.cs

@@ -1,6 +1,10 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using System.Net;
 using System.Net.Http;
+using System.Security.Authentication;
 using System.Threading.Tasks;
+using Newtonsoft.Json;
 
 namespace LauncherIcarus.Daemon.HTTP
 {
@@ -11,10 +15,7 @@ namespace LauncherIcarus.Daemon.HTTP
         private readonly string _getLauncherVersionUrl =
             Configuration.Default.ServerIp + Configuration.Default.GetLauncherVersion;
 
-        private readonly string _updateLauncherVersionUrl =
-            Configuration.Default.ServerIp + Configuration.Default.UpdateLauncherVersion;
-
-        private readonly string _getLauncherFilesUrl =
+        private readonly string _getUpdatesListUrl =
             Configuration.Default.ServerIp + Configuration.Default.ListFileUrl;
 
         private readonly string _checkClientFiles =
@@ -22,61 +23,81 @@ namespace LauncherIcarus.Daemon.HTTP
 
         private readonly string _getTranslate = Configuration.Default.ServerIp + Configuration.Default.GetTranslate;
 
+        private readonly string _checkLauncherVersion =
+            Configuration.Default.ServerIp + Configuration.Default.CheckLauncherVersion;
+
+        private readonly HttpClient _client = new HttpClient(new HttpClientHandler
+        {
+            SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13
+        });
+
         public async Task<string> LoginAsync(string accountName, string password)
         {
-            string str;
             using (var content = new FormUrlEncodedContent(new Dictionary<string, string>
                    {
                        {
-                           "Username",
+                           "name",
                            accountName
                        },
                        {
-                           "Password",
+                           "password",
                            password
                        }
                    }))
             {
-                using (var client = new HttpClient())
+                try
                 {
-                    str = await (await client.PostAsync(_loginUrl, content))
+                    return await (await _client.PostAsync(_loginUrl, content))
                         .Content
                         .ReadAsStringAsync();
                 }
+                catch (Exception exception)
+                {
+                    Logger.WriteLog(exception.Message, nameof(LoginAsync));
+                    return exception.Message;
+                }
             }
 
-            return str;
-        }
+            var json = JsonConvert.SerializeObject(new Dictionary<string, string>
+            {
+                {
+                    "name",
+                    accountName
+                },
+                {
+                    "password",
+                    password
+                }
+            });
 
-        public async Task<string> GetLauncherVersionAsync(string token, string username)
-        {
-            string launcherVersionAsync;
-            using (var content = new FormUrlEncodedContent(new Dictionary<string, string>
-                   {
-                       {
-                           nameof(token),
-                           token
-                       },
-                       {
-                           nameof(username),
-                           username
-                       }
-                   }))
+            try
             {
-                using (var client = new HttpClient())
+                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 |
+                                                       SecurityProtocolType.Tls12;
+                var request = (HttpWebRequest)WebRequest.Create(_loginUrl);
+                request.Method = "POST";
+                request.ContentType = "application/json";
+
+                using (var streamWriter = new System.IO.StreamWriter(request.GetRequestStream()))
                 {
-                    launcherVersionAsync = await (await client.PostAsync(_getLauncherVersionUrl, content))
-                        .Content
-                        .ReadAsStringAsync();
+                    await streamWriter.WriteAsync(json);
                 }
-            }
 
-            return launcherVersionAsync;
+                var response = (HttpWebResponse)request.GetResponse();
+                using (var streamReader = new System.IO.StreamReader(response.GetResponseStream()))
+                {
+                    return await streamReader.ReadToEndAsync();
+                }
+            }
+            catch (Exception exception)
+            {
+                Logger.WriteLog(exception.Message, nameof(LoginAsync));
+                return exception.Message;
+            }
         }
 
-        public async Task<string> UpdateLauncherVersionAsync(string token, string updatedVersion, string username)
+        public async Task<string> GetLauncherVersionAsync(string token, string username)
         {
-            string str;
             using (var content = new FormUrlEncodedContent(new Dictionary<string, string>
                    {
                        {
@@ -86,53 +107,33 @@ namespace LauncherIcarus.Daemon.HTTP
                        {
                            nameof(username),
                            username
-                       },
-                       {
-                           "UpdaterVersion",
-                           updatedVersion
                        }
                    }))
             {
-                using (var client = new HttpClient())
-                {
-                    str = await (await client.PostAsync(_updateLauncherVersionUrl, content))
-                        .Content
-                        .ReadAsStringAsync();
-                }
+                return await (await _client.PostAsync(_getLauncherVersionUrl, content))
+                    .Content
+                    .ReadAsStringAsync();
             }
-
-            return str;
         }
 
-        public async Task<string> GetLauncherListFilesAsync(string token, string clientVersion)
+        public async Task<string> GetUpdatesListAsync(string clientVersion)
         {
-            string launcherListFilesAsync;
             using (var content = new FormUrlEncodedContent(new Dictionary<string, string>
                    {
-                       {
-                           nameof(token),
-                           token
-                       },
                        {
                            nameof(clientVersion),
                            clientVersion
                        }
                    }))
             {
-                using (var client = new HttpClient())
-                {
-                    launcherListFilesAsync = await (await client.PostAsync(_getLauncherFilesUrl, content))
-                        .Content
-                        .ReadAsStringAsync();
-                }
+                return await (await _client.PostAsync(_getUpdatesListUrl, content))
+                    .Content
+                    .ReadAsStringAsync();
             }
-
-            return launcherListFilesAsync;
         }
 
         public async Task<string> GetClientFilesCheckListAsync(string token)
         {
-            string filesCheckListAsync;
             using (var content = new FormUrlEncodedContent(new Dictionary<string, string>
                    {
                        {
@@ -141,26 +142,22 @@ namespace LauncherIcarus.Daemon.HTTP
                        }
                    }))
             {
-                using (var client = new HttpClient())
-                {
-                    filesCheckListAsync = await (await client.PostAsync(_checkClientFiles, content))
-                        .Content
-                        .ReadAsStringAsync();
-                }
+                return await (await _client.PostAsync(_checkClientFiles, content))
+                    .Content
+                    .ReadAsStringAsync();
             }
-
-            return filesCheckListAsync;
         }
 
         public async Task<string> GetLauncherTranslateAsync()
         {
-            string launcherTranslateAsync;
-            using (var client = new HttpClient())
-            {
-                launcherTranslateAsync = await (await client.GetAsync(_getTranslate)).Content.ReadAsStringAsync();
-            }
+            return await (await _client.GetAsync(_getTranslate)).Content.ReadAsStringAsync();
+        }
 
-            return launcherTranslateAsync;
+        public async Task<string> GetLauncherFileAsync()
+        {
+            return await (await _client.GetAsync(_checkLauncherVersion))
+                .Content
+                .ReadAsStringAsync();
         }
     }
 }

+ 8 - 8
LauncherIcarus/Daemon/Logger.cs

@@ -3,11 +3,11 @@ using System.IO;
 
 namespace LauncherIcarus.Daemon
 {
-    public class Logger
+    public static class Logger
     {
-        public static void WriteLog(string strLog)
+        public static void WriteLog(string strLog, string method)
         {
-            string path = "./Logger";
+            var path = "./Logger";
             Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "Top-Level Folder");
             Directory.CreateDirectory(path);
             string str = path + "/Log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".txt";
@@ -16,13 +16,13 @@ namespace LauncherIcarus.Daemon
             if (!directoryInfo.Exists)
                 directoryInfo.Create();
             StreamWriter streamWriter = new StreamWriter(fileInfo.Exists
-                ? (Stream) new FileStream(str, FileMode.Append)
-                : (Stream) fileInfo.Create());
+                ? (Stream)new FileStream(str, FileMode.Append)
+                : (Stream)fileInfo.Create());
             streamWriter.WriteLine("\r\nLog Entry : ");
-            streamWriter.WriteLine("{0} {1}", (object) DateTime.Now.ToLongTimeString(),
-                (object) DateTime.Now.ToLongDateString());
+            streamWriter.WriteLine("{0} {1}", (object)DateTime.Now.ToLongTimeString(),
+                (object)DateTime.Now.ToLongDateString());
             streamWriter.WriteLine("  :");
-            streamWriter.WriteLine("  :{0}", (object) strLog);
+            streamWriter.WriteLine("  {0}:{1}", method, (object)strLog);
             streamWriter.WriteLine("-------------------------------");
             streamWriter.Close();
         }

+ 1 - 1
LauncherIcarus/LauncherIcarus.csproj

@@ -7,7 +7,7 @@
     <ProjectGuid>{1C762126-981C-4830-A940-E1C6A0E00BCE}</ProjectGuid>
     <OutputType>WinExe</OutputType>
     <AssemblyName>LauncherIcarus</AssemblyName>
-    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
     <ApplicationVersion>1.0.0.0</ApplicationVersion>
     <FileAlignment>512</FileAlignment>
     <RootNamespace>LauncherIcarus</RootNamespace>

+ 45 - 51
LauncherIcarus/MainWindow.xaml.cs

@@ -50,22 +50,23 @@ namespace LauncherIcarus
                 _mainViewModel.IsLogged = false;
                 _mainViewModel.Lang = _fileConfig.GetLanguage();
                 DataContext = _mainViewModel;
-                wbSlide.Navigate(Configuration.Default.ServerIp + Configuration.Default.LauncherNewsUrl);
-                AccountModel.Username = _fileConfig.GetUsername();
+                // wbSlide.Navigate(Configuration.Default.ServerIp + Configuration.Default.LauncherNewsUrl);
+                wbSlide.Navigate("https://fw-rebirth.com/pacherslideshow2020.php");
+                AccountModel.Name = _fileConfig.GetUsername();
                 _currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
                 _parentDirectory = _currentDirectory.Parent;
 
-                if (AccountModel.Username != "")
+                if (AccountModel.Name != "")
                 {
-                    textUsername.Text = AccountModel.Username;
+                    textUsername.Text = AccountModel.Name;
                 }
 
                 if (!File.Exists("LauncherVersionSetting"))
                 {
-                    _fileConfig.SetLauncherIsChecked(EncryptionHelper.Encrypt("FALSE"));
+                    _fileConfig.SetLauncherIsChecked("FALSE");
                 }
 
-                if (EncryptionHelper.Decrypt(this._fileConfig.GetLauncherIsChecked()) != "FALSE")
+                if (_fileConfig.GetLauncherIsChecked() != "FALSE")
                 {
                     return;
                 }
@@ -75,16 +76,16 @@ namespace LauncherIcarus
                     throw new DirectoryNotFoundException();
                 }
 
-                Process.Start(new ProcessStartInfo
-                {
-                    WorkingDirectory = _parentDirectory.FullName,
-                    FileName = "LauncherUpdater.exe",
-                    CreateNoWindow = false
-                });
+                // Process.Start(new ProcessStartInfo
+                // {
+                // WorkingDirectory = _parentDirectory.FullName,
+                // FileName = "LauncherUpdater.exe",
+                // CreateNoWindow = false
+                // });
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(Initialize));
             }
         }
 
@@ -102,13 +103,13 @@ namespace LauncherIcarus
                 );
                 if (responseLogin?.Code == 0)
                 {
-                    _fileConfig.SetUsername(responseLogin.AccountInfo.Username);
+                    _fileConfig.SetUsername(responseLogin.AccountInfo.Name);
                     AccountModel.Token = responseLogin.Token;
-                    AccountModel.Username = responseLogin.AccountInfo.Username;
-                    AccountModel.Version = responseLogin.AccountInfo.Version;
+                    AccountModel.Name = responseLogin.AccountInfo.Name;
+                    AccountModel.Lang = responseLogin.AccountInfo.Language;
                     _fileConfig.SetLauncherIsChecked(EncryptionHelper.Encrypt("FALSE"));
                     lblWellcome.Visibility = Visibility.Visible;
-                    lblWellcome.Content = "Seja bem vindo " + AccountModel.Username;
+                    lblWellcome.Content = "Seja bem vindo " + AccountModel.Name;
                     lblMsgStatus.Visibility = Visibility.Hidden;
                     inputUsername.Visibility = Visibility.Hidden;
                     inputPassword.Visibility = Visibility.Hidden;
@@ -125,7 +126,7 @@ namespace LauncherIcarus
             catch (Exception ex)
             {
                 lblMsgStatus.Content = ex.Message;
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(buttonAccess_Click));
             }
         }
 
@@ -158,16 +159,12 @@ namespace LauncherIcarus
                     Directory.CreateDirectory(Configuration.Default.DownloadDir);
                 }
 
-                //TODO: Проверка версии лаунчера выглядит как бесполезная.
-                var getVersionResponse = JsonConvert.DeserializeObject<ResponseLauncherVersion>(
-                    await httpRequest.GetLauncherVersionAsync(AccountModel.Token, AccountModel.Username)
-                );
-                var getLauncherListResponse = JsonConvert.DeserializeObject<ResponseListLauncherFiles>(
-                    await httpRequest.GetLauncherListFilesAsync(
-                        AccountModel.Token, $"{getVersionResponse?.UpdaterVersion}"
-                    )
+                var clientVersion = 1 ;
+                var getUpdatesListResponse = JsonConvert.DeserializeObject<ResponseListLauncherFiles>(
+                    await httpRequest.GetUpdatesListAsync($"{clientVersion}")
                 );
-                if (getLauncherListResponse?.TotalBytes > 0.0)
+                // if (getUpdatesListResponse?.TotalBytes > 0.0)
+                if (getUpdatesListResponse?.Files.Count > 0)
                 {
                     var totalDownloaded = 0.0;
                     mainWindow.progressBar.Width = 0.0;
@@ -177,9 +174,9 @@ namespace LauncherIcarus
                     mainWindow.lblFileDownloading.Visibility = Visibility.Visible;
                     mainWindow.lblFileDownloadingName.Visibility = Visibility.Visible;
                     var lastVersion = 0;
-                    var clientVersion = getVersionResponse?.UpdaterVersion;
-                    mainWindow.lblTotalQtd.Content = Math.Round(getLauncherListResponse.TotalBytes / 1024.0, 2) + "MB";
-                    foreach (var file in getLauncherListResponse.File)
+                    // mainWindow.lblTotalQtd.Content = Math.Round(getUpdatesListResponse.TotalBytes / 1024.0, 2) + "MB";
+                    mainWindow.lblTotalQtd.Content = Math.Round(1000 / 1024.0, 2) + "MB";
+                    foreach (var file in getUpdatesListResponse.Files)
                     {
                         lastVersion = (int)file.Version;
                         double num1;
@@ -191,7 +188,8 @@ namespace LauncherIcarus
                             lblAtualQtd.Content = str;
                         }
 
-                        var num3 = file.Size / getLauncherListResponse.TotalBytes * 656.0;
+                        // var num3 = file.Size / getUpdatesListResponse.TotalBytes * 656.0;
+                        var num3 = file.Size / 1000 * 656.0;
                         totalDownloaded += file.Size;
                         mainWindow.progressBar.Width += (int)num3;
                         mainWindow.ExtractFiles();
@@ -200,13 +198,6 @@ namespace LauncherIcarus
                         var str1 = num1 + "MB";
                         totalAtualizadoQtd.Content = str1;
                     }
-
-                    //TODO: Запись версии лаунчера выглядит как бесполезная.
-                    JsonConvert.DeserializeObject<ResponseLauncherVersion>(
-                        await httpRequest.UpdateLauncherVersionAsync(
-                            AccountModel.Token, lastVersion.ToString(), AccountModel.Username
-                        )
-                    );
                 }
 
                 mainWindow._mainViewModel.IsUpdating = false;
@@ -221,7 +212,7 @@ namespace LauncherIcarus
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(GetUpdate));
             }
         }
 
@@ -238,17 +229,18 @@ namespace LauncherIcarus
                     await mainWindow._httpRequest.GetClientFilesCheckListAsync(AccountModel.Token)
                 );
 
-                if (get?.TotalBytes > 0.0)
+                // if (get?.TotalBytes > 0.0)
                 {
                     var lblTotalQtd = mainWindow.lblTotalQtd;
-                    var num1 = Math.Round(get.TotalBytes / 1024.0, 2);
+                    // var num1 = Math.Round(get.TotalBytes / 1024.0, 2);
+                    var num1 = Math.Round(1000 / 1024.0, 2);
                     var str1 = num1 + "MB";
                     lblTotalQtd.Content = str1;
                     mainWindow.lblDownloadSpeed.Visibility = Visibility.Visible;
                     mainWindow.lblDownloadSpeedQtd.Visibility = Visibility.Visible;
                     mainWindow.lblFileDownloading.Visibility = Visibility.Visible;
                     mainWindow.lblFileDownloadingName.Visibility = Visibility.Visible;
-                    foreach (var k in get.File)
+                    foreach (var k in get.Files)
                     {
                         var filename = k.Filename;
                         var empty = string.Empty;
@@ -283,7 +275,8 @@ namespace LauncherIcarus
                         }
 
                         totalDownloaded += k.Size;
-                        var num5 = k.Size / get.TotalBytes * 656.0;
+                        // var num5 = k.Size / get.TotalBytes * 656.0;
+                        var num5 = k.Size / 1000 * 656.0;
                         var totalAtualizadoQtd = mainWindow.lblTotalAtualizadoQtd;
                         num1 = Math.Round(totalDownloaded / 1024.0, 2);
                         var str3 = num1 + "MB";
@@ -304,7 +297,7 @@ namespace LauncherIcarus
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(CheckClientFiles));
             }
         }
 
@@ -351,7 +344,7 @@ namespace LauncherIcarus
                 }
 
                 fileName = downloadPath + strArray[num2 + 1].Replace("/", "\\");
-                Logger.WriteLog(filename);
+                Logger.WriteLog(filename, nameof(DownloadArchiveAsync));
             }
             else
             {
@@ -400,7 +393,7 @@ namespace LauncherIcarus
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(ExtractFiles));
             }
         }
 
@@ -416,7 +409,8 @@ namespace LauncherIcarus
                 var folder = _parentDirectory.FullName.Replace("Launcher", "");
                 var sw = new StreamWriter(folder + @"\start.bat");
                 sw.WriteLine(
-                    $"cd {folder} && start Bin64/Launcher.exe /i:{AccountModel.Token} /r:123456 /O /u:3913056 /m:P");
+                    $"cd \"{folder}\" && start Bin64/Launcher.exe /i:{AccountModel.Token} /r:123456 /O /u:3913056 /m:P"
+                );
                 sw.Close();
                 var param = folder + @"\start.bat";
                 Process.Start(param);
@@ -425,7 +419,7 @@ namespace LauncherIcarus
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(buttonStart_Click));
             }
         }
 
@@ -454,7 +448,7 @@ namespace LauncherIcarus
                     var listLauncherFiles = JsonConvert.DeserializeObject<ResponseListLauncherFiles>(
                         await httpRequest.GetLauncherTranslateAsync()
                     );
-                    if (listLauncherFiles?.TotalBytes > 0.0)
+                    // if (listLauncherFiles?.TotalBytes > 0.0)
                     {
                         var totalDownloaded = 0.0;
                         mainWindow.progressBar.Width = 0.0;
@@ -463,7 +457,7 @@ namespace LauncherIcarus
                         mainWindow.lblDownloadSpeedQtd.Visibility = Visibility.Visible;
                         mainWindow.lblFileDownloading.Visibility = Visibility.Visible;
                         mainWindow.lblFileDownloadingName.Visibility = Visibility.Visible;
-                        foreach (var file in listLauncherFiles.File)
+                        foreach (var file in listLauncherFiles.Files)
                         {
                             if (file.Filename != mainWindow._mainViewModel.Lang.ToLower() + ".zip")
                             {
@@ -510,7 +504,7 @@ namespace LauncherIcarus
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(ex.Message);
+                Logger.WriteLog(ex.Message, nameof(cmbLanguage_DropDownClosed));
             }
         }
     }

+ 1 - 5
LauncherIcarus/Model/AccountModel.cs

@@ -2,12 +2,8 @@
 {
     public static class AccountModel
     {
-        public static string Username { get; set; }
-
+        public static string Name { get; set; }
         public static string Token { get; set; }
-
-        public static string Version { get; set; }
-
         public static string Lang { get; set; }
     }
 }

+ 4 - 16
LauncherIcarus/Properties/Resources.cs

@@ -15,27 +15,15 @@ namespace LauncherIcarus.Properties
         private static ResourceManager resourceMan;
         private static CultureInfo resourceCulture;
 
-        internal Resources()
-        {
-        }
-
         [EditorBrowsable(EditorBrowsableState.Advanced)]
-        internal static ResourceManager ResourceManager
-        {
-            get
-            {
-                if (LauncherIcarus.Properties.Resources.resourceMan == null)
-                    LauncherIcarus.Properties.Resources.resourceMan = new ResourceManager(
-                        "LauncherIcarus.Properties.Resources", typeof(LauncherIcarus.Properties.Resources).Assembly);
-                return LauncherIcarus.Properties.Resources.resourceMan;
-            }
-        }
+        internal static ResourceManager ResourceManager => resourceMan ?? (resourceMan =
+            new ResourceManager("LauncherIcarus.Properties.Resources", typeof(Resources).Assembly));
 
         [EditorBrowsable(EditorBrowsableState.Advanced)]
         internal static CultureInfo Culture
         {
-            get => LauncherIcarus.Properties.Resources.resourceCulture;
-            set => LauncherIcarus.Properties.Resources.resourceCulture = value;
+            get => resourceCulture;
+            set => resourceCulture = value;
         }
     }
 }

+ 5 - 23
LauncherIcarus/ResponseModel/AccountInfo.cs

@@ -4,28 +4,10 @@ namespace LauncherIcarus.ResponseModel
 {
     public class AccountInfo
     {
-        [JsonProperty("AccountDBID")] public int AccountDBID { get; set; }
-
-        [JsonProperty("Username")] public string Username { get; set; }
-
-        [JsonProperty("RegisterTime")] public string RegisterTime { get; set; }
-
-        [JsonProperty("RegisterIP")] public string RegisterIp { get; set; }
-
-        [JsonProperty("LastLoginTime")] public string LastLoginTime { get; set; }
-
-        [JsonProperty("LastLoginIP")] public string LastLoginIp { get; set; }
-
-        [JsonProperty("IsBlocked")] public int IsBlocked { get; set; }
-
-        [JsonProperty("Real_Balance")] public double RealBalance { get; set; }
-
-        [JsonProperty("Bonus_Balance")] public double BonusBalance { get; set; }
-
-        [JsonProperty("BirthDate")] public string BirthDate { get; set; }
-
-        [JsonProperty("Email")] public string Email { get; set; }
-
-        [JsonProperty("Version")] public string Version { get; set; }
+        [JsonProperty("id")] public int Id { get; set; }
+        [JsonProperty("name")] public string Name { get; set; }
+        [JsonProperty("email")] public string Email { get; set; }
+        [JsonProperty("lang")] public string Language { get; set; }
+        [JsonProperty("create_at")] public string RegisterTime { get; set; }
     }
 }

+ 0 - 4
LauncherIcarus/ResponseModel/Files.cs

@@ -5,13 +5,9 @@ namespace LauncherIcarus.ResponseModel
     public class Files
     {
         [JsonProperty("filename")] public string Filename { get; set; }
-
         [JsonProperty("url")] public string Url { get; set; }
-
         [JsonProperty("version")] public long Version { get; set; }
-
         [JsonProperty("size")] public double Size { get; set; }
-
         [JsonProperty("crc32")] public string Crc32 { get; set; }
     }
 }

+ 2 - 4
LauncherIcarus/ResponseModel/ResponseListLauncherFiles.cs

@@ -3,10 +3,8 @@ using System.Collections.Generic;
 
 namespace LauncherIcarus.ResponseModel
 {
-    internal class ResponseListLauncherFiles
+    public class ResponseListLauncherFiles
     {
-        [JsonProperty("totalBytes")] public double TotalBytes { get; set; }
-
-        [JsonProperty("files")] public List<Files> File { get; set; }
+        [JsonProperty("files")] public List<Files> Files { get; set; }
     }
 }

+ 2 - 2
LauncherIcarus/ResponseModel/ResponseLogin.cs

@@ -8,8 +8,8 @@ namespace LauncherIcarus.ResponseModel
 
         [JsonProperty("msg")] public string Message { get; set; }
 
-        [JsonProperty("token")] public string Token { get; set; }
+        [JsonProperty("game_login_token")] public string Token { get; set; }
 
-        [JsonProperty("accountinfo")] public AccountInfo AccountInfo { get; set; }
+        [JsonProperty("info")] public AccountInfo AccountInfo { get; set; }
     }
 }

+ 0 - 18
LauncherUpdater/Function/Configuration.cs

@@ -1,18 +0,0 @@
-namespace LauncherUpdater.Function
-{
-    public class Configuration
-    {
-        public static readonly Configuration Default = new Configuration
-        {
-            ServerIp = "191.96.224.202",
-            LauncherDir = "./Launcher/",
-            CheckLauncherVersion = "/api/CheckLauncherVersion"
-        };
-
-        public string ServerIp { get; set; }
-
-        public string LauncherDir { get; set; }
-
-        public string CheckLauncherVersion { get; set; }
-    }
-}

+ 0 - 93
LauncherUpdater/Function/EncryptionHelper.cs

@@ -1,93 +0,0 @@
-using System;
-using System.IO;
-using System.Security.Cryptography;
-using System.Text;
-
-namespace LauncherUpdater.Function
-{
-    public static class EncryptionHelper
-    {
-        public static string Encrypt(string clearText)
-        {
-            const string password = "N1PEUPQX";
-            var bytes = Encoding.Unicode.GetBytes(clearText);
-            using (var aes = Aes.Create())
-            {
-                var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, new byte[]
-                {
-                    73,
-                    118,
-                    97,
-                    110,
-                    32,
-                    77,
-                    101,
-                    100,
-                    118,
-                    101,
-                    100,
-                    101,
-                    118
-                });
-                aes.Key = rfc2898DeriveBytes.GetBytes(32);
-                aes.IV = rfc2898DeriveBytes.GetBytes(16);
-                using (var memoryStream = new MemoryStream())
-                {
-                    using (
-                        var cryptoStream = new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write)
-                    )
-                    {
-                        cryptoStream.Write(bytes, 0, bytes.Length);
-                        cryptoStream.Close();
-                    }
-
-                    clearText = Convert.ToBase64String(memoryStream.ToArray());
-                }
-            }
-
-            return clearText;
-        }
-
-        public static string Decrypt(string cipherText)
-        {
-            const string password = "N1PEUPQX";
-            cipherText = cipherText.Replace(" ", "+");
-            var buffer = Convert.FromBase64String(cipherText);
-            using (var aes = Aes.Create())
-            {
-                var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, new byte[]
-                {
-                    73,
-                    118,
-                    97,
-                    110,
-                    32,
-                    77,
-                    101,
-                    100,
-                    118,
-                    101,
-                    100,
-                    101,
-                    118
-                });
-                aes.Key = rfc2898DeriveBytes.GetBytes(32);
-                aes.IV = rfc2898DeriveBytes.GetBytes(16);
-                using (var memoryStream = new MemoryStream())
-                {
-                    using (
-                        var cryptoStream = new CryptoStream(memoryStream, aes.CreateDecryptor(), CryptoStreamMode.Write)
-                    )
-                    {
-                        cryptoStream.Write(buffer, 0, buffer.Length);
-                        cryptoStream.Close();
-                    }
-
-                    cipherText = Encoding.Unicode.GetString(memoryStream.ToArray());
-                }
-            }
-
-            return cipherText;
-        }
-    }
-}

+ 0 - 17
LauncherUpdater/Function/FileConfig.cs

@@ -1,17 +0,0 @@
-using System;
-using System.IO;
-
-namespace LauncherUpdater.Function
-{
-    public class FileConfig
-    {
-        private string _launcherVersionSetting = nameof(_launcherVersionSetting);
-
-        public void SetLauncherIsChecked(string text) =>
-            File.WriteAllText("./Launcher/" + _launcherVersionSetting, text + Environment.NewLine);
-
-        public string GetLauncherIsChecked() => File.Exists(_launcherVersionSetting)
-            ? File.ReadAllText("./Launcher/" + _launcherVersionSetting).Replace("\r\n", string.Empty)
-            : "FALSE";
-    }
-}

+ 0 - 35
LauncherUpdater/Function/Logger.cs

@@ -1,35 +0,0 @@
-using System;
-using System.IO;
-
-namespace LauncherUpdater.Function
-{
-    public class Logger
-    {
-        public static void WriteLog(string strLog)
-        {
-            var path = Configuration.Default.LauncherDir + nameof(Logger);
-            Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "Top-Level Folder");
-            Directory.CreateDirectory(path);
-            var str = path + "/Log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".txt";
-            var fileInfo = new FileInfo(str);
-            var directoryInfo = new DirectoryInfo(fileInfo.DirectoryName);
-            if (!directoryInfo.Exists)
-            {
-                directoryInfo.Create();
-            }
-
-            var streamWriter =
-                new StreamWriter(fileInfo.Exists ? new FileStream(str, FileMode.Append) : fileInfo.Create());
-            streamWriter.WriteLine("\r\nLog Entry : ");
-            var now = DateTime.Now;
-            var longTimeString = now.ToLongTimeString();
-            now = DateTime.Now;
-            var longDateString = now.ToLongDateString();
-            streamWriter.WriteLine("{0} {1}", longTimeString, longDateString);
-            streamWriter.WriteLine("  :");
-            streamWriter.WriteLine("  :{0}", strLog);
-            streamWriter.WriteLine("-------------------------------");
-            streamWriter.Close();
-        }
-    }
-}

+ 0 - 25
LauncherUpdater/HTTP/HttpRequest.cs

@@ -1,25 +0,0 @@
-using LauncherUpdater.Function;
-using System.Net.Http;
-using System.Threading.Tasks;
-
-namespace LauncherUpdater.HTTP
-{
-    public class HttpRequest
-    {
-        private readonly string _checkLauncherVersion =
-            Configuration.Default.ServerIp + Configuration.Default.CheckLauncherVersion;
-
-        public async Task<string> GetLauncherFileAsync()
-        {
-            string launcherFileAsync;
-            using (var client = new HttpClient())
-            {
-                launcherFileAsync = await (await client.GetAsync(_checkLauncherVersion))
-                    .Content
-                    .ReadAsStringAsync();
-            }
-
-            return launcherFileAsync;
-        }
-    }
-}

+ 7 - 8
LauncherUpdater/LauncherUpdater.csproj

@@ -7,7 +7,7 @@
     <ProjectGuid>{3626DC35-20ED-476A-B9A3-047B88C5FCB9}</ProjectGuid>
     <OutputType>WinExe</OutputType>
     <AssemblyName>LauncherUpdater</AssemblyName>
-    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
     <ApplicationVersion>1.0.0.0</ApplicationVersion>
     <FileAlignment>512</FileAlignment>
     <RootNamespace>LauncherUpdater</RootNamespace>
@@ -66,13 +66,6 @@
     <Compile Include="App.cs" />
     <Compile Include="Properties\Resources.cs" />
     <Compile Include="Properties\Settings.cs" />
-    <Compile Include="HTTP\HttpRequest.cs" />
-    <Compile Include="Response\ResponseListLauncherFiles.cs" />
-    <Compile Include="Response\Files.cs" />
-    <Compile Include="Function\EncryptionHelper.cs" />
-    <Compile Include="Function\FileConfig.cs" />
-    <Compile Include="Function\Configuration.cs" />
-    <Compile Include="Function\Logger.cs" />
     <Compile Include="MainWindow.xaml.cs">
       <DependentUpon>mainwindow.xaml</DependentUpon>
       <SubType>Code</SubType>
@@ -98,5 +91,11 @@
   <ItemGroup>
     <Folder Include="obj\Debug" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\LauncherIcarus\LauncherIcarus.csproj">
+      <Project>{1c762126-981c-4830-a940-e1c6a0e00bce}</Project>
+      <Name>LauncherIcarus</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 8 - 9
LauncherUpdater/MainWindow.xaml.cs

@@ -1,16 +1,15 @@
-using LauncherUpdater.Function;
-using LauncherUpdater.HTTP;
-using LauncherUpdater.Response;
+using LauncherIcarus.ResponseModel;
 using Newtonsoft.Json;
 using System;
 using System.Diagnostics;
 using System.IO;
-using System.IO.Hashing;
 using System.Linq;
 using System.Net;
 using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Markup;
+using LauncherIcarus.Daemon;
+using LauncherIcarus.Daemon.HTTP;
+using Crc32 = System.IO.Hashing.Crc32;
 
 namespace LauncherUpdater
 {
@@ -46,7 +45,7 @@ namespace LauncherUpdater
                 var launcherFiles = JsonConvert.DeserializeObject<ResponseListLauncherFiles>(
                     await _httpRequest.GetLauncherFileAsync()
                 );
-                if (launcherFiles?.TotalBytes > 0.0)
+                // if (launcherFiles?.TotalBytes > 0.0)
                 {
                     foreach (var file in launcherFiles.Files)
                     {
@@ -72,8 +71,8 @@ namespace LauncherUpdater
                             await DownloadAsync(file.Filename, Configuration.Default.LauncherDir, file.Url);
                         }
 
-                        var num3 = file.Size / launcherFiles.TotalBytes * 370.0;
-                        ProgressBar.Width += Math.Round(num3, 0);
+                        // var num3 = file.Size / launcherFiles.TotalBytes * 370.0;
+                        // ProgressBar.Width += Math.Round(num3, 0);
                     }
                 }
 
@@ -88,7 +87,7 @@ namespace LauncherUpdater
             }
             catch (Exception ex)
             {
-                Logger.WriteLog(Application.Current + " : " + ex.Message);
+                Logger.WriteLog(Application.Current + " : " + ex.Message, nameof(CheckLauncherFiles));
                 Environment.Exit(0);
             }
         }

+ 0 - 17
LauncherUpdater/Response/Files.cs

@@ -1,17 +0,0 @@
-using Newtonsoft.Json;
-
-namespace LauncherUpdater.Response
-{
-    public class Files
-    {
-        [JsonProperty("filename")] public string Filename { get; set; }
-
-        [JsonProperty("url")] public string Url { get; set; }
-
-        [JsonProperty("version")] public long Version { get; set; }
-
-        [JsonProperty("size")] public double Size { get; set; }
-
-        [JsonProperty("crc32")] public string Crc32 { get; set; }
-    }
-}

+ 0 - 12
LauncherUpdater/Response/ResponseListLauncherFiles.cs

@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-using System.Collections.Generic;
-
-namespace LauncherUpdater.Response
-{
-    internal class ResponseListLauncherFiles
-    {
-        [JsonProperty("totalBytes")] public double TotalBytes { get; set; }
-
-        [JsonProperty("files")] public List<Files> Files { get; set; }
-    }
-}