add appstate

This commit is contained in:
Matt Parker
2025-10-01 19:47:47 +10:00
parent 8a0dd9109e
commit 4651c8012c
6 changed files with 74 additions and 9 deletions

View File

@@ -0,0 +1,19 @@
namespace SharpIDE.Godot.Features.IdeSettings;
public class AppState
{
public string? LastOpenSolutionFilePath { get; set; }
public IdeSettings IdeSettings { get; set; } = new IdeSettings();
public List<PreviouslyOpenedSln> PreviouslyOpenedSolutions { get; set; } = [];
}
public class IdeSettings
{
public bool AutoOpenLastSolution { get; set; }
}
public class PreviouslyOpenedSln
{
public required string Name { get; set; }
public required string FilePath { get; set; }
}

View File

@@ -0,0 +1 @@
uid://ccsfv10f1lhxd

View File

@@ -0,0 +1,39 @@
using System.Text.Json;
using Ardalis.GuardClauses;
namespace SharpIDE.Godot.Features.IdeSettings;
public static class AppStateLoader
{
private static string GetConfigFilePath()
{
var folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var configFolder = Path.Combine(folder, "SharpIDE");
Directory.CreateDirectory(configFolder);
var configFilePath = Path.Combine(configFolder, "sharpIde.json");
return configFilePath;
}
public static AppState LoadAppStateFromConfigFile()
{
var configFilePath = GetConfigFilePath();
if (File.Exists(configFilePath) is false)
{
File.WriteAllText(configFilePath, "{}");
}
using var stream = File.OpenRead(configFilePath);
var deserializedAppState = JsonSerializer.Deserialize<AppState>(stream);
Guard.Against.Null(deserializedAppState, nameof(deserializedAppState));
return deserializedAppState;
}
public static void SaveAppStateToConfigFile(AppState appState)
{
var configFilePath = GetConfigFilePath();
using var stream = File.Create(configFilePath);
JsonSerializer.Serialize(stream, appState);
stream.Flush();
}
}

View File

@@ -0,0 +1 @@
uid://dnu6x5m37dapi