57 lines
1.7 KiB
C#
57 lines
1.7 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;
|
|
/// <summary>Windows modifier flags: Alt=1, Ctrl=2, Shift=4, Win=8.</summary>
|
|
public int HotkeyModifiers { get; set; } = 1; // MOD_ALT
|
|
/// <summary>Windows virtual key code (e.g. VK_F9=0x78, VK_PRIOR=0x21 for PgUp).</summary>
|
|
public int HotkeyVirtualKey { get; set; } = 0x78; // VK_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 { }
|
|
}
|
|
}
|
|
} |