- 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

@@ -27,7 +27,7 @@ namespace Mitria_Minecraft_Updater
int countFiles = System.IO.Directory.GetFiles(directorys[i - 1], "*", System.IO.SearchOption.AllDirectories).Length;
if (countDirectory + countFiles == 0)
{
System.IO.Directory.Delete(directorys[i - 1]);
System.IO.Directory.Delete(directorys[i - 1],true);
}
}
}

View File

@@ -5,6 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<StartupObject>Mitria_Minecraft_Updater.Program</StartupObject>
<AssemblyName>mmu</AssemblyName>
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>

View File

@@ -6,89 +6,86 @@ namespace Mitria_Minecraft_Updater
{
internal static class Program
{
static int nowPosTop;
static int nowPosLeft;
private static int nowPosTop;
private static int nowPosLeft;
static void Main(string[] args)
private static void Main(string[] args)
{
Settings.LoadConfig();
if (args.Length < 1)
{
HelpMessage();
return;
}
var versionType = VersionType.Major;
var checkArg = false;
if (args.Length >= 2)
UpdateType? updateType = GetUpdateType(args[0]);
if( updateType == null)
{
switch (args[1].ToUpper())
HelpMessage();
return;
}
if(updateType == UpdateType.Launcher)
{
LauncherUpdate();
return;
}
if (args.Length < 3)
{
HelpMessage();
return;
}
VersionType? versionType = GetVersionType(args[1]);
if (versionType == null)
{
HelpMessage();
return;
}
CommonLibrary.ServerInformation serverInformation = Settings.LoadServerInformation();
if(CommonLibrary.Extensions.IsDefault(ref serverInformation))
{
Console.WriteLine("not found ServerData Location : " + Settings.config.Target + Settings.config.InformationToServer);
return;
}
bool serverIs = false;
string serverOriginalName = string.Empty;
string serverList = string.Empty;
foreach (var item in serverInformation.Servers)
{
serverList += item.ServerName + ", ";
if( item.ServerName.ToUpper() == args[2].ToUpper())
{
case "MAJOR":
versionType = VersionType.Major;
break;
case "MINOR":
versionType = VersionType.Minor;
break;
case "BUILD":
versionType = VersionType.Build;
break;
case "REVISION":
versionType = VersionType.Revision;
break;
default:
HelpMessage();
return;
serverIs = true;
serverOriginalName = item.ServerName;
}
checkArg = true;
}
switch (args[0].ToUpper())
if(!serverIs)
{
case "LAUNCHER":
LauncherUpdate();
break;
case "RUNTIME":
if (!checkArg)
{
HelpMessage();
return;
}
RuntimeUpdate(versionType);
break;
case "PACKAGE":
if (!checkArg)
{
HelpMessage();
return;
}
PackageUpdate(versionType);
break;
case "COMPONENT":
if (!checkArg)
{
HelpMessage();
return;
}
ComponentUpdate(versionType);
break;
default:
HelpMessage();
HelpMessage();
if (serverList.Length > 1)
{
serverList = serverList.Substring(0, serverList.Length - 2);
Console.WriteLine(" [ServerList] " + serverList);
return;
}
}
switch(updateType)
{
case UpdateType.Runtime:
RuntimeUpdate(serverOriginalName, (VersionType)versionType);
break;
case UpdateType.Package:
PackageUpdate(serverOriginalName, (VersionType)versionType);
break;
case UpdateType.Component:
ComponentUpdate(serverOriginalName, (VersionType)versionType);
break;
}
}
public static void HelpMessage()
@@ -96,15 +93,15 @@ namespace Mitria_Minecraft_Updater
Console.WriteLine("dotnet mmu.dll [option1] [option2]");
Console.WriteLine(" [option1] Launcher, Runtime, Package, Component");
Console.WriteLine(" [option2] Major, Minor, Build, Revision");
Console.WriteLine(" [option3] ServerName");
}
public static void LauncherUpdate()
{
Settings.LoadConfig();
var launcherPatchInformation = Settings.LoadLauncherPatchInformation(); // 런처 패치정보 Load
Console.WriteLine("Start Launcher Update");
var launcherSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source , Settings.config.LauncherSource);
var launcherSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, Settings.config.LauncherSource);
var launcherTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, Settings.config.LauncherUrl);
var launcherSourceFile = CommonLibrary.Extensions.PathCombineL(launcherSourceDirectory, Settings.config.LauncherFileName);
var launcherTargetFile = CommonLibrary.Extensions.PathCombineL(launcherTargetDirectory, Settings.config.LauncherFileName);
@@ -113,13 +110,13 @@ namespace Mitria_Minecraft_Updater
if (!System.IO.File.Exists(launcherSourceFile))
{
Console.WriteLine("The source file could not be found.");
Console.WriteLine("The source file could not be found. Location : " + launcherSourceFile);
return;
}
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(launcherSourceFile);
var sourceVersion = new Version(fileVersionInfo.ProductVersion);
var sourceVersion = new Version(fileVersionInfo.ProductVersion);
Version oldVersoin;
@@ -144,7 +141,7 @@ namespace Mitria_Minecraft_Updater
Console.WriteLine("The existing version is higher.");
return;
}
if (System.IO.File.Exists(launcherTargetFile))
{
System.IO.File.Delete(launcherTargetFile);
@@ -157,24 +154,21 @@ namespace Mitria_Minecraft_Updater
Console.WriteLine("Update Complete");
}
public static void RuntimeUpdate(VersionType versionType)
public static void RuntimeUpdate(string serverName, VersionType versionType)
{
Settings.LoadConfig();
var dataPatchInformation = Settings.LoadDataPatchInformation();
var dataPatchInformation = Settings.LoadDataPatchInformation(serverName);
Console.WriteLine("Start Runtime Update - version " + versionType.ToString());
var runtimeSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, Settings.config.RuntimeSource);
var runtimeTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, Settings.config.RuntimeUrl);
var runtimeSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source,"Servers" , serverName, Settings.config.RuntimeSource);
var runtimeTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target,"Servers", serverName, Settings.config.RuntimeUrl);
Extensions.DirectoryCheckCrate(runtimeSourceDirectory);
Extensions.DirectoryCheckCrate(runtimeTargetDirectory);
// 파일이 하나도 없을경우 조회실패
if (System.IO.Directory.GetFiles(runtimeSourceDirectory, "*.*", System.IO.SearchOption.AllDirectories).Length == 0)
{
Console.WriteLine("The source file could not be found.");
Console.WriteLine("The source file could not be found. Location : " + runtimeSourceDirectory );
return;
}
@@ -198,19 +192,18 @@ namespace Mitria_Minecraft_Updater
var newVersion = VersionChange(dataPatchInformation.RuntimeVersion, versionType);
Console.WriteLine("update Version : " + dataPatchInformation.RuntimeVersion + " → " + newVersion);
dataPatchInformation.RuntimeVersion = newVersion;
Settings.SaveDataPatchInformation(dataPatchInformation);
Settings.SaveDataPatchInformation(serverName,dataPatchInformation);
Console.WriteLine("Update Complete");
}
public static void PackageUpdate(VersionType versionType)
public static void PackageUpdate(string serverName, VersionType versionType)
{
Settings.LoadConfig();
var dataPatchInformation = Settings.LoadDataPatchInformation();
var dataPatchInformation = Settings.LoadDataPatchInformation(serverName);
Console.WriteLine("Start Package Update - version " + versionType.ToString());
var packageSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, Settings.config.PackageSource);
var packageTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, Settings.config.PackageUrl);
var packageSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, "Servers", serverName, Settings.config.PackageSource);
var packageTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, "Servers", serverName, Settings.config.PackageUrl);
Extensions.DirectoryCheckCrate(packageSourceDirectory);
Extensions.DirectoryCheckCrate(packageTargetDirectory);
@@ -218,7 +211,7 @@ namespace Mitria_Minecraft_Updater
// 파일이 하나도 없을경우 조회실패
if (System.IO.Directory.GetFiles(packageSourceDirectory, "*.*", System.IO.SearchOption.AllDirectories).Length == 0)
{
Console.WriteLine("The source file could not be found.");
Console.WriteLine("The source file could not be found. Location : " + packageSourceDirectory );
return;
}
@@ -229,7 +222,7 @@ namespace Mitria_Minecraft_Updater
Packing(packageSourceDirectory, tempFile);
// 최종 저장 경로 할당
var finalTarget = CommonLibrary.Extensions.PathCombineL(packageTargetDirectory , Settings.config.PackageFilename);
var finalTarget = CommonLibrary.Extensions.PathCombineL(packageTargetDirectory, Settings.config.PackageFilename);
// 최종 저장 경로에 이미 파일이 있다면 삭제
if (System.IO.File.Exists(finalTarget))
@@ -242,7 +235,6 @@ namespace Mitria_Minecraft_Updater
for (int i = 0; i < directories.Length; i++)
{
directories[i] = System.IO.Path.GetRelativePath(Settings.config.Source, directories[i]);
}
@@ -250,26 +242,25 @@ namespace Mitria_Minecraft_Updater
var newVersion = VersionChange(dataPatchInformation.PackageVersion, versionType);
Console.WriteLine("Update Version : " + dataPatchInformation.PackageVersion + " → " + newVersion);
dataPatchInformation.PackageVersion = newVersion;
Settings.SaveDataPatchInformation(dataPatchInformation);
Settings.SaveDataPatchInformation(serverName,dataPatchInformation);
Console.WriteLine("Update Complete");
}
public static void ComponentUpdate(VersionType versionType)
public static void ComponentUpdate(string serverName, VersionType versionType)
{
Settings.LoadConfig();
CommonLibrary.DataPatchInformation dataPatchInformation = Settings.LoadDataPatchInformation();
CommonLibrary.DataPatchInformation dataPatchInformation = Settings.LoadDataPatchInformation(serverName);
Console.WriteLine("Start Component Update - version " + versionType.ToString());
var componentSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, Settings.config.ComponentSource);
var componentTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, Settings.config.ComponentUrl);
var componentSourceDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Source, "Servers", serverName, Settings.config.ComponentSource);
var componentTargetDirectory = CommonLibrary.Extensions.PathCombineL(Settings.config.Target, "Servers", serverName, Settings.config.ComponentUrl);
Extensions.DirectoryCheckCrate(componentSourceDirectory);
Extensions.DirectoryCheckCrate(componentTargetDirectory);
if (System.IO.Directory.GetFiles(componentSourceDirectory, "*.*", System.IO.SearchOption.AllDirectories).Length == 0)
{
Console.WriteLine("The source file could not be found.");
Console.WriteLine("The source file could not be found. Location : " + componentSourceDirectory);
return;
}
@@ -338,7 +329,7 @@ namespace Mitria_Minecraft_Updater
{
System.IO.File.Delete(targetFileFullPath);
System.IO.File.Copy(sourceFileFullPath, targetFileFullPath);
Console.Write("Update File : " + oFile);
Console.WriteLine("Update File : " + oFile);
}
}
@@ -359,16 +350,15 @@ namespace Mitria_Minecraft_Updater
dataPatchInformation.ComponentDirectorys = sourceDirectorys.ToList();
// 파일 디테일
var newVersion = VersionChange(dataPatchInformation.ComponentVersion, versionType);
Console.WriteLine("Update Version : " + dataPatchInformation.ComponentVersion + " → " + newVersion);
dataPatchInformation.ComponentVersion = newVersion;
Settings.SaveDataPatchInformation(dataPatchInformation);
Settings.SaveDataPatchInformation(serverName,dataPatchInformation);
Console.WriteLine("Update Complete");
// 무결성 검사후 업데이트
}
static void Packing(string source, string target)
private static void Packing(string source, string target)
{
if (System.IO.File.Exists(target))
{
@@ -393,7 +383,7 @@ namespace Mitria_Minecraft_Updater
Console.WriteLine("Packing Complite");
}
static string VersionChange(string version, VersionType versionType)
private static string VersionChange(string version, VersionType versionType)
{
var v = Version.Parse(version);
@@ -419,7 +409,7 @@ namespace Mitria_Minecraft_Updater
return v.ToString();
}
static void ProgressChange(double obj)
private static void ProgressChange(double obj)
{
Console.SetCursorPosition(nowPosLeft, nowPosTop);
var Progress = (int)(obj * 10);
@@ -432,6 +422,66 @@ namespace Mitria_Minecraft_Updater
Console.Write(" " + $"{obj:P2}");
}
private static UpdateType? GetUpdateType(string data)
{
UpdateType? updateType;
switch (data.ToUpper())
{
case "LAUNCHER":
updateType = UpdateType.Launcher;
break;
case "RUNTIME":
updateType = UpdateType.Runtime;
break;
case "PACKAGE":
updateType = UpdateType.Package;
break;
case "COMPONENT":
updateType = UpdateType.Component;
break;
default:
updateType = null;
break;
}
return updateType;
}
private static VersionType? GetVersionType(string data)
{
VersionType? versionType;
switch (data.ToUpper())
{
case "MAJOR":
versionType = VersionType.Major;
break;
case "MINOR":
versionType = VersionType.Minor;
break;
case "BUILD":
versionType = VersionType.Build;
break;
case "REVISION":
versionType = VersionType.Revision;
break;
default:
versionType = null;
break;
}
return versionType;
}
}
internal enum UpdateType

