change settings.json path to the standard one

This commit is contained in:
2026-04-26 21:41:05 +03:00
parent b4429354c3
commit 339766bdc3

View File

@@ -1,17 +1,22 @@
using System.IO; using System;
using System.IO;
using System.Text.Json; using System.Text.Json;
namespace KeyKeeper; namespace KeyKeeper;
public static class AppSettings public static class AppSettings
{ {
private static readonly string FilePath = "settings.json"; private static readonly string FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "KeyKeeper", "settings.json");
public static bool ExitOnRepositoryClose { get; set; } = false; public static bool ExitOnRepositoryClose { get; set; } = false;
// Сохранение в файл // Сохранение в файл
public static void Save() public static void Save()
{ {
var directory = Path.GetDirectoryName(FilePath);
if (!string.IsNullOrEmpty(directory))
Directory.CreateDirectory(directory);
var data = new { ExitOnRepositoryClose }; var data = new { ExitOnRepositoryClose };
string json = JsonSerializer.Serialize(data); string json = JsonSerializer.Serialize(data);
File.WriteAllText(FilePath, json); File.WriteAllText(FilePath, json);
@@ -39,4 +44,4 @@ public static class AppSettings
{ {
public bool ExitOnRepositoryClose { get; set; } public bool ExitOnRepositoryClose { get; set; }
} }
} }