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(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(); } } } 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(); 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(path); } else { UserClientVersion = new ClientVersion(); UserClientVersion.PackageVersion = "0.0.0.0"; UserClientVersion.PackageDirectorys = new List(); UserClientVersion.ComponentVersion = "0.0.0.0"; UserClientVersion.ComponentDirectorys = new List(); } } 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); } } }