replaced dtsod with json

This commit is contained in:
2026-09-20 21:08:19 +02:00
parent 5b1b8f4ce5
commit b419fe7679
3 changed files with 113 additions and 90 deletions
+21 -17
View File
@@ -1,21 +1,27 @@
using DTLib.Dtsod;
using System.Text.Json.Serialization;
namespace ParadoxSaveParser.WebAPI;
public class Config
{
[JsonIgnore]
public const int ActualVersion = 1;
public string BaseUrl = "http://127.0.0.1:5226/";
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 int Version = ActualVersion;
public static Config FromDtsod(DtsodV23 d)
public static JsonSerializerOptions JsonOptions = new()
{
var cfg = new Config
{
Version = d["version"],
BaseUrl = d["baseUrl"]
};
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)
@@ -23,12 +29,10 @@ public class Config
return cfg;
}
public DtsodV23 ToDtsod()
=> new()
{
{ "version", Version },
{ "baseUrl", BaseUrl }
};
public override string ToString() => JsonSerializer.Serialize(this, JsonOptions);
public override string ToString() => ToDtsod().ToString();
public void Save(IOPath configPath)
{
File.WriteAllText(configPath, ToString());
}
}