using Mlaumcherb.Client.Avalonia.зримое; using Mlaumcherb.Client.Avalonia.холопы; namespace Mlaumcherb.Client.Avalonia; public record Config { public bool debug { get; set; } = #if DEBUG true; #else false; #endif public string player_name { get; set; } = ""; public int max_memory { get; set; } = 4096; public string minecraft_dir { get; set; } = "."; public bool download_java { get; set; } = true; public string? last_launched_version { get; set; } public int max_parallel_downloads { get; set; } = 16; [JsonIgnore] static IOPath _filePath = "config.json"; public static Config LoadFromFile() { LauncherApp.Logger.LogInfo(nameof(Config), $"loading config from file '{_filePath}'"); if(!File.Exists(_filePath)) { LauncherApp.Logger.LogInfo(nameof(Config), "file doesn't exist"); return new Config(); } string text = File.ReadAllText(_filePath); string errorMessage = "config is empty"; Config? config = null; try { config = JsonConvert.DeserializeObject(text); } catch (Exception ex) { errorMessage = ex.Message; } if (config == null) { IOPath _brokenPath = _filePath + ".broken"; File.Move(_filePath, _brokenPath, true); ErrorHelper.ShowMessageBox(nameof(Config), $"Can't reed config file '{_filePath}'.\n" + $"New config file has been created. Old is renamed to '{_brokenPath}'.\n\n" + $"Config parser error: {errorMessage}"); config = new Config(); config.SaveToFile(); } LauncherApp.Logger.LogDebug(nameof(Config), $"config has been loaded: {config}"); return config; } public void SaveToFile() { LauncherApp.Logger.LogInfo(nameof(Config), $"saving config to file '{_filePath}'"); var text = JsonConvert.SerializeObject(this, Formatting.Indented); File.WriteAllText(_filePath, text); LauncherApp.Logger.LogDebug(nameof(Config), $"config has been saved: {text}"); } }