57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace VisionAsist.Models;
|
|
|
|
public class AppSettings
|
|
{
|
|
public string OllamaBaseUrl { get; set; } = "http://localhost:11434/api";
|
|
public string OllamaModel { get; set; } = "llama3";
|
|
}
|
|
|
|
public static class SettingsManager
|
|
{
|
|
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
|
|
private static AppSettings _current = new();
|
|
|
|
public static AppSettings Current => _current;
|
|
|
|
static SettingsManager()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
public static void Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(SettingsFilePath))
|
|
{
|
|
var json = File.ReadAllText(SettingsFilePath);
|
|
_current = JsonSerializer.Deserialize<AppSettings>(json) ?? new AppSettings();
|
|
}
|
|
else
|
|
{
|
|
Save();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
_current = new AppSettings();
|
|
}
|
|
}
|
|
|
|
public static void Save()
|
|
{
|
|
try
|
|
{
|
|
var json = JsonSerializer.Serialize(_current, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(SettingsFilePath, json);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error saving settings: {ex.Message}");
|
|
}
|
|
}
|
|
} |