From c29658e7e4f5c3f9d7c96820de152ca40223cf64 Mon Sep 17 00:00:00 2001 From: shept Date: Thu, 1 Jan 2026 05:10:44 +0500 Subject: [PATCH] add storage functionality and appdata model --- .../Intefaces/IStorageService.cs | 9 +++++ MetaforceInstaller.Core/Models/AppData.cs | 6 ++++ .../Services/StorageService.cs | 36 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 MetaforceInstaller.Core/Intefaces/IStorageService.cs create mode 100644 MetaforceInstaller.Core/Models/AppData.cs create mode 100644 MetaforceInstaller.Core/Services/StorageService.cs diff --git a/MetaforceInstaller.Core/Intefaces/IStorageService.cs b/MetaforceInstaller.Core/Intefaces/IStorageService.cs new file mode 100644 index 0000000..5967309 --- /dev/null +++ b/MetaforceInstaller.Core/Intefaces/IStorageService.cs @@ -0,0 +1,9 @@ +using MetaforceInstaller.Core.Models; + +namespace MetaforceInstaller.Core.Intefaces; + +public interface IStorageService +{ + AppData Load(); + void Save(AppData data); +} \ No newline at end of file diff --git a/MetaforceInstaller.Core/Models/AppData.cs b/MetaforceInstaller.Core/Models/AppData.cs new file mode 100644 index 0000000..5c37871 --- /dev/null +++ b/MetaforceInstaller.Core/Models/AppData.cs @@ -0,0 +1,6 @@ +namespace MetaforceInstaller.Core.Models; + +public class AppData +{ + public List Installations { get; set; } = new(); +} \ No newline at end of file diff --git a/MetaforceInstaller.Core/Services/StorageService.cs b/MetaforceInstaller.Core/Services/StorageService.cs new file mode 100644 index 0000000..7fa1601 --- /dev/null +++ b/MetaforceInstaller.Core/Services/StorageService.cs @@ -0,0 +1,36 @@ +using System.Text.Json; +using MetaforceInstaller.Core.Intefaces; +using MetaforceInstaller.Core.Models; + +namespace MetaforceInstaller.Core.Services; + +public class StorageService : IStorageService +{ + private readonly string _storagePath; + + public StorageService() + { + var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + var appDirectory = Path.Combine(appData, "MetaforceInstaller"); + Directory.CreateDirectory(appDirectory); + _storagePath = Path.Combine(appDirectory, "installations.json"); + } + + public AppData Load() + { + if (!File.Exists(_storagePath)) + return new AppData(); + + var json = File.ReadAllText(_storagePath); + return JsonSerializer.Deserialize(json) ?? new AppData(); + } + + public void Save(AppData data) + { + var json = JsonSerializer.Serialize(data, new JsonSerializerOptions + { + WriteIndented = true + }); + File.WriteAllText(_storagePath, json); + } +} \ No newline at end of file