38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace ParadoxSaveParser.WebAPI;
|
|
|
|
public class Config
|
|
{
|
|
[JsonIgnore]
|
|
public const int ActualVersion = 1;
|
|
public int Version { get; set; } = ActualVersion;
|
|
public string BaseUrl { get; set; } = "http://127.0.0.1:5226/";
|
|
public int UploadLifetimeDays { get; set; } = 30;
|
|
public string DbPath { get; set; } = "database.sqlite";
|
|
|
|
public static JsonSerializerOptions JsonOptions = new()
|
|
{
|
|
WriteIndented = false,
|
|
MaxDepth = 1024,
|
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
};
|
|
|
|
public static Config Load(IOPath configPath)
|
|
{
|
|
var cfg = JsonSerializer.Deserialize<Config>(File.ReadAllText(configPath))
|
|
?? throw new Exception("Could not parse config file");
|
|
if (cfg.Version < ActualVersion)
|
|
throw new Exception($"config is obsolete (config v{cfg.Version} < program v{ActualVersion})");
|
|
if (cfg.Version > ActualVersion)
|
|
throw new Exception($"program is obsolete (config v{cfg.Version} > program v{ActualVersion})");
|
|
return cfg;
|
|
}
|
|
|
|
public override string ToString() => JsonSerializer.Serialize(this, JsonOptions);
|
|
|
|
public void Save(IOPath configPath)
|
|
{
|
|
File.WriteAllText(configPath, ToString());
|
|
}
|
|
} |