67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
using Newtonsoft.Json;
|
|
|
|
namespace ModpackUpdater;
|
|
|
|
public class AppConfig
|
|
{
|
|
public string LastMinecraftProfilePath { get; set; }
|
|
public string LastConfigFilePath { get; set; }
|
|
public List<string> KeepLocalFiles { get; set; } = [];
|
|
|
|
public void Reset()
|
|
{
|
|
KeepLocalFiles.Clear();
|
|
KeepLocalFiles.Add("OptiFine_1.7.10_HD_U_E7.jar");
|
|
}
|
|
|
|
private static AppConfig instance = null;
|
|
|
|
public static AppConfig Instance
|
|
{
|
|
get
|
|
{
|
|
|
|
if (instance is null)
|
|
{
|
|
if (File.Exists(SettingsPath))
|
|
instance = LoadConfig(SettingsPath);
|
|
else
|
|
{
|
|
instance = new AppConfig();
|
|
instance.Reset();
|
|
}
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
}
|
|
private static string settingsPath = string.Empty;
|
|
|
|
private static string SettingsPath
|
|
{
|
|
get
|
|
{
|
|
const string AppDataDirectoryName = "MinecraftModpackUpdater";
|
|
const string SettingsFileName = "Settings.json";
|
|
|
|
if (string.IsNullOrEmpty(settingsPath))
|
|
{
|
|
settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataDirectoryName);
|
|
Directory.CreateDirectory(settingsPath);
|
|
settingsPath = Path.Combine(settingsPath, SettingsFileName);
|
|
}
|
|
|
|
return settingsPath;
|
|
}
|
|
}
|
|
|
|
public void SaveConfig()
|
|
{
|
|
File.WriteAllText(SettingsPath, JsonConvert.SerializeObject(this));
|
|
}
|
|
|
|
private static AppConfig LoadConfig(string filePath)
|
|
{
|
|
return JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(filePath));
|
|
}
|
|
} |