From 814e6018705ee7ea3d5e111bf9431b955214080a Mon Sep 17 00:00:00 2001 From: Creeper Lv Date: Sun, 4 Jan 2026 05:35:39 +1100 Subject: [PATCH] Made a storage provider interface and both classic and avalonia impl. --- .../Storage/ClassicStorageProvider.cs | 36 ++++++++ Progrart.Core/Storage/IStorageProvider.cs | 12 +++ Progrart/App.axaml | 2 +- Progrart/App.axaml.cs | 2 + .../Core/Storage/AvaloniaStorageProvider.cs | 42 ++++++++++ Progrart/Pages/AboutPage.axaml | 3 + Progrart/Pages/Console.axaml | 24 ++++++ Progrart/Pages/Console.axaml.cs | 83 +++++++++++++++++++ 8 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 Progrart.Core/Storage/ClassicStorageProvider.cs create mode 100644 Progrart.Core/Storage/IStorageProvider.cs create mode 100644 Progrart/Core/Storage/AvaloniaStorageProvider.cs create mode 100644 Progrart/Pages/Console.axaml create mode 100644 Progrart/Pages/Console.axaml.cs diff --git a/Progrart.Core/Storage/ClassicStorageProvider.cs b/Progrart.Core/Storage/ClassicStorageProvider.cs new file mode 100644 index 0000000..8e99398 --- /dev/null +++ b/Progrart.Core/Storage/ClassicStorageProvider.cs @@ -0,0 +1,36 @@ +namespace Progrart.Core.Storage +{ + public class ClassicStorageProvider : IStorageProvider + { + public DirectoryInfo BaseDirectory; + + public ClassicStorageProvider(DirectoryInfo baseDirectory) + { + BaseDirectory = baseDirectory; + } + + public async Task TryOpenRead(string path) + { + try + { + return File.OpenRead(Path.Combine(BaseDirectory.FullName, path)); + } + catch (Exception) + { + return null; + } + } + + public async Task TryOpenWrite(string path) + { + try + { + return File.OpenWrite(Path.Combine(BaseDirectory.FullName, path)); + } + catch (Exception) + { + return null; + } + } + } +} diff --git a/Progrart.Core/Storage/IStorageProvider.cs b/Progrart.Core/Storage/IStorageProvider.cs new file mode 100644 index 0000000..719da6d --- /dev/null +++ b/Progrart.Core/Storage/IStorageProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Progrart.Core.Storage +{ + public interface IStorageProvider + { + Task TryOpenRead(string path); + Task TryOpenWrite(string path); + } +} diff --git a/Progrart/App.axaml b/Progrart/App.axaml index 170ffb1..31a6e9e 100644 --- a/Progrart/App.axaml +++ b/Progrart/App.axaml @@ -289,7 +289,7 @@