54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace ClipForge
|
|
{
|
|
public class AppSettings
|
|
{
|
|
public int ClipLengthSeconds { get; set; } = 30;
|
|
public int VideoQuality { get; set; } = 70;
|
|
public int Framerate { get; set; } = 60;
|
|
public string HotkeyDisplay { get; set; } = "Alt + F9";
|
|
}
|
|
|
|
public class SettingsService
|
|
{
|
|
private static string SettingsPath => Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"ClipForge", "settings.json");
|
|
|
|
public AppSettings Settings { get; private set; } = new();
|
|
|
|
public void Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(SettingsPath))
|
|
{
|
|
var json = File.ReadAllText(SettingsPath);
|
|
Settings = JsonSerializer.Deserialize<AppSettings>(json) ?? new();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
Settings = new AppSettings();
|
|
}
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
try
|
|
{
|
|
var dir = Path.GetDirectoryName(SettingsPath)!;
|
|
if (!Directory.Exists(dir))
|
|
Directory.CreateDirectory(dir);
|
|
|
|
var json = JsonSerializer.Serialize(Settings,
|
|
new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(SettingsPath, json);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
} |