68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Test_ACS
|
|
{
|
|
/// <summary>
|
|
/// 애플리케이션 설정을 관리하는 클래스
|
|
/// </summary>
|
|
public class AppSettings
|
|
{
|
|
public string LastPort { get; set; } = "COM1";
|
|
public string LastBaudRate { get; set; } = "9600";
|
|
public string LastRFID { get; set; } = "0001";
|
|
public string LastAlias { get; set; } = "CHARGER1";
|
|
public int LastAGV { get; set; } = 11;
|
|
|
|
private static string GetConfigFilePath()
|
|
{
|
|
// 실행 파일과 같은 폴더에 같은 이름으로 .config 파일 생성
|
|
string exePath = Application.ExecutablePath;
|
|
string exeName = Path.GetFileNameWithoutExtension(exePath);
|
|
string configPath = Path.Combine(Path.GetDirectoryName(exePath), exeName + ".config");
|
|
return configPath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 설정 파일을 로드합니다
|
|
/// </summary>
|
|
public static AppSettings Load()
|
|
{
|
|
try
|
|
{
|
|
string configPath = GetConfigFilePath();
|
|
if (File.Exists(configPath))
|
|
{
|
|
string json = File.ReadAllText(configPath);
|
|
return JsonConvert.DeserializeObject<AppSettings>(json);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// 로드 실패 시 기본값 반환
|
|
}
|
|
|
|
return new AppSettings();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 설정을 파일에 저장합니다
|
|
/// </summary>
|
|
public void Save()
|
|
{
|
|
try
|
|
{
|
|
string configPath = GetConfigFilePath();
|
|
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
|
File.WriteAllText(configPath, json);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// 저장 실패 시 무시
|
|
}
|
|
}
|
|
}
|
|
}
|