changed response logic
This commit is contained in:
@@ -20,7 +20,7 @@ using DTLib.Web.Routes;
|
||||
|
||||
namespace ParadoxSaveParser.WebAPI;
|
||||
|
||||
public partial class Program
|
||||
public static partial class Program
|
||||
{
|
||||
private static readonly IOPath _configPath = "./config.dtsod";
|
||||
private static Config _config = new();
|
||||
@@ -28,23 +28,23 @@ public partial class Program
|
||||
private static readonly ILogger _loggerRoot = new CompositeLogger(
|
||||
new ConsoleLogger(),
|
||||
new FileLogger("logs", "ParadoxSaveParser.WebAPI"));
|
||||
|
||||
|
||||
private static readonly CancellationTokenSource _mainCancel = new();
|
||||
private static ConcurrentDictionary<string, SaveFileMetadata> _saveMetadataStorage = new();
|
||||
|
||||
private static JsonSerializerOptions _saveSerializerOptions = new()
|
||||
private static readonly ConcurrentDictionary<string, SaveFileMetadata> _saveMetadataStorage = new();
|
||||
|
||||
private static readonly JsonSerializerOptions _saveSerializerOptions = new()
|
||||
{
|
||||
WriteIndented = false,
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
MaxDepth = 1024,
|
||||
MaxDepth = 1024
|
||||
};
|
||||
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.InputEncoding = Encoding.UTF8;
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
Console.CursorVisible = false;
|
||||
ContextLogger logger = new ContextLogger(nameof(Main), _loggerRoot);
|
||||
var logger = new ContextLogger(nameof(Main), _loggerRoot);
|
||||
Console.CancelKeyPress += (_, e) =>
|
||||
{
|
||||
e.Cancel = true;
|
||||
@@ -61,7 +61,10 @@ public partial class Program
|
||||
File.WriteAllText(_configPath, _config.ToString());
|
||||
logger.LogWarn($"created default at {_configPath}.");
|
||||
}
|
||||
else _config = Config.FromDtsod(new DtsodV23(File.ReadAllText(_configPath)));
|
||||
else
|
||||
{
|
||||
_config = Config.FromDtsod(new DtsodV23(File.ReadAllText(_configPath)));
|
||||
}
|
||||
|
||||
PrepareLocalFiles();
|
||||
|
||||
@@ -89,21 +92,19 @@ public partial class Program
|
||||
{
|
||||
Directory.Create(PathHelper.DATA_DIR);
|
||||
Directory.Create(PathHelper.SAVES_DIR);
|
||||
foreach (var metaFilePath in System.IO.Directory.GetFiles(
|
||||
foreach (string metaFilePath in System.IO.Directory.GetFiles(
|
||||
PathHelper.SAVES_DIR.Str, "*.meta.json",
|
||||
SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
using var metaFile = File.OpenRead(metaFilePath);
|
||||
var meta = JsonSerializer.Deserialize<SaveFileMetadata>(metaFile) ??
|
||||
var meta = JsonSerializer.Deserialize<SaveFileMetadata>(metaFile) ??
|
||||
throw new NullReferenceException(metaFilePath);
|
||||
if (meta.status != SaveFileProcessingStatus.Done)
|
||||
{
|
||||
_loggerRoot.LogWarn(nameof(PrepareLocalFiles), $"metadata file '{metaFilePath}' status has invalid status {meta.status}");
|
||||
}
|
||||
_loggerRoot.LogWarn(nameof(PrepareLocalFiles),
|
||||
$"metadata file '{metaFilePath}' status has invalid status {meta.status}");
|
||||
|
||||
if(!_saveMetadataStorage.TryAdd(meta.id, meta))
|
||||
if (!_saveMetadataStorage.TryAdd(meta.id, meta))
|
||||
throw new Exception("Guid collision!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user