using System; using System.Diagnostics; using System.IO; using CommonLibrary; namespace Mitria_Minecraft_Launcher.Updater { internal class LauncherUpdate { public LauncherUpdateStatus Start() { Downloader downloader = new Downloader(); CommonLibrary.Log.INFO("Launcher Update Process Start"); string verionData = downloader.DownloadString(Settings.ServerBaseUrl + Settings.ServerLauncherPatchInformationFile); if (verionData == string.Empty) { return LauncherUpdateStatus.Fail; } LauncherPatchInformation launcherPatchInformation = CommonLibrary.XmlSystem.LoadFromData(verionData); Version thisVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Version remoteVersion = Version.Parse(launcherPatchInformation.Version); CommonLibrary.Log.INFO("Launcher Version : " + thisVersion); CommonLibrary.Log.INFO("Remote Launcher Version : " + remoteVersion); int result = remoteVersion.CompareTo(thisVersion); if (result <= 0) { CommonLibrary.Log.INFO("Version Same"); return LauncherUpdateStatus.Same; } else { CommonLibrary.Log.INFO("Launcher Update"); string tempDirectory = Path.GetFullPath("temp"); if (!System.IO.Directory.Exists(tempDirectory)) { System.IO.Directory.CreateDirectory("temp"); } string downloadUrl = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, launcherPatchInformation.LauncherUrl, launcherPatchInformation.LauncherFileName); 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); // 언패킹 과정 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; } } } internal enum LauncherUpdateStatus { Update, Same, Fail } }