- Recovery

This commit is contained in:
2022-10-09 12:27:47 +09:00
parent f53695b228
commit 9052652122
30 changed files with 1112 additions and 219 deletions

View File

@@ -25,7 +25,7 @@ namespace Mitria_Minecraft_Launcher.Updater
// Version File Download
CommonLibrary.Log.INFO("download version file.");
var verionData = downloader.DownloadString(Settings.ServerBaseUrl + Settings.ServerDataPatchInformationFile);
var verionData = downloader.DownloadString(CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl,"Servers", Settings.NowProfile.ServerName, Settings.ServerDataPatchInformationFile));
// Versoin File 받기에 실패하였을때 업데이트 전체 실패처리
if (verionData == string.Empty)
@@ -36,7 +36,7 @@ namespace Mitria_Minecraft_Launcher.Updater
}
// Version File Xml 형태로 변환
var dataPatchInformation = CommonLibrary.XMLSystem.LoadFromData<DataPatchInformation>(verionData);
var dataPatchInformation = CommonLibrary.XmlSystem.LoadFromData<DataPatchInformation>(verionData);
// 임시 폴더 생성
var tempDirectory = System.IO.Path.GetFullPath("temp");
@@ -54,7 +54,7 @@ namespace Mitria_Minecraft_Launcher.Updater
Log.INFO("[Runtime] Version Check");
// 버전 비교
var thisVersion = Version.Parse(Settings.UserLauncherConfig.RuntimeVersion);
var thisVersion = Version.Parse(Settings.NowProfile.RuntimeVersion);
var remoteVersion = Version.Parse(dataPatchInformation.RuntimeVersion);
CommonLibrary.Log.INFO("[Runtime] LocalVersion : " + thisVersion);
CommonLibrary.Log.INFO("[Runtime] RemoteVersion : " + remoteVersion);
@@ -72,7 +72,7 @@ namespace Mitria_Minecraft_Launcher.Updater
CommonLibrary.Log.INFO("Runtime delete it for update.");
// 런타임 폴더 경로 가져오기
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(Settings.RuntimeLocation));
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.RuntimeLocation,Settings.NowProfile.ServerName)));
// 런타임 폴더 삭제후 새로만들기
if (!rootDirectoryInfo.Exists)
@@ -91,7 +91,7 @@ namespace Mitria_Minecraft_Launcher.Updater
// 런타임 다운로드 시작
GameUpdateManagerMessage(this, new GameUpdateManagerMessageEventArgs(GameUpdateManagerMessageType.First, 2, 9, "[2/9] Runtime Download"));
Log.INFO("[Runtime] Data Download Start");
var downloadUrl = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, dataPatchInformation.RuntimeUrl, dataPatchInformation.RuntimeFileName);
var downloadUrl = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, "Servers", Settings.NowProfile.ServerName, dataPatchInformation.RuntimeUrl, dataPatchInformation.RuntimeFileName);
var targetPath = System.IO.Path.Combine(tempDirectory, dataPatchInformation.RuntimeFileName); // 임시폴더에 다운로드
downloader.DownloadFile(downloadUrl, targetPath);
Log.INFO("[Runtime] Data Download End");
@@ -99,11 +99,11 @@ namespace Mitria_Minecraft_Launcher.Updater
// 런타임 언패킹 작업
var progressPacker = new ProgressPacker();
var unpackPath = System.IO.Path.GetFullPath(Settings.RuntimeLocation);
var unpackPath = rootDirectoryInfo.FullName;
GameUpdateManagerMessage(this, new GameUpdateManagerMessageEventArgs(GameUpdateManagerMessageType.First, 3, 9, "[3/9] Runtime Unpack"));
Log.INFO("[Runtime] Unpack Start");
progressPacker.UnPack(targetPath, unpackPath, new BasicProgress<double>(p => Change(p)));
Settings.UserLauncherConfig.RuntimeVersion = remoteVersion.ToString();
Settings.NowProfile.RuntimeVersion = remoteVersion.ToString();
//임시폴더 삭제
System.IO.File.Delete(targetPath);
@@ -134,7 +134,7 @@ namespace Mitria_Minecraft_Launcher.Updater
.INFO(string.Format("{0}", result == 1 ? "remote is the upper version" : "remote is the lower version"));
CommonLibrary.Log.INFO("[Package] delete it for update.");
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(Settings.UserLauncherConfig.GameDirectory));
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory,Settings.NowProfile.ServerName)));
if (!rootDirectoryInfo.Exists)
{
@@ -144,11 +144,15 @@ namespace Mitria_Minecraft_Launcher.Updater
else
{
// 비우기 전에 스크린샷폴더 보존 /screenshots
string oldScreenshotsDirectory = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, "screenshots");
string oldScreenshotsDirectory = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName, "screenshots");
string newScreenshotsDirectory = CommonLibrary.Extensions.PathCombineW("screenshots " + DateTime.Now.ToString());
if (System.IO.Directory.Exists(oldScreenshotsDirectory) && System.IO.Directory.GetFiles(oldScreenshotsDirectory, "*", System.IO.SearchOption.AllDirectories).Length > 0)
{
Log.INFO("[Package] Screenshots Directory Backup : " + newScreenshotsDirectory);
if(!System.IO.Directory.Exists(newScreenshotsDirectory))
{
System.IO.Directory.CreateDirectory(newScreenshotsDirectory);
}
System.IO.Directory.Move(oldScreenshotsDirectory, newScreenshotsDirectory);
}
@@ -156,7 +160,7 @@ namespace Mitria_Minecraft_Launcher.Updater
Log.INFO("[Package] Empty GameDirectory");
}
var downloadUrl = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, dataPatchInformation.PackageUrl, dataPatchInformation.PackageFileName);
var downloadUrl = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, "Servers", Settings.NowProfile.ServerName, dataPatchInformation.PackageUrl, dataPatchInformation.PackageFileName);
var targetPath = System.IO.Path.Combine(tempDirectory, dataPatchInformation.PackageFileName);
GameUpdateManagerMessage(this, new GameUpdateManagerMessageEventArgs(GameUpdateManagerMessageType.First, 5, 9, "[5/9] Package Download"));
Log.INFO("[Package] Download Start");
@@ -203,6 +207,7 @@ namespace Mitria_Minecraft_Launcher.Updater
System.IO.File.Delete(targetPath);
Log.INFO("[Package] -[F] " + targetPath);
Log.INFO("[Package] Unpack End");
Settings.UserClientVersion.ComponentVersion = "0.0.0.0";
}
#endregion Package Update
@@ -236,7 +241,7 @@ namespace Mitria_Minecraft_Launcher.Updater
foreach (var directory in resultDirectorys)
{
var directoryPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, directory));
var directoryPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory,Settings.NowProfile.ServerName, directory));
if (System.IO.Directory.Exists(directoryPath))
{
@@ -247,7 +252,7 @@ namespace Mitria_Minecraft_Launcher.Updater
foreach (var directory in dataPatchInformation.ComponentDirectorys)
{
var directoryPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, directory));
var directoryPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName, directory));
if (!System.IO.Directory.Exists(directoryPath))
{
@@ -265,7 +270,7 @@ namespace Mitria_Minecraft_Launcher.Updater
foreach (var fileDetail in removeFiles)
{
var filePath = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, fileDetail.Directory, fileDetail.FileName);
var filePath = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory,Settings.NowProfile.ServerName, fileDetail.Directory, fileDetail.FileName);
if (System.IO.File.Exists(filePath))
{
Log.INFO("[Component] -[F] " + filePath);
@@ -277,8 +282,8 @@ namespace Mitria_Minecraft_Launcher.Updater
Log.INFO("[Component] Download Start");
for (int i = 0; i < needFiles.Count; i++)
{
var url = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, dataPatchInformation.ComponentUrl, needFiles[i].Directory, needFiles[i].FileName);
var path = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, needFiles[i].Directory, needFiles[i].FileName);
var url = CommonLibrary.Extensions.PathCombineL(Settings.ServerBaseUrl, "Servers", Settings.NowProfile.ServerName, dataPatchInformation.ComponentUrl, needFiles[i].Directory, needFiles[i].FileName);
var path = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory,Settings.NowProfile.ServerName, needFiles[i].Directory, needFiles[i].FileName);
downloader.DownloadFile(url, path);
Log.INFO("[Component] +[F] " + path);
}
@@ -293,7 +298,15 @@ namespace Mitria_Minecraft_Launcher.Updater
#region CustomData
// 삭제된 파일 찾기
string rootCustomPath = System.IO.Path.GetFullPath(Settings.CustomDataDirectory);
string rootCustomPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.CustomDataDirectory, Settings.NowProfile.ServerName));
if(!System.IO.Directory.Exists(CommonLibrary.Extensions.PathCombineW(rootCustomPath, "config")))
{
System.IO.Directory.CreateDirectory(CommonLibrary.Extensions.PathCombineW(rootCustomPath, "config"));
}
if (!System.IO.Directory.Exists(CommonLibrary.Extensions.PathCombineW(rootCustomPath, "mods")))
{
System.IO.Directory.CreateDirectory(CommonLibrary.Extensions.PathCombineW(rootCustomPath, "mods"));
}
List<string> files = new List<string>();
files.AddRange(System.IO.Directory.GetFiles(CommonLibrary.Extensions.PathCombineW(rootCustomPath, "config")));
files.AddRange(System.IO.Directory.GetFiles(CommonLibrary.Extensions.PathCombineW(rootCustomPath, "mods")));
@@ -302,21 +315,11 @@ namespace Mitria_Minecraft_Launcher.Updater
files[i] = files[i].Replace(rootCustomPath + '\\', string.Empty);
}
for (int i = 0; i < Settings.UserLauncherConfig.CustomData.Count; i++)
{
if (!files.Contains(Settings.UserLauncherConfig.CustomData[i]))
{
string filePath = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.UserLauncherConfig.CustomData[i]);
System.IO.File.Delete(filePath);
Log.INFO("[CustomData] -[F] " + filePath);
}
}
foreach (var file in files)
{
string sourcePath = CommonLibrary.Extensions.PathCombineW(rootCustomPath, file);
string targetPath = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, file);
string targetPath = CommonLibrary.Extensions.PathCombineW( Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName,file);
if (System.IO.File.Exists(targetPath))
@@ -335,7 +338,7 @@ namespace Mitria_Minecraft_Launcher.Updater
System.IO.File.Copy(sourcePath, targetPath);
Log.INFO("[CustomData] +[F] " + targetPath);
}
Settings.UserLauncherConfig.CustomData = files;
//Settings.UserLauncherConfig.CustomData = files;
Settings.SaveUserLauncherConfig();
}