Files
Better-Seewo/Manager/Services/InkSettings.cs

45 lines
1.5 KiB
C#
Raw Normal View History

using System.IO;
using System.Text.Json;
namespace BetterSeewo.Manager.Services
{
public class InkSettings
{
private static readonly string SettingsPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData),
"BetterEN5", "ink-settings.json");
public bool AutoSaveEnabled { get; set; } = false;
public int AutoSaveIntervalMinutes { get; set; } = 5;
public string SaveDirectory { get; set; } = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),
"Better-Seewo", "Ink");
public static InkSettings Load()
{
try
{
if (File.Exists(SettingsPath))
{
var json = File.ReadAllText(SettingsPath);
return JsonSerializer.Deserialize<InkSettings>(json) ?? new InkSettings();
}
}
catch { }
return new InkSettings();
}
public void Save()
{
try
{
var dir = Path.GetDirectoryName(SettingsPath);
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
Directory.CreateDirectory(dir);
File.WriteAllText(SettingsPath, JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }));
}
catch { }
}
}
}