- First Update
This commit is contained in:
69
Mitria_Minecraft_Updater/Extensions.cs
Normal file
69
Mitria_Minecraft_Updater/Extensions.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Mitria_Minecraft_Updater
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static void DirectoryCheckCrate(string path)
|
||||
{
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteEmptyDirectory(string path)
|
||||
{
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
string[] directorys = System.IO.Directory.GetDirectories(path, "*", System.IO.SearchOption.AllDirectories);
|
||||
for (int i = directorys.Length; i > 0; i--)
|
||||
{
|
||||
int countDirectory = System.IO.Directory.GetDirectories(directorys[i - 1], "*", System.IO.SearchOption.AllDirectories).Length;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] GetDirectoriesRelativePath(string path, string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
string[] directories = System.IO.Directory.GetDirectories(path, searchPattern, searchOption);
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
directories[i] = System.IO.Path.GetRelativePath(path, directories[i]);
|
||||
}
|
||||
|
||||
return directories;
|
||||
}
|
||||
|
||||
public static string[] GetFilesRelativePath(string path, string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
string[] files = System.IO.Directory.GetFiles(path, searchPattern, searchOption);
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
files[i] = System.IO.Path.GetRelativePath(path, files[i]);
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
public static string GetFileHash(string filePath)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(filePath);
|
||||
byte[] hashCode = MD5.Create().ComputeHash(fileInfo.OpenRead());
|
||||
StringBuilder hashStringBuilder = new StringBuilder();
|
||||
foreach (byte b in hashCode)
|
||||
{
|
||||
hashStringBuilder.AppendFormat("{0:x2}", b);
|
||||
}
|
||||
return hashStringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
14
Mitria_Minecraft_Updater/Mitria_Minecraft_Updater.csproj
Normal file
14
Mitria_Minecraft_Updater/Mitria_Minecraft_Updater.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<StartupObject>Mitria_Minecraft_Updater.Program</StartupObject>
|
||||
<AssemblyName>mmu</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CommonLibrary\CommonLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
452
Mitria_Minecraft_Updater/Program.cs
Normal file
452
Mitria_Minecraft_Updater/Program.cs
Normal file
@@ -0,0 +1,452 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mitria_Minecraft_Updater
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
static int nowPosTop;
|
||||
static int nowPosLeft;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
HelpMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
var versionType = VersionType.Major;
|
||||
var checkArg = false;
|
||||
|
||||
if (args.Length >= 2)
|
||||
{
|
||||
switch (args[1].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;
|
||||
}
|
||||
|
||||
checkArg = true;
|
||||
}
|
||||
|
||||
switch (args[0].ToUpper())
|
||||
{
|
||||
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();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void HelpMessage()
|
||||
{
|
||||
Console.WriteLine("dotnet mmu.dll [option1] [option2]");
|
||||
Console.WriteLine(" [option1] Launcher, Runtime, Package, Component");
|
||||
Console.WriteLine(" [option2] Major, Minor, Build, Revision");
|
||||
}
|
||||
|
||||
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 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);
|
||||
Extensions.DirectoryCheckCrate(launcherSourceDirectory);
|
||||
Extensions.DirectoryCheckCrate(launcherTargetDirectory);
|
||||
|
||||
if (!System.IO.File.Exists(launcherSourceFile))
|
||||
{
|
||||
Console.WriteLine("The source file could not be found.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(launcherSourceFile);
|
||||
|
||||
var sourceVersion = new Version(fileVersionInfo.ProductVersion);
|
||||
|
||||
Version oldVersoin;
|
||||
|
||||
if (!System.IO.File.Exists(launcherTargetFile))
|
||||
{
|
||||
oldVersoin = Version.Parse("0.0.0.0");
|
||||
}
|
||||
else
|
||||
{
|
||||
oldVersoin = Version.Parse(launcherPatchInformation.Version);
|
||||
}
|
||||
|
||||
var result = sourceVersion.CompareTo(oldVersoin);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
Console.WriteLine("Version Same");
|
||||
return;
|
||||
}
|
||||
else if (result == -1)
|
||||
{
|
||||
Console.WriteLine("The existing version is higher.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (System.IO.File.Exists(launcherTargetFile))
|
||||
{
|
||||
System.IO.File.Delete(launcherTargetFile);
|
||||
}
|
||||
|
||||
System.IO.File.Copy(launcherSourceFile, launcherTargetFile);
|
||||
Console.WriteLine("update Version : " + launcherPatchInformation.Version + " → " + sourceVersion);
|
||||
launcherPatchInformation.Version = sourceVersion.ToString();
|
||||
Settings.SaveLauncherPatchInformation(launcherPatchInformation);
|
||||
Console.WriteLine("Update Complete");
|
||||
}
|
||||
|
||||
public static void RuntimeUpdate(VersionType versionType)
|
||||
{
|
||||
Settings.LoadConfig();
|
||||
var dataPatchInformation = Settings.LoadDataPatchInformation();
|
||||
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);
|
||||
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Packing 임시 파일명
|
||||
var tempFile = "runtime.temp";
|
||||
|
||||
// Pakcing 작업 시작
|
||||
Packing(runtimeSourceDirectory, tempFile);
|
||||
|
||||
// 최종 저장 경로 할당
|
||||
var finalTarget = CommonLibrary.Extensions.PathCombineL(runtimeTargetDirectory, Settings.config.RuntimeFilename);
|
||||
|
||||
// 최종 저장 경로에 이미 파일이 있다면 삭제
|
||||
if (System.IO.File.Exists(finalTarget))
|
||||
{
|
||||
System.IO.File.Delete(finalTarget);
|
||||
}
|
||||
|
||||
System.IO.File.Move(tempFile, finalTarget);
|
||||
|
||||
var newVersion = VersionChange(dataPatchInformation.RuntimeVersion, versionType);
|
||||
Console.WriteLine("update Version : " + dataPatchInformation.RuntimeVersion + " → " + newVersion);
|
||||
dataPatchInformation.RuntimeVersion = newVersion;
|
||||
Settings.SaveDataPatchInformation(dataPatchInformation);
|
||||
Console.WriteLine("Update Complete");
|
||||
}
|
||||
|
||||
public static void PackageUpdate(VersionType versionType)
|
||||
{
|
||||
Settings.LoadConfig();
|
||||
var dataPatchInformation = Settings.LoadDataPatchInformation();
|
||||
|
||||
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);
|
||||
|
||||
Extensions.DirectoryCheckCrate(packageSourceDirectory);
|
||||
Extensions.DirectoryCheckCrate(packageTargetDirectory);
|
||||
|
||||
// 파일이 하나도 없을경우 조회실패
|
||||
if (System.IO.Directory.GetFiles(packageSourceDirectory, "*.*", System.IO.SearchOption.AllDirectories).Length == 0)
|
||||
{
|
||||
Console.WriteLine("The source file could not be found.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Packing 임시 파일명
|
||||
var tempFile = "package.temp";
|
||||
|
||||
// Pakcing 작업 시작
|
||||
Packing(packageSourceDirectory, tempFile);
|
||||
|
||||
// 최종 저장 경로 할당
|
||||
var finalTarget = CommonLibrary.Extensions.PathCombineL(packageTargetDirectory , Settings.config.PackageFilename);
|
||||
|
||||
// 최종 저장 경로에 이미 파일이 있다면 삭제
|
||||
if (System.IO.File.Exists(finalTarget))
|
||||
{
|
||||
System.IO.File.Delete(finalTarget);
|
||||
}
|
||||
|
||||
System.IO.File.Move(tempFile, finalTarget);
|
||||
var directories = System.IO.Directory.GetDirectories(packageSourceDirectory);
|
||||
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
|
||||
directories[i] = System.IO.Path.GetRelativePath(Settings.config.Source, directories[i]);
|
||||
}
|
||||
|
||||
dataPatchInformation.PackageDirectorys = directories.ToList();
|
||||
var newVersion = VersionChange(dataPatchInformation.PackageVersion, versionType);
|
||||
Console.WriteLine("Update Version : " + dataPatchInformation.PackageVersion + " → " + newVersion);
|
||||
dataPatchInformation.PackageVersion = newVersion;
|
||||
Settings.SaveDataPatchInformation(dataPatchInformation);
|
||||
Console.WriteLine("Update Complete");
|
||||
}
|
||||
|
||||
public static void ComponentUpdate(VersionType versionType)
|
||||
{
|
||||
Settings.LoadConfig();
|
||||
CommonLibrary.DataPatchInformation dataPatchInformation = Settings.LoadDataPatchInformation();
|
||||
|
||||
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);
|
||||
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
|
||||
Extensions.DeleteEmptyDirectory(componentSourceDirectory);
|
||||
var sourceDirectorys = Extensions.GetDirectoriesRelativePath(componentSourceDirectory, "*", System.IO.SearchOption.AllDirectories);
|
||||
var sourceFiles = Extensions.GetFilesRelativePath(componentSourceDirectory, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
var oldDirectorys = Extensions.GetDirectoriesRelativePath(componentTargetDirectory, "*", System.IO.SearchOption.AllDirectories);
|
||||
var oldFiles = Extensions.GetFilesRelativePath(componentTargetDirectory, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
// 없어진 파일 삭제
|
||||
foreach (string oFile in oldFiles)
|
||||
{
|
||||
if (!sourceFiles.Contains(oFile))
|
||||
{
|
||||
var fullPath = CommonLibrary.Extensions.PathCombineL(componentTargetDirectory, oFile);
|
||||
System.IO.File.Delete(fullPath);
|
||||
Console.WriteLine("DeleteFile : " + oFile);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string oDirectory in oldDirectorys)
|
||||
{
|
||||
if (!sourceDirectorys.Contains(oDirectory))
|
||||
{
|
||||
var fullPath = CommonLibrary.Extensions.PathCombineL(componentTargetDirectory, oDirectory);
|
||||
System.IO.Directory.Delete(fullPath);
|
||||
Console.WriteLine("DeleteDirectory : " + oDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
// 새로운 파일 추가
|
||||
foreach (string sDirectory in sourceDirectorys)
|
||||
{
|
||||
if (!oldDirectorys.Contains(sDirectory))
|
||||
{
|
||||
var fullPath = CommonLibrary.Extensions.PathCombineL(componentTargetDirectory, sDirectory);
|
||||
System.IO.Directory.CreateDirectory(fullPath);
|
||||
Console.WriteLine("CreateDirectory : " + sDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string sFile in sourceFiles)
|
||||
{
|
||||
if (!oldFiles.Contains(sFile))
|
||||
{
|
||||
var sourceFileFullPath = CommonLibrary.Extensions.PathCombineL(componentSourceDirectory, sFile);
|
||||
var targetFileFullPath = CommonLibrary.Extensions.PathCombineL(componentTargetDirectory, sFile);
|
||||
System.IO.File.Copy(sourceFileFullPath, targetFileFullPath);
|
||||
Console.WriteLine("Copy NewFile : " + sFile);
|
||||
}
|
||||
}
|
||||
|
||||
// 무결성 검사 후 업데이트
|
||||
oldFiles = Extensions.GetFilesRelativePath(componentTargetDirectory, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
foreach (string oFile in oldFiles)
|
||||
{
|
||||
var sourceFileFullPath = CommonLibrary.Extensions.PathCombineL(componentSourceDirectory, oFile);
|
||||
var targetFileFullPath = CommonLibrary.Extensions.PathCombineL(componentTargetDirectory, oFile);
|
||||
|
||||
var sourceHash = Extensions.GetFileHash(sourceFileFullPath);
|
||||
var targetHash = Extensions.GetFileHash(targetFileFullPath);
|
||||
|
||||
if (targetHash != sourceHash)
|
||||
{
|
||||
System.IO.File.Delete(targetFileFullPath);
|
||||
System.IO.File.Copy(sourceFileFullPath, targetFileFullPath);
|
||||
Console.Write("Update File : " + oFile);
|
||||
}
|
||||
}
|
||||
|
||||
List<CommonLibrary.FileDetail> fileDetails = new List<CommonLibrary.FileDetail>();
|
||||
for (int i = 0; i < sourceFiles.Length; i++)
|
||||
{
|
||||
CommonLibrary.FileDetail fileDetail = new CommonLibrary.FileDetail();
|
||||
string fullPath = CommonLibrary.Extensions.PathCombineL(componentTargetDirectory, sourceFiles[i]);
|
||||
fileDetail.Directory = System.IO.Path.GetDirectoryName(sourceFiles[i]);
|
||||
fileDetail.FileName = System.IO.Path.GetFileName(sourceFiles[i]);
|
||||
System.IO.FileInfo fi = new System.IO.FileInfo(fullPath);
|
||||
fileDetail.FileSize = fi.Length;
|
||||
fileDetail.HashCode = Extensions.GetFileHash(fullPath);
|
||||
fileDetails.Add(fileDetail);
|
||||
}
|
||||
// 시작
|
||||
dataPatchInformation.ComponentList = fileDetails;
|
||||
dataPatchInformation.ComponentDirectorys = sourceDirectorys.ToList();
|
||||
// 파일 디테일
|
||||
|
||||
|
||||
var newVersion = VersionChange(dataPatchInformation.ComponentVersion, versionType);
|
||||
Console.WriteLine("Update Version : " + dataPatchInformation.ComponentVersion + " → " + newVersion);
|
||||
dataPatchInformation.ComponentVersion = newVersion;
|
||||
Settings.SaveDataPatchInformation(dataPatchInformation);
|
||||
Console.WriteLine("Update Complete");
|
||||
// 무결성 검사후 업데이트
|
||||
}
|
||||
|
||||
static void Packing(string source, string target)
|
||||
{
|
||||
if (System.IO.File.Exists(target))
|
||||
{
|
||||
System.IO.File.Delete(target);
|
||||
}
|
||||
|
||||
var progressPacker = new CommonLibrary.ProgressPacker();
|
||||
Console.WriteLine("Packing Start");
|
||||
Console.WriteLine("----------------------------------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
nowPosLeft = Console.CursorLeft;
|
||||
nowPosTop = Console.CursorTop;
|
||||
|
||||
Console.CursorVisible = false;
|
||||
progressPacker.Pack(source, target, new CommonLibrary.BasicProgress<double>(ProgressChange));
|
||||
Console.CursorVisible = true;
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("----------------------------------------");
|
||||
Console.WriteLine("Packing Complite");
|
||||
}
|
||||
|
||||
static string VersionChange(string version, VersionType versionType)
|
||||
{
|
||||
var v = Version.Parse(version);
|
||||
|
||||
switch (versionType)
|
||||
{
|
||||
case VersionType.Major:
|
||||
v = new Version(v.Major + 1, 0, 0, 0);
|
||||
break;
|
||||
|
||||
case VersionType.Minor:
|
||||
v = new Version(v.Major, v.Minor + 1, 0, 0);
|
||||
break;
|
||||
|
||||
case VersionType.Build:
|
||||
v = new Version(v.Major, v.Minor, v.Build + 1, 0);
|
||||
break;
|
||||
|
||||
case VersionType.Revision:
|
||||
v = new Version(v.Major, v.Minor, v.Build, v.Revision + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
return v.ToString();
|
||||
}
|
||||
|
||||
static void ProgressChange(double obj)
|
||||
{
|
||||
Console.SetCursorPosition(nowPosLeft, nowPosTop);
|
||||
var Progress = (int)(obj * 10);
|
||||
|
||||
for (int i = 0; i < Progress; i++)
|
||||
Console.Write("■");
|
||||
|
||||
for (int i = 0; i < 10 - Progress; i++)
|
||||
Console.Write("□");
|
||||
|
||||
Console.Write(" " + $"{obj:P2}");
|
||||
}
|
||||
}
|
||||
|
||||
internal enum UpdateType
|
||||
{
|
||||
Launcher,
|
||||
Runtime,
|
||||
Package,
|
||||
Component
|
||||
}
|
||||
|
||||
internal enum VersionType
|
||||
{
|
||||
Major,
|
||||
Minor,
|
||||
Build,
|
||||
Revision
|
||||
}
|
||||
}
|
12
Mitria_Minecraft_Updater/Properties/launchSettings.json
Normal file
12
Mitria_Minecraft_Updater/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Mitria_Minecraft_Updater": {
|
||||
"commandName": "Project"
|
||||
},
|
||||
"WSL": {
|
||||
"commandName": "WSL2",
|
||||
"environmentVariables": {},
|
||||
"distributionName": ""
|
||||
}
|
||||
}
|
||||
}
|
145
Mitria_Minecraft_Updater/Settings.cs
Normal file
145
Mitria_Minecraft_Updater/Settings.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
|
||||
namespace Mitria_Minecraft_Updater
|
||||
{
|
||||
public static class Settings
|
||||
{
|
||||
#pragma warning disable S1104 // Fields should not have public accessibility
|
||||
#pragma warning disable S2223 // Non-constant static fields should not be visible
|
||||
public static Config config;
|
||||
#pragma warning restore S2223 // Non-constant static fields should not be visible
|
||||
#pragma warning restore S1104 // Fields should not have public accessibility
|
||||
public static readonly string configPath = "config.xml";
|
||||
|
||||
private static void InitializationConfig()
|
||||
{
|
||||
// 줄여야함
|
||||
config.Source = "./Source";
|
||||
config.Target = "./Target";
|
||||
|
||||
config.InformationToLauncher = "/Launcher.xml";
|
||||
config.InformationToData = "/Data.xml";
|
||||
|
||||
config.LauncherSource = "/Launcher";
|
||||
config.LauncherUrl = "/Data/Launcher";
|
||||
config.LauncherFileName = "MitriaMLauncher.exe";
|
||||
config.RuntimeSource = "/Runtime";
|
||||
config.RuntimeUrl = "/Data/Runtime";
|
||||
config.RuntimeFilename = "Runtime.pack";
|
||||
config.PackageSource = "/Package";
|
||||
config.PackageUrl = "/Data/Package";
|
||||
config.PackageFilename = "Package.pack";
|
||||
config.ComponentSource = "/Component";
|
||||
config.ComponentUrl = "/Data/Component";
|
||||
}
|
||||
|
||||
public static void LoadConfig()
|
||||
{
|
||||
if (System.IO.File.Exists(configPath))
|
||||
{
|
||||
config = CommonLibrary.XMLSystem.LoadFromPath<Config>(configPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
InitializationConfig();
|
||||
SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveConfig()
|
||||
{
|
||||
CommonLibrary.XMLSystem.Save(configPath, config);
|
||||
}
|
||||
|
||||
public static CommonLibrary.LauncherPatchInformation LoadLauncherPatchInformation()
|
||||
{
|
||||
CommonLibrary.LauncherPatchInformation launcherPatchInformation = new CommonLibrary.LauncherPatchInformation();
|
||||
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target, config.InformationToLauncher);
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
launcherPatchInformation = CommonLibrary.XMLSystem.LoadFromPath<CommonLibrary.LauncherPatchInformation>(fullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
launcherPatchInformation.Version = "0.0.0.0";
|
||||
}
|
||||
// 혹시모를 변경 될수도 있음
|
||||
launcherPatchInformation.LauncherUrl = config.LauncherUrl;
|
||||
launcherPatchInformation.LauncherFileName = config.LauncherFileName;
|
||||
return launcherPatchInformation;
|
||||
}
|
||||
|
||||
public static void SaveLauncherPatchInformation(CommonLibrary.LauncherPatchInformation launcherPatchInformation)
|
||||
{
|
||||
|
||||
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target, config.InformationToLauncher);
|
||||
if (!System.IO.Directory.Exists(config.Target))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(config.Target);
|
||||
}
|
||||
CommonLibrary.XMLSystem.Save(fullPath, launcherPatchInformation);
|
||||
}
|
||||
|
||||
public static CommonLibrary.DataPatchInformation LoadDataPatchInformation()
|
||||
{
|
||||
CommonLibrary.DataPatchInformation dataPatchInformation = new CommonLibrary.DataPatchInformation();
|
||||
string fullPath = config.Target + config.InformationToData;
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
dataPatchInformation = CommonLibrary.XMLSystem.LoadFromPath<CommonLibrary.DataPatchInformation>(fullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataPatchInformation.RuntimeVersion = "0.0.0.0";
|
||||
dataPatchInformation.PackageVersion = "0.0.0.0";
|
||||
dataPatchInformation.PackageDirectorys = new System.Collections.Generic.List<string>();
|
||||
dataPatchInformation.ComponentVersion = "0.0.0.0";
|
||||
dataPatchInformation.ComponentDirectorys = new System.Collections.Generic.List<string>();
|
||||
dataPatchInformation.ComponentList = new System.Collections.Generic.List<CommonLibrary.FileDetail>();
|
||||
}
|
||||
dataPatchInformation.RuntimeUrl = config.RuntimeUrl;
|
||||
dataPatchInformation.RuntimeFileName = config.RuntimeFilename;
|
||||
dataPatchInformation.PackageUrl = config.PackageUrl;
|
||||
dataPatchInformation.PackageFileName = config.PackageFilename;
|
||||
dataPatchInformation.ComponentUrl = config.ComponentUrl;
|
||||
|
||||
return dataPatchInformation;
|
||||
}
|
||||
|
||||
public static void SaveDataPatchInformation(CommonLibrary.DataPatchInformation dataPatchInformation)
|
||||
{
|
||||
string fullPath = CommonLibrary.Extensions.PathCombineL(config.Target , config.InformationToData);
|
||||
if (!System.IO.Directory.Exists(config.Target))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(config.Target);
|
||||
}
|
||||
CommonLibrary.XMLSystem.Save(fullPath, dataPatchInformation);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct Config
|
||||
{
|
||||
public string Source { get; set; } //./Source
|
||||
public string Target { get; set; } ///usr/share/nginx/html/Patchdata
|
||||
public string DataDirectory { get; set; } // {Target}/Data
|
||||
|
||||
public string InformationToLauncher { get; set; } //{InformationDirectory}/Launcher.xml
|
||||
public string InformationToData { get; set; } // {InformationDirectory}/Data.xml
|
||||
|
||||
public string LauncherSource { get; set; } // {Source}/Launcher
|
||||
public string LauncherUrl { get; set; } // {Target}/Launcher
|
||||
public string LauncherFileName { get; set; } // 런처 파일이름
|
||||
|
||||
public string RuntimeSource { get; set; } // {Source}/Runtime
|
||||
public string RuntimeUrl { get; set; } // {Target}/Runtime
|
||||
public string RuntimeFilename { get; set; } // Runtime.pack
|
||||
|
||||
public string PackageSource { get; set; } // {Source}/Package
|
||||
public string PackageUrl { get; set; } // {Target}/Package
|
||||
public string PackageFilename { get; set; } // Package.pack
|
||||
|
||||
public string ComponentSource { get; set; } // {Source}/GameFile
|
||||
public string ComponentUrl { get; set; } // {Target}/GameFile
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user