Browse Source

Add BatchResizeWindowConfig #204

Ruben 4 months ago
parent
commit
4923c5645f
1 changed files with 65 additions and 0 deletions
  1. 65 0
      src/PicView.Core/Config/BatchResizeWindowConfig.cs

+ 65 - 0
src/PicView.Core/Config/BatchResizeWindowConfig.cs

@@ -0,0 +1,65 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using PicView.Core.Config.ConfigFileManagement;
+
+namespace PicView.Core.Config;
+
+[JsonSourceGenerationOptions(AllowTrailingCommas = true, WriteIndented = true)]
+[JsonSerializable(typeof(BatchResizeWindowConfig.BatchResizeWindowProperties))]
+internal partial class BatchResizeWindowGenerationContext : JsonSerializerContext;
+public class BatchResizeWindowConfig() : ConfigFile("BatchResizeWindow.json")
+{
+    public BatchResizeWindowProperties? WindowProperties { get; private set;  }
+
+    public async Task LoadAsync()
+    {
+        CorrectPath ??= ConfigFileManager.ResolveDefaultConfigPath(this);
+        try
+        {
+            if (File.Exists(CorrectPath))
+            {
+                var jsonString = await File.ReadAllTextAsync(CorrectPath).ConfigureAwait(false);
+                if (JsonSerializer.Deserialize(
+                        jsonString, typeof(BatchResizeWindowProperties), SettingsWindowGenerationContext.Default) is BatchResizeWindowProperties settings)
+                {
+                    WindowProperties = settings;
+                }
+                else
+                {
+                    WindowProperties = new BatchResizeWindowProperties();
+                } 
+            }
+            else
+            {
+                WindowProperties = new BatchResizeWindowProperties();
+            }
+        }
+        catch
+        {
+            WindowProperties = new BatchResizeWindowProperties();
+        }
+    }
+    
+    public async Task SaveAsync()
+    {
+        CorrectPath = await ConfigFileManager.SaveConfigFileAndReturnPathAsync(this,
+            CorrectPath, WindowProperties, typeof(BatchResizeWindowProperties), SettingsWindowGenerationContext.Default);
+    }
+    
+    public class BatchResizeWindowProperties : IWindowProperties
+    {
+        public int? Top { get; set; }
+        public int? Left { get; set; }
+        public double? Width { get; set; }
+        public double? Height { get; set; }
+        public bool Maximized { get; set; }
+        
+        public int ConvertToIndex { get; set; }
+        public int CompressionIndex { get; set; }
+        public int ResizeIndex { get; set; }
+        public int GenerateThumbnailsIndex { get; set; }
+    }
+}
+
+
+