Files
Mitria_Minecraft_Project/Mitria_Minecraft_Launcher/Updater/LauncherUpdate.cs
Crudelis 7a5c8e3f02 -Bug Fix
Ran_agro 제보
루트로 지정했을시 폴더 구분자가 중복되어 에러가 나던 문제 해결
2023-05-20 12:54:48 +09:00

70 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 (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
}
}