v0.4: persistent config in AppData, voices in LOCALAPPDATA, remove Speak button
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System.Text.Json;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Robovoice.App;
|
||||
|
||||
public sealed class AppConfig
|
||||
{
|
||||
public string Voice { get; set; } = string.Empty;
|
||||
public int PttKey { get; set; } = (int)Keys.F8;
|
||||
public string OutputDevice { get; set; } = string.Empty;
|
||||
public int NoiseScale { get; set; } = 667;
|
||||
public int LengthScale { get; set; } = 100;
|
||||
public int NoiseWScale { get; set; } = 800;
|
||||
public bool MinimizeToTray { get; set; } = true;
|
||||
|
||||
public static string AppDataDir => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"Hackmaster", "Robovoice");
|
||||
|
||||
public static string ConfigPath => Path.Combine(AppDataDir, "config.json");
|
||||
public static string VoicesDir => Path.Combine(AppDataDir, "Piper-voices");
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
public static AppConfig Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(ConfigPath))
|
||||
{
|
||||
using var stream = File.OpenRead(ConfigPath);
|
||||
return JsonSerializer.Deserialize<AppConfig>(stream) ?? new AppConfig();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return new AppConfig();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(AppDataDir);
|
||||
using var stream = File.Create(ConfigPath);
|
||||
JsonSerializer.Serialize(stream, this, JsonOptions);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user