Files
Mitria_Minecraft_Project/Mitria_Minecraft_Launcher/Updater/LauncherUpdate.cs
Crudelis db5a1cff63 Update Module
- 백신 회피를 위한 런처 수정
2023-02-10 17:20:25 +09:00

73 lines
3.0 KiB
C#

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<LauncherPatchInformation>(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 DEBUG
result =1;
#endif
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
}
}