add appstate
This commit is contained in:
19
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs
Normal file
19
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs
Normal 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; }
|
||||
}
|
||||
1
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs.uid
Normal file
1
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ccsfv10f1lhxd
|
||||
39
src/SharpIDE.Godot/Features/IdeSettings/AppStateLoader.cs
Normal file
39
src/SharpIDE.Godot/Features/IdeSettings/AppStateLoader.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnu6x5m37dapi
|
||||
Reference in New Issue
Block a user