using System; 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 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"); System.IO.File.Move(launcherFile, oldLauncherFile); System.IO.File.Move(newLauncherFile, launcherFile); return LauncherUpdateStatus.Update; } } } internal enum LauncherUpdateStatus { Update, Same, Fail } }