Files
ParadoxSaveParser/ParadoxSaveParser.WebAPI/Config.cs
T

47 lines
1.7 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 SaveUploadConfig SaveUpload { get; set; } = new();
public class SaveUploadConfig
{
/// max size of game data entry after decompression
public long MaxSizePlainTextBytes { get; set; } = 200 * 1024 * 1024;
/// max size of uploaded .tar.zst
public long MaxSizeCompressedBytes { get; set; } = 60 * 1024 * 1024;
}
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());
}
}