mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-12 11:26:30 +03:00
commit
This commit is contained in:
42
src/KeyKeeper/Views/AppSettings.cs
Normal file
42
src/KeyKeeper/Views/AppSettings.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace KeyKeeper;
|
||||||
|
|
||||||
|
public static class AppSettings
|
||||||
|
{
|
||||||
|
private static readonly string FilePath = "settings.json";
|
||||||
|
|
||||||
|
public static bool ExitOnRepositoryClose { get; set; } = false;
|
||||||
|
|
||||||
|
// Сохранение в файл
|
||||||
|
public static void Save()
|
||||||
|
{
|
||||||
|
var data = new { ExitOnRepositoryClose };
|
||||||
|
string json = JsonSerializer.Serialize(data);
|
||||||
|
File.WriteAllText(FilePath, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Загрузка из файла
|
||||||
|
public static void Load()
|
||||||
|
{
|
||||||
|
if (File.Exists(FilePath))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string json = File.ReadAllText(FilePath);
|
||||||
|
var data = JsonSerializer.Deserialize<SettingsData>(json);
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
ExitOnRepositoryClose = data.ExitOnRepositoryClose;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { /* Если файл поврежден, просто используем значения по умолчанию */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SettingsData
|
||||||
|
{
|
||||||
|
public bool ExitOnRepositoryClose { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user