From db5a1cff631ef4613761a75ad7f6d6d4e59db912 Mon Sep 17 00:00:00 2001 From: Crudelis Date: Fri, 10 Feb 2023 17:20:25 +0900 Subject: [PATCH] Update Module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 백신 회피를 위한 런처 수정 --- CommonLibrary/Packer.cs | 8 ++++- .../Updater/LauncherUpdate.cs | 25 ++++++++++++--- Mitria_Minecraft_Updater/Program.cs | 31 ++++++++++++------- Mitria_Minecraft_Updater/Settings.cs | 16 +++++----- 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/CommonLibrary/Packer.cs b/CommonLibrary/Packer.cs index a324596..b512509 100644 --- a/CommonLibrary/Packer.cs +++ b/CommonLibrary/Packer.cs @@ -114,13 +114,19 @@ namespace CommonLibrary { using (Stream outputStream = File.OpenWrite(fileName)) { + Stream progressStream = new ProgressStream(outputStream, null, new BasicProgress(i => { currentBytes += i; - progress.Report(currentBytes / totalBytes); + if (progress != null) + { + progress.Report(currentBytes / totalBytes); + } })); + inputStream.CopyTo(progressStream); + } File.SetLastWriteTime(fileName, entry.LastWriteTime.LocalDateTime); } diff --git a/Mitria_Minecraft_Launcher/Updater/LauncherUpdate.cs b/Mitria_Minecraft_Launcher/Updater/LauncherUpdate.cs index 5e9439c..5fe5789 100644 --- a/Mitria_Minecraft_Launcher/Updater/LauncherUpdate.cs +++ b/Mitria_Minecraft_Launcher/Updater/LauncherUpdate.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using CommonLibrary; namespace Mitria_Minecraft_Launcher.Updater @@ -22,6 +23,9 @@ namespace Mitria_Minecraft_Launcher.Updater CommonLibrary.Log.INFO("Launcher Version : " + thisVersion); CommonLibrary.Log.INFO("Remote Launcher Version : " + remoteVersion); int result = remoteVersion.CompareTo(thisVersion); +#if DEBUG +result =1; +#endif if (result <= 0) { CommonLibrary.Log.INFO("Version Same"); @@ -37,13 +41,24 @@ namespace Mitria_Minecraft_Launcher.Updater } string downloadUrl = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, launcherPatchInformation.LauncherUrl, launcherPatchInformation.LauncherFileName); - string newLauncherFile = CommonLibrary.Extensions.PathCombineW(tempDirectory, launcherPatchInformation.LauncherFileName); - downloader.DownloadFile(downloadUrl, newLauncherFile); - string launcherFile = System.Reflection.Assembly.GetExecutingAssembly().Location; - string oldLauncherFile = CommonLibrary.Extensions.PathCombineW(tempDirectory, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + "_old"); + string launcherPackFile = CommonLibrary.Extensions.PathCombineW(tempDirectory, launcherPatchInformation.LauncherFileName); + downloader.DownloadFile(downloadUrl, launcherPackFile); + string launcherFile = System.Reflection.Assembly.GetExecutingAssembly().Location; + string launcherPath = System.IO.Path.GetDirectoryName(launcherFile); + + // 기존 파일 파일명 변경후 temp 디렉토리로 이전 + string oldLauncherFile = CommonLibrary.Extensions.PathCombineW(tempDirectory, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + "_old"); System.IO.File.Move(launcherFile, oldLauncherFile); - System.IO.File.Move(newLauncherFile, launcherFile); + + // 언패킹 과정 + var progressPacker = new ProgressPacker(); + + Log.INFO("[Launcher] Unpack Start"); + progressPacker.UnPack(launcherPackFile, launcherPath, null); + Log.INFO("[Launcher] Unpack Done"); + + //System.IO.File.Move(newLauncherFile, launcherFile); return LauncherUpdateStatus.Update; } } diff --git a/Mitria_Minecraft_Updater/Program.cs b/Mitria_Minecraft_Updater/Program.cs index ef7918f..c7ddf01 100644 --- a/Mitria_Minecraft_Updater/Program.cs +++ b/Mitria_Minecraft_Updater/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace Mitria_Minecraft_Updater { @@ -50,14 +51,15 @@ namespace Mitria_Minecraft_Updater bool serverIs = false; string serverOriginalName = string.Empty; - string serverList = string.Empty; - foreach (var item in serverInformation.Servers) + StringBuilder serverList = new StringBuilder(); + foreach (var serverName in serverInformation.Servers.Select(x => x.ServerName)) { - serverList += item.ServerName + ", "; - if( item.ServerName.ToUpper() == args[2].ToUpper()) + serverList.Append(serverName); + serverList.Append(", "); + if(serverName.ToUpper() == args[2].ToUpper()) { serverIs = true; - serverOriginalName = item.ServerName; + serverOriginalName = serverName; } } if(!serverIs) @@ -65,8 +67,8 @@ namespace Mitria_Minecraft_Updater HelpMessage(); if (serverList.Length > 1) { - serverList = serverList.Substring(0, serverList.Length - 2); - Console.WriteLine(" [ServerList] " + serverList); + serverList.Remove(serverList.Length - 2, 2); + Console.WriteLine(" [ServerList] " + serverList.ToString()); return; } } @@ -103,12 +105,12 @@ namespace Mitria_Minecraft_Updater var launcherSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, Settings.config.LauncherSource); var launcherTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, Settings.config.LauncherUrl); - var launcherSourceFile = CommonLibrary.Extensions.PathCombineL(launcherSourceDirectory, Settings.config.LauncherFileName); + var launcherSourceFile = CommonLibrary.Extensions.PathCombineL(launcherSourceDirectory, Settings.config.LauncherSourceFileName); var launcherTargetFile = CommonLibrary.Extensions.PathCombineL(launcherTargetDirectory, Settings.config.LauncherFileName); Extensions.DirectoryCheckCrate(launcherSourceDirectory); Extensions.DirectoryCheckCrate(launcherTargetDirectory); - if (!System.IO.File.Exists(launcherSourceFile)) + if (!System.IO.File.Exists(launcherSourceFile)) // 런처 소스 파일이 있는지 확인 { Console.WriteLine("The source file could not be found. Location : " + launcherSourceFile); return; @@ -147,7 +149,12 @@ namespace Mitria_Minecraft_Updater System.IO.File.Delete(launcherTargetFile); } - System.IO.File.Copy(launcherSourceFile, launcherTargetFile); + var tempFile = "launcher.temp"; + + // Pakcing 작업 시작 + Packing(launcherSourceDirectory, tempFile); + + System.IO.File.Move(tempFile, launcherTargetFile); Console.WriteLine("update Version : " + launcherPatchInformation.Version + " → " + sourceVersion); launcherPatchInformation.Version = sourceVersion.ToString(); Settings.SaveLauncherPatchInformation(launcherPatchInformation); @@ -179,7 +186,7 @@ namespace Mitria_Minecraft_Updater Packing(runtimeSourceDirectory, tempFile); // 최종 저장 경로 할당 - var finalTarget = CommonLibrary.Extensions.PathCombineL(runtimeTargetDirectory, Settings.config.RuntimeFilename); + var finalTarget = CommonLibrary.Extensions.PathCombineL(runtimeTargetDirectory, Settings.config.RuntimeFileName); // 최종 저장 경로에 이미 파일이 있다면 삭제 if (System.IO.File.Exists(finalTarget)) @@ -222,7 +229,7 @@ namespace Mitria_Minecraft_Updater Packing(packageSourceDirectory, tempFile); // 최종 저장 경로 할당 - var finalTarget = CommonLibrary.Extensions.PathCombineL(packageTargetDirectory, Settings.config.PackageFilename); + var finalTarget = CommonLibrary.Extensions.PathCombineL(packageTargetDirectory, Settings.config.PackageFileName); // 최종 저장 경로에 이미 파일이 있다면 삭제 if (System.IO.File.Exists(finalTarget)) diff --git a/Mitria_Minecraft_Updater/Settings.cs b/Mitria_Minecraft_Updater/Settings.cs index 8eb06e5..7608483 100644 --- a/Mitria_Minecraft_Updater/Settings.cs +++ b/Mitria_Minecraft_Updater/Settings.cs @@ -23,13 +23,14 @@ namespace Mitria_Minecraft_Updater config.LauncherSource = "/Launcher"; config.LauncherUrl = "/Launcher"; - config.LauncherFileName = "MitriaMLauncher.exe"; + config.LauncherSourceFileName = "MitriaMLauncher.exe"; + config.LauncherFileName = "MitriaMLauncher.pack"; config.RuntimeSource = "/Runtime"; config.RuntimeUrl = "/Data/Runtime"; - config.RuntimeFilename = "Runtime.pack"; + config.RuntimeFileName = "Runtime.pack"; config.PackageSource = "/Package"; config.PackageUrl = "/Data/Package"; - config.PackageFilename = "Package.pack"; + config.PackageFileName = "Package.pack"; config.ComponentSource = "/Component"; config.ComponentUrl = "/Data/Component"; } @@ -111,9 +112,9 @@ namespace Mitria_Minecraft_Updater dataPatchInformation.ComponentList = new System.Collections.Generic.List(); } dataPatchInformation.RuntimeUrl = config.RuntimeUrl; - dataPatchInformation.RuntimeFileName = config.RuntimeFilename; + dataPatchInformation.RuntimeFileName = config.RuntimeFileName; dataPatchInformation.PackageUrl = config.PackageUrl; - dataPatchInformation.PackageFileName = config.PackageFilename; + dataPatchInformation.PackageFileName = config.PackageFileName; dataPatchInformation.ComponentUrl = config.ComponentUrl; return dataPatchInformation; @@ -142,15 +143,16 @@ namespace Mitria_Minecraft_Updater public string InformationToServer { get; set; } public string LauncherSource { get; set; } // {Source}/Launcher public string LauncherUrl { get; set; } // {Target}/Launcher + public string LauncherSourceFileName { get; set; } public string LauncherFileName { get; set; } // 런처 파일이름 public string RuntimeSource { get; set; } // {Source}/Runtime public string RuntimeUrl { get; set; } // {Target}/Runtime - public string RuntimeFilename { get; set; } // Runtime.pack + public string RuntimeFileName { get; set; } // Runtime.pack public string PackageSource { get; set; } // {Source}/Package public string PackageUrl { get; set; } // {Target}/Package - public string PackageFilename { get; set; } // Package.pack + public string PackageFileName { get; set; } // Package.pack public string ComponentSource { get; set; } // {Source}/GameFile public string ComponentUrl { get; set; } // {Target}/GameFile