You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
using System;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using leak_test_project.Models;
|
|
|
|
namespace leak_test_project.Utils
|
|
{
|
|
public static class ConfigManager
|
|
{
|
|
private static readonly string ConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.xml");
|
|
public static AppConfig Current { get; private set; } = new AppConfig();
|
|
public static event EventHandler ConfigChanged;
|
|
|
|
static ConfigManager()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
public static void Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(ConfigPath))
|
|
{
|
|
XmlSerializer serializer = new XmlSerializer(typeof(AppConfig));
|
|
using (FileStream fs = new FileStream(ConfigPath, FileMode.Open))
|
|
{
|
|
Current = (AppConfig)serializer.Deserialize(fs);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Current = new AppConfig();
|
|
Save(); // 초기 파일 생성
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"[Config] Error loading config: {ex.Message}");
|
|
Current = new AppConfig();
|
|
}
|
|
}
|
|
|
|
public static void Save()
|
|
{
|
|
try
|
|
{
|
|
XmlSerializer serializer = new XmlSerializer(typeof(AppConfig));
|
|
using (FileStream fs = new FileStream(ConfigPath, FileMode.Create))
|
|
{
|
|
serializer.Serialize(fs, Current);
|
|
}
|
|
ConfigChanged?.Invoke(null, EventArgs.Empty);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"[Config] Error saving config: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|