Add project files.
This commit is contained in:
54
ClipForge/SettingsService.cs
Normal file
54
ClipForge/SettingsService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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 { }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user