using Microsoft.Win32;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
|
|
namespace SHARP_CLAS_UI
|
{
|
public class Equipment_Info_Manager
|
{
|
#region Define
|
string str_equipment_info = "equipment_info.xml";
|
#endregion
|
|
#region Property
|
private static readonly Lazy<Equipment_Info_Manager> _instatnce = new Lazy<Equipment_Info_Manager>(() => new Equipment_Info_Manager());
|
|
public static Equipment_Info_Manager Instance
|
{
|
get
|
{
|
return _instatnce.Value;
|
}
|
}
|
#endregion
|
|
#region Field
|
Equipment_Info equipment_info;
|
|
private Xml_Manager<Equipment_Info> xml_manager = new Xml_Manager<Equipment_Info>();
|
|
private string file_path;
|
#endregion
|
|
#region Construct
|
public Equipment_Info_Manager()
|
{
|
equipment_info = new Equipment_Info();
|
Get_Equipment_Info();
|
}
|
#endregion
|
|
#region Function
|
private void Get_File_Path()
|
{
|
RegistryKey rkk = Registry.CurrentUser.OpenSubKey(Equipment.Registry_Path, true);
|
|
try
|
{
|
if (rkk == null)
|
{
|
rkk = Registry.CurrentUser.CreateSubKey(Equipment.Registry_Path);
|
|
rkk.SetValue("EQUIPMENT_INFO", @"C:\SHARP_CLAS\SETTING\EQUIPMENT_INFO\");
|
file_path = @"C:\SHARP_CLAS\SETTING\EQUIPMENT_INFO\";
|
}
|
else
|
{
|
object value = rkk.GetValue("EQUIPMENT_INFO");
|
if (value == null)
|
{
|
rkk.SetValue("EQUIPMENT_INFO", @"C:\SHARP_CLAS\SETTING\EQUIPMENT_INFO\");
|
file_path = @"C:\SHARP_CLAS\SETTING\EQUIPMENT_INFO\";
|
}
|
else
|
{
|
file_path = value.ToString();
|
}
|
}
|
}
|
finally
|
{
|
rkk.Close();
|
}
|
}
|
|
private void Get_Equipment_Info()
|
{
|
Get_File_Path();
|
|
if (Directory.Exists(file_path))
|
{
|
Equipment_Info info = xml_manager.Read_File(file_path + str_equipment_info);
|
|
if (info != null)
|
{
|
this.equipment_info = info;
|
}
|
}
|
else
|
{
|
Directory.CreateDirectory(file_path);
|
}
|
}
|
|
public bool Save_Equipment_Info(Equipment_Info info)
|
{
|
this.equipment_info = info.Clone();
|
return xml_manager.Try_Save_File(file_path + str_equipment_info, equipment_info);
|
}
|
|
public Equipment_Info Get_Info()
|
{
|
return equipment_info.Clone();
|
}
|
#endregion
|
}
|
}
|