View File

@@ -14,14 +14,15 @@ namespace Mitria_Minecraft_Updater
private static void InitializationConfig()
{
// 줄여야함
config.Source = "./Source";
config.Target = "./Target";
config.Source = "../Source";
config.Target = "../Target";
config.InformationToLauncher = "/Launcher.xml";
config.InformationToData = "/Data.xml";
config.InformationToLauncher = "/launcher.xml";
config.InformationToData = "/data.xml";
config.InformationToServer = "/server.xml";
config.LauncherSource = "/Launcher";
config.LauncherUrl = "/Data/Launcher";
config.LauncherUrl = "/Launcher";
config.LauncherFileName = "MitriaMLauncher.exe";
config.RuntimeSource = "/Runtime";
config.RuntimeUrl = "/Data/Runtime";
@@ -37,7 +38,7 @@ namespace Mitria_Minecraft_Updater
{
if (System.IO.File.Exists(configPath))
{
config = CommonLibrary.XMLSystem.LoadFromPath<Config>(configPath);
config = CommonLibrary.XmlSystem.LoadFromPath<Config>(configPath);
}
else
{
@@ -48,7 +49,7 @@ namespace Mitria_Minecraft_Updater
public static void SaveConfig()
{
CommonLibrary.XMLSystem.Save(configPath, config);
CommonLibrary.XmlSystem.Save(configPath, config);
}
public static CommonLibrary.LauncherPatchInformation LoadLauncherPatchInformation()
@@ -57,7 +58,7 @@ namespace Mitria_Minecraft_Updater
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target, config.InformationToLauncher);
if (System.IO.File.Exists(fullPath))
{
launcherPatchInformation = CommonLibrary.XMLSystem.LoadFromPath<CommonLibrary.LauncherPatchInformation>(fullPath);
launcherPatchInformation = CommonLibrary.XmlSystem.LoadFromPath<CommonLibrary.LauncherPatchInformation>(fullPath);
}
else
{
@@ -69,6 +70,18 @@ namespace Mitria_Minecraft_Updater
return launcherPatchInformation;
}
public static CommonLibrary.ServerInformation LoadServerInformation()
{
CommonLibrary.ServerInformation serverInformation = new CommonLibrary.ServerInformation();
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target, config.InformationToServer);
if(System.IO.File.Exists(fullPath))
{
serverInformation = CommonLibrary.XmlSystem.LoadFromPath<CommonLibrary.ServerInformation>(fullPath);
}
return serverInformation;
}
public static void SaveLauncherPatchInformation(CommonLibrary.LauncherPatchInformation launcherPatchInformation)
{
@@ -77,16 +90,16 @@ namespace Mitria_Minecraft_Updater
{
System.IO.Directory.CreateDirectory(config.Target);
}
CommonLibrary.XMLSystem.Save(fullPath, launcherPatchInformation);
CommonLibrary.XmlSystem.Save(fullPath, launcherPatchInformation);
}
public static CommonLibrary.DataPatchInformation LoadDataPatchInformation()
public static CommonLibrary.DataPatchInformation LoadDataPatchInformation(string serverName)
{
CommonLibrary.DataPatchInformation dataPatchInformation = new CommonLibrary.DataPatchInformation();
string fullPath = config.Target + config.InformationToData;
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target, "Servers", serverName, config.InformationToData);
if (System.IO.File.Exists(fullPath))
{
dataPatchInformation = CommonLibrary.XMLSystem.LoadFromPath<CommonLibrary.DataPatchInformation>(fullPath);
dataPatchInformation = CommonLibrary.XmlSystem.LoadFromPath<CommonLibrary.DataPatchInformation>(fullPath);
}
else
{
@@ -106,14 +119,14 @@ namespace Mitria_Minecraft_Updater
return dataPatchInformation;
}
public static void SaveDataPatchInformation(CommonLibrary.DataPatchInformation dataPatchInformation)
public static void SaveDataPatchInformation(string serverName, CommonLibrary.DataPatchInformation dataPatchInformation)
{
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target , config.InformationToData);
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target, "Servers", serverName, config.InformationToData);
if (!System.IO.Directory.Exists(config.Target))
{
System.IO.Directory.CreateDirectory(config.Target);
}
CommonLibrary.XMLSystem.Save(fullPath, dataPatchInformation);
CommonLibrary.XmlSystem.Save(fullPath, dataPatchInformation);
}
}
@@ -126,7 +139,7 @@ namespace Mitria_Minecraft_Updater
public string InformationToLauncher { get; set; } //{InformationDirectory}/Launcher.xml
public string InformationToData { get; set; } // {InformationDirectory}/Data.xml
public string InformationToServer { get; set; }
public string LauncherSource { get; set; } // {Source}/Launcher
public string LauncherUrl { get; set; } // {Target}/Launcher
public string LauncherFileName { get; set; } // 런처 파일이름