From 60f24d69076a204f477d33a13dcaa7a66ef0b6cf Mon Sep 17 00:00:00 2001 From: Timerix Date: Thu, 20 Mar 2025 13:46:01 +0500 Subject: [PATCH] separated classes into files --- ParadoxSaveParser.Lib/Parser.cs | 2 ++ ParadoxSaveParser.Lib/ParserEU4.cs | 7 ++++ ParadoxSaveParser.Lib/SaveData.cs | 6 ++++ ParadoxSaveParser.WebAPI/PathHelper.cs | 12 +++++++ ParadoxSaveParser.WebAPI/Program.cs | 35 -------------------- ParadoxSaveParser.WebAPI/SaveFileMetadata.cs | 30 +++++++++++++++++ 6 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 ParadoxSaveParser.Lib/SaveData.cs create mode 100644 ParadoxSaveParser.WebAPI/PathHelper.cs create mode 100644 ParadoxSaveParser.WebAPI/SaveFileMetadata.cs diff --git a/ParadoxSaveParser.Lib/Parser.cs b/ParadoxSaveParser.Lib/Parser.cs index e3f223e..c52751c 100644 --- a/ParadoxSaveParser.Lib/Parser.cs +++ b/ParadoxSaveParser.Lib/Parser.cs @@ -24,4 +24,6 @@ public abstract class Parser { } + + public abstract SaveData Parse(); } \ No newline at end of file diff --git a/ParadoxSaveParser.Lib/ParserEU4.cs b/ParadoxSaveParser.Lib/ParserEU4.cs index 3542f96..b7ee253 100644 --- a/ParadoxSaveParser.Lib/ParserEU4.cs +++ b/ParadoxSaveParser.Lib/ParserEU4.cs @@ -5,4 +5,11 @@ public class ParserEU4 : Parser public ParserEU4(Stream savefile) : base(savefile) { } + + public override SaveData Parse() + { + var saveData = new SaveData(); + + return saveData; + } } \ No newline at end of file diff --git a/ParadoxSaveParser.Lib/SaveData.cs b/ParadoxSaveParser.Lib/SaveData.cs new file mode 100644 index 0000000..dc352c8 --- /dev/null +++ b/ParadoxSaveParser.Lib/SaveData.cs @@ -0,0 +1,6 @@ +namespace ParadoxSaveParser.Lib; + +public class SaveData +{ + +} \ No newline at end of file diff --git a/ParadoxSaveParser.WebAPI/PathHelper.cs b/ParadoxSaveParser.WebAPI/PathHelper.cs new file mode 100644 index 0000000..ad0ccc1 --- /dev/null +++ b/ParadoxSaveParser.WebAPI/PathHelper.cs @@ -0,0 +1,12 @@ +using System.IO; + +namespace ParadoxSaveParser.WebAPI; + +public static class PathHelper +{ + + public const string DATA_DIR = "data"; + public static string SAVES_DIR = Path.Join(DATA_DIR, "saves"); + public static string GetMetaFilePath(string save_id) => Path.Join(SAVES_DIR, save_id + ".meta.json"); + public static string GetEU4SaveFilePath(string save_id) => Path.Join(SAVES_DIR, save_id + ".eu4"); +} \ No newline at end of file diff --git a/ParadoxSaveParser.WebAPI/Program.cs b/ParadoxSaveParser.WebAPI/Program.cs index 1d26853..f78f030 100644 --- a/ParadoxSaveParser.WebAPI/Program.cs +++ b/ParadoxSaveParser.WebAPI/Program.cs @@ -11,41 +11,6 @@ using ParadoxSaveParser.Lib; namespace ParadoxSaveParser.WebAPI; -public enum SaveFileProcessingStatus -{ - Initialized, Uploading, Parsing, SavingResults, Done, Error -} - -public enum Game -{ - Unknown, EU4 -} - -public class SaveFileMetadata -{ - public required string id { get; init; } - public required Game game { get; init; } - public required SaveFileProcessingStatus status { get; set; } - - public string? errorMesage { get; set; } - - private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true }; - public void SaveToFile() - { - using var metaFile = File.Open(PathHelper.GetMetaFilePath(id), FileMode.CreateNew, FileAccess.Write); - JsonSerializer.Serialize(metaFile, this, _jsonOptions); - } -} - -public static class PathHelper -{ - - public const string DATA_DIR = "data"; - public static string SAVES_DIR = Path.Join(DATA_DIR, "saves"); - public static string GetMetaFilePath(string save_id) => Path.Join(SAVES_DIR, save_id + ".meta.json"); - public static string GetEU4SaveFilePath(string save_id) => Path.Join(SAVES_DIR, save_id + ".eu4"); -} - public class Program { private static ConcurrentDictionary _saveMetadataStorage = new(); diff --git a/ParadoxSaveParser.WebAPI/SaveFileMetadata.cs b/ParadoxSaveParser.WebAPI/SaveFileMetadata.cs new file mode 100644 index 0000000..e21eb37 --- /dev/null +++ b/ParadoxSaveParser.WebAPI/SaveFileMetadata.cs @@ -0,0 +1,30 @@ +using System.IO; +using System.Text.Json; + +namespace ParadoxSaveParser.WebAPI; + +public enum SaveFileProcessingStatus +{ + Initialized, Uploading, Parsing, SavingResults, Done, Error +} + +public enum Game +{ + Unknown, EU4 +} + +public class SaveFileMetadata +{ + public required string id { get; init; } + public required Game game { get; init; } + public required SaveFileProcessingStatus status { get; set; } + + public string? errorMesage { get; set; } + + private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true }; + public void SaveToFile() + { + using var metaFile = File.Open(PathHelper.GetMetaFilePath(id), FileMode.CreateNew, FileAccess.Write); + JsonSerializer.Serialize(metaFile, this, _jsonOptions); + } +} \ No newline at end of file