replaced dtsod with json
This commit is contained in:
@@ -12,7 +12,6 @@ global using Directory = DTLib.Filesystem.Directory;
|
||||
global using File = DTLib.Filesystem.File;
|
||||
global using Path = DTLib.Filesystem.Path;
|
||||
using DTLib.Console;
|
||||
using DTLib.Dtsod;
|
||||
using DTLib.Web;
|
||||
using DTLib.Web.Routes;
|
||||
using ParadoxSaveParser.WebAPI.BackgroundTasks;
|
||||
@@ -29,7 +28,7 @@ public static class Program
|
||||
internal static DatabaseConnector DB = null!;
|
||||
|
||||
|
||||
public static async Task Main(string[] args)
|
||||
public static async Task<int> Main(string[] args)
|
||||
{
|
||||
Console.InputEncoding = Encoding.UTF8;
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
@@ -43,7 +42,8 @@ public static class Program
|
||||
new LaunchArgument(["d", "debug"],
|
||||
"enables debug log output to console",
|
||||
() => IsDebug = true)
|
||||
).AllowNoArguments().ParseAndHandle(args);
|
||||
)
|
||||
.AllowNoArguments().ParseAndHandle(args);
|
||||
|
||||
var loggerRoot = new CompositeLogger(
|
||||
new ConsoleLogger
|
||||
@@ -68,23 +68,22 @@ public static class Program
|
||||
try
|
||||
{
|
||||
// config
|
||||
IOPath configPath = "./config.dtsod";
|
||||
IOPath configPath = "config.json";
|
||||
Config config;
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
config = Config.FromDtsod(new DtsodV23(File.ReadAllText(configPath)));
|
||||
config = Config.Load(configPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
loggerMain.LogWarn("config file not found.");
|
||||
config = new();
|
||||
File.WriteAllText(configPath, config.ToString());
|
||||
loggerMain.LogWarn($"created default at {configPath}.");
|
||||
loggerMain.LogWarn($"Config file not found. Creating default config at {configPath}.");
|
||||
config = new Config();
|
||||
config.Save(configPath);
|
||||
}
|
||||
|
||||
|
||||
PathHelper.CreateProgramDirectories();
|
||||
PathHelper.CleanTempDirectory();
|
||||
DB = new("database.sqlite", 30, loggerRoot);
|
||||
DB = new DatabaseConnector(config.DbPath, config.UploadLifetimeDays, loggerRoot);
|
||||
await DB.InitializeAsync();
|
||||
await DB.DeleteInvalidData();
|
||||
|
||||
@@ -93,10 +92,10 @@ public static class Program
|
||||
{
|
||||
{ Game.EU4, new SaveDataFilterEU4() },
|
||||
};
|
||||
|
||||
|
||||
// http server
|
||||
var router = new SimpleRouter(loggerRoot);
|
||||
router.DefaultRoute = new SimpleRouter.RouteWithMethod(HttpMethod.GET,
|
||||
router.DefaultRoute = new SimpleRouter.RouteWithMethod(HttpMethod.GET,
|
||||
new ServeFilesRouteHandler(PathHelper.PUBLIC_DIR));
|
||||
router.MapRoute("/uploadSave", HttpMethod.POST,
|
||||
new UploadSaveHandler(mainCancel.Token, bgJobManager, saveFilters));
|
||||
@@ -108,6 +107,10 @@ public static class Program
|
||||
var app = new WebApp(config.BaseUrl, loggerRoot, router, mainCancel.Token);
|
||||
await app.Run();
|
||||
}
|
||||
catch (LaunchArgumentParser.ExitAfterHelpException)
|
||||
{
|
||||
// this exception is throwed after -h argument to close the program
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
loggerMain.LogWarn($"catched OperationCanceledException from {ex.Source}");
|
||||
@@ -115,6 +118,12 @@ public static class Program
|
||||
catch (Exception ex)
|
||||
{
|
||||
loggerMain.LogError(ex.ToStringDemystified());
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.ResetColor();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user