Files
Crudelis 6fa68e5306 Bug Fix
런처 파일 삭제 버그 수정
2023-02-02 11:05:28 +09:00

146 lines
5.8 KiB
C#

using System.Collections.Generic;
namespace Mitria_Minecraft_Launcher
{
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 LauncherConfig UserLauncherConfig;
public static ClientVersion UserClientVersion;
public static LauncherConfig.Profile NowProfile;
public static CommonLibrary.ServerInformation ServerInformation;
public static readonly string UserLauncherConfigPath = "config.xml";
public static readonly string UserClientVersionPath = "version.xml"; // 위치 // 게임 디렉토리 +
public static readonly string CustomDataDirectory = "CustomData";
public static readonly string RuntimeLocation = "runtime";
#pragma warning disable S1075 // URIs should not be hardcoded
public static readonly string ServerBaseUrl = "http://mitria.kr/Patchdata";
#pragma warning restore S1075 // URIs should not be hardcoded
public static readonly string ServerLauncherPatchInformationFile = "/launcher.xml";
public static readonly string ServerInformationFile = "/server.xml";
public static readonly string ServerDataPatchInformationFile = "/data.xml";
public static void LoadUserLauncherConfig()
{
string path = System.IO.Path.GetFullPath(UserLauncherConfigPath);
if (System.IO.File.Exists(path))
{
UserLauncherConfig = CommonLibrary.XmlSystem.LoadFromPath<LauncherConfig>(path);
}
else
{
UserLauncherConfig = new LauncherConfig();
UserLauncherConfig.MinecraftPlayerName = string.Empty;
UserLauncherConfig.GameDirectory = @"C:\Games\Mitria";
UserLauncherConfig.ShellView = false;
}
}
public static void SaveUserLauncherConfig()
{
SaveProfile();
string path = System.IO.Path.GetFullPath(UserLauncherConfigPath);
string pathDirectory = System.IO.Path.GetDirectoryName(path);
if (!System.IO.Directory.Exists(pathDirectory))
{
System.IO.Directory.CreateDirectory(pathDirectory);
}
CommonLibrary.XmlSystem.Save(path, UserLauncherConfig);
}
public static void ChangeProfile(string serverName)
{
LauncherConfig.Profile myProfile = new LauncherConfig.Profile();
bool exists = false;
if (Settings.UserLauncherConfig.Profiles != null)
{
foreach (var profile in Settings.UserLauncherConfig.Profiles)
{
if (profile.ServerName == serverName)
{
myProfile = profile;
exists = true;
}
}
}
if (!exists)
{
foreach (var server in Settings.ServerInformation.Servers)
{
if (server.ServerName == serverName)
{
myProfile.ServerName = server.ServerName;
myProfile.Argument = server.BaseArgument;
myProfile.OriginalArgument = server.BaseArgument;
myProfile.RuntimeVersion = "0.0.0.0";
myProfile.CustomData = new List<string>();
}
}
}
NowProfile = myProfile;
LoadUserClientVersion();
}
private static void SaveProfile()
{
if(NowProfile.ServerName == string.Empty)
{
return;
}
bool isSave = false;
if(Settings.UserLauncherConfig.Profiles == null)
{
Settings.UserLauncherConfig.Profiles = new List<LauncherConfig.Profile>();
Settings.UserLauncherConfig.Profiles.Add(NowProfile);
return;
}
for (int i = 0; i < Settings.UserLauncherConfig.Profiles.Count; i++)
{
if (NowProfile.ServerName == Settings.UserLauncherConfig.Profiles[i].ServerName)
{
Settings.UserLauncherConfig.Profiles[i] = NowProfile;
isSave = true;
}
}
if(!isSave)
{
Settings.UserLauncherConfig.Profiles.Add(NowProfile);
}
}
public static void LoadUserClientVersion()
{
string path = CommonLibrary.Extensions.PathCombineW(UserLauncherConfig.GameDirectory, NowProfile.ServerName, UserClientVersionPath);
if (System.IO.File.Exists(path))
{
UserClientVersion = CommonLibrary.XmlSystem.LoadFromPath<ClientVersion>(path);
}
else
{
UserClientVersion = new ClientVersion();
UserClientVersion.PackageVersion = "0.0.0.0";
UserClientVersion.PackageDirectorys = new List<string>();
UserClientVersion.ComponentVersion = "0.0.0.0";
UserClientVersion.ComponentDirectorys = new List<string>();
}
}
public static void SaveUserClientVersion()
{
string path = CommonLibrary.Extensions.PathCombineW(UserLauncherConfig.GameDirectory, NowProfile.ServerName, UserClientVersionPath);
string pathDirectory = System.IO.Path.GetDirectoryName(path);
if (!System.IO.Directory.Exists(pathDirectory))
{
System.IO.Directory.CreateDirectory(pathDirectory);
}
CommonLibrary.XmlSystem.Save(path, UserClientVersion);
}
}
}