initial release
This commit is contained in:
63
ConfigManager.cs
Normal file
63
ConfigManager.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
namespace OpenQuery;
|
||||
|
||||
public class AppConfig
|
||||
{
|
||||
public string ApiKey { get; set; } = "";
|
||||
public string Model { get; set; } = "qwen/qwen3.5-flash-02-23";
|
||||
public int DefaultQueries { get; set; } = 3;
|
||||
public int DefaultChunks { get; set; } = 3;
|
||||
public int DefaultResults { get; set; } = 5;
|
||||
}
|
||||
|
||||
public static class ConfigManager
|
||||
{
|
||||
private static string GetConfigPath()
|
||||
{
|
||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var configDir = Path.Combine(home, ".config", "openquery");
|
||||
if (!Directory.Exists(configDir))
|
||||
{
|
||||
Directory.CreateDirectory(configDir);
|
||||
}
|
||||
return Path.Combine(configDir, "config");
|
||||
}
|
||||
|
||||
public static AppConfig Load()
|
||||
{
|
||||
var config = new AppConfig();
|
||||
var path = GetConfigPath();
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var lines = File.ReadAllLines(path);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var parts = line.Split('=', 2);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
var key = parts[0].Trim();
|
||||
var val = parts[1].Trim();
|
||||
if (key == "ApiKey") config.ApiKey = val;
|
||||
if (key == "Model") config.Model = val;
|
||||
if (key == "DefaultQueries" && int.TryParse(val, out var q)) config.DefaultQueries = q;
|
||||
if (key == "DefaultChunks" && int.TryParse(val, out var c)) config.DefaultChunks = c;
|
||||
if (key == "DefaultResults" && int.TryParse(val, out var r)) config.DefaultResults = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void Save(AppConfig config)
|
||||
{
|
||||
var path = GetConfigPath();
|
||||
var lines = new List<string>
|
||||
{
|
||||
$"ApiKey={config.ApiKey}",
|
||||
$"Model={config.Model}",
|
||||
$"DefaultQueries={config.DefaultQueries}",
|
||||
$"DefaultChunks={config.DefaultChunks}",
|
||||
$"DefaultResults={config.DefaultResults}"
|
||||
};
|
||||
File.WriteAllLines(path, lines);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user