천호석
2022-06-17 c6b6801427b900d82d726eae0808c1beaf86df3b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
 
namespace SHARP_CLAS_UI
{
    public class Parameter_System_Manager
    {
        #region Define
        string str_mode = "mode.xml";
        string str_setting = "setting.xml";
        #endregion
 
        #region Property
        private static readonly Lazy<Parameter_System_Manager> _instatnce = new Lazy<Parameter_System_Manager>(() => new Parameter_System_Manager());
 
        public static Parameter_System_Manager Instance
        {
            get
            {
                return _instatnce.Value;
            }
        }
        #endregion
 
        #region Field
        private Xml_Manager<Parameter_Mode> mode_xml_manager = new Xml_Manager<Parameter_Mode>();
        private Xml_Manager<Parameter_Setting> setting_xml_manager = new Xml_Manager<Parameter_Setting>();
 
        Parameter_Mode mode;
        Parameter_Setting setting;
        private string file_path;
        #endregion
 
        #region Construct
        public Parameter_System_Manager()
        {
            Get_File_Path();
            mode = new Parameter_Mode();
            setting = new Parameter_Setting();
            Get_System_Mode();
            Get_System_Setting();
        }
        #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("SYSTEM_PARAMETER", @"C:\SHARP_CLAS\Config\SETTING\");
                    file_path = @"C:\SHARP_CLAS\Config\SETTING\";
                }
                else
                {
                    object value = rkk.GetValue("SYSTEM_PARAMETER");
                    if (value == null)
                    {
                        rkk.SetValue("SYSTEM_PARAMETER", @"C:\SHARP_CLAS\Config\SETTING\");
                        file_path = @"C:\SHARP_CLAS\Config\SETTING\";
                    }
                    else
                    {
                        file_path = value.ToString();
                    }
                }
            }
            finally
            {
                rkk.Close();
            }
        }
 
        private void Get_System_Mode()
        {
            Get_File_Path();
            
            if (Directory.Exists(file_path))
            {
                Parameter_Mode mode = mode_xml_manager.Read_File(file_path + str_mode);
 
                if(mode != null)
                {
                    this.mode = mode;
                }
            }
            else
            {
                Directory.CreateDirectory(file_path);
            }
        }
 
        private void Get_System_Setting()
        {
            Get_File_Path();
 
            if (Directory.Exists(file_path))
            {
                Parameter_Setting setting = setting_xml_manager.Read_File(file_path + str_setting);
 
                if(setting != null)
                {
                    this.setting = setting;
                }
            }
            else
            {
                Directory.CreateDirectory(file_path);
            }
        }
 
        public bool Save_System_Mode(Parameter_Mode mode)
        {
            this.mode = mode.Clone();
            return mode_xml_manager.Try_Save_File(file_path + str_mode, mode);
        }
 
        public bool Save_System_Setting(Parameter_Setting setting)
        {
            this.setting = setting.Clone();
            return setting_xml_manager.Try_Save_File(file_path + str_setting, setting);
        }
 
        public Parameter_Mode Get_Mode()
        {
            return mode.Clone();
        }
 
        public Parameter_Setting Get_Setting()
        {
            return setting.Clone();
        }
        #endregion
    }
}