패키지 업데이트 분리 작업

This commit is contained in:
2025-09-04 19:49:18 +09:00
parent c7aeee4eee
commit 33b64b619a
2 changed files with 72 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
@@ -13,7 +14,7 @@ namespace Mitria_Minecraft_Launcher
bool error = false;
DirectoryInfo directoryInfo = new DirectoryInfo(location);
foreach (var fi in directoryInfo.EnumerateFiles())
{
try
@@ -55,6 +56,38 @@ namespace Mitria_Minecraft_Launcher
return error;
}
static void DeleteFile(string filePath)
{
try
{
File.SetAttributes(filePath, FileAttributes.Normal); // 읽기 전용 제거
File.Delete(filePath);
}
catch (Exception ex)
{
Console.WriteLine("파일 삭제 실패: " + ex.Message);
}
}
static void DeleteDirectory(string dirPath)
{
try
{
// 하위 파일 속성 변경 및 삭제
foreach (string file in Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories))
{
File.SetAttributes(file, FileAttributes.Normal);
}
// 디렉터리 삭제 (재귀적)
Directory.Delete(dirPath, true);
}
catch (Exception ex)
{
Console.WriteLine("디렉터리 삭제 실패: " + ex.Message);
}
}
public static string ApplyExcuteCommand(ExcuteArgument excuteArgument)
{
string command = excuteArgument.Argument;
@@ -79,12 +112,12 @@ namespace Mitria_Minecraft_Launcher
return command;
}
public static bool IsDefault<T>(ref this T data) where T : struct
{
return default(T).Equals(data);
}
public static string UnitSeparator(this long value)
{
return string.Format("{0:#,0}", (object)value);
@@ -94,6 +127,7 @@ namespace Mitria_Minecraft_Launcher
{
return string.Format("{0:#,0}", (object)value);
}
public static string GetFileHashCode(this FileInfo file)
{
using (MD5 md5 = MD5.Create())

View File

@@ -148,6 +148,15 @@ namespace Mitria_Minecraft_Launcher.Updater
packageInitialization = false;
CommonLibrary.Log.INFO("[Package] update.");
}
// 패키지 다운로드
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");
downloader.DownloadFile(downloadUrl, targetPath);
Log.INFO("[Package] Download End");
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName)));
if (!rootDirectoryInfo.Exists)
@@ -157,6 +166,7 @@ namespace Mitria_Minecraft_Launcher.Updater
}
else if(packageInitialization)
{
Log.INFO("[Package] Empty GameDirectory Start");
// 비우기 전에 스크린샷폴더 보존 /screenshots
string oldScreenshotsDirectory = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName, "screenshots");
string newScreenshotsDirectory = System.IO.Path.GetFullPath("screenshots_" + DateTime.Now.ToString("yyyyMMddHHmmss"));
@@ -171,16 +181,32 @@ namespace Mitria_Minecraft_Launcher.Updater
Extensions.EmptyDirectory(rootDirectoryInfo.FullName);
Log.INFO("[Package] Empty GameDirectory");
}
else
{
Log.INFO("[Package] Partial Clean GameDirectory Start");
var tempPacker = new ProgressPacker();
var list = tempPacker.GetTopLevelItem(targetPath);
// 리스트에 있는 디렉토리와 파일 삭제
foreach (var item in list)
{
string target = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName, item.Name);
if (item.IsDirectory)
{
Extensions.DeleteDirectory(target);
Log.INFO("[Package] -[D] " + target);
}
else
{
Extensions.DeleteFile(target);
Log.INFO("[Package] -[F] " + target);
}
}
Log.INFO("[Package] Partial Clean GameDirectory End");
}
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");
downloader.DownloadFile(downloadUrl, targetPath);
Log.INFO("[Package] Download End");
// 용도가 뭐지/???
if (Settings.UserClientVersion.PackageDirectorys != null)
{
foreach (var item in Settings.UserClientVersion.PackageDirectorys)