OSDN Git Service

fix ticket #18663
[yamy/yamy.git] / registry.h
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
2 // registry.h\r
3 \r
4 \r
5 #ifndef _REGISTRY_H\r
6 #  define _REGISTRY_H\r
7 \r
8 #  include "stringtool.h"\r
9 #  include <list>\r
10 \r
11 \r
12 /// registry access class\r
13 class Registry\r
14 {\r
15         HKEY m_root;                                    /// registry root\r
16         tstring m_path;                         /// path from registry root\r
17 \r
18 public:\r
19         typedef std::list<tstring> tstrings;\r
20 \r
21 public:\r
22         ///\r
23         Registry() : m_root(NULL) {\r
24                 setRoot(NULL, _T(""));\r
25         }\r
26         ///\r
27         Registry(HKEY i_root, const tstring &i_path)\r
28                         : m_root(i_root), m_path(i_path) {\r
29                 setRoot(i_root, i_path);\r
30         }\r
31 \r
32         /// set registry root and path\r
33         void setRoot(HKEY i_root, const tstring &i_path) {\r
34                 m_root = i_root;\r
35                 if (m_root) {\r
36                         m_path = i_path;\r
37                 } else {\r
38                         _TCHAR exePath[GANA_MAX_PATH];\r
39                         _TCHAR exeDrive[GANA_MAX_PATH];\r
40                         _TCHAR exeDir[GANA_MAX_PATH];\r
41                         GetModuleFileName(NULL, exePath, GANA_MAX_PATH);\r
42                         _tsplitpath_s(exePath, exeDrive, GANA_MAX_PATH, exeDir, GANA_MAX_PATH, NULL, 0, NULL, 0);\r
43                         m_path = exeDrive;\r
44                         m_path += exeDir;\r
45                         m_path += _T("yamy.ini");\r
46                 }\r
47         }\r
48 \r
49         /// remvoe\r
50         bool remove(const tstring &i_name = _T("")) const {\r
51                 return remove(m_root, m_path, i_name);\r
52         }\r
53 \r
54         /// does exist the key ?\r
55         bool doesExist() const {\r
56                 return doesExist(m_root, m_path);\r
57         }\r
58 \r
59         /// read DWORD\r
60         bool read(const tstring &i_name, int *o_value, int i_defaultValue = 0)\r
61         const {\r
62                 return read(m_root, m_path, i_name, o_value, i_defaultValue);\r
63         }\r
64         /// write DWORD\r
65         bool write(const tstring &i_name, int i_value) const {\r
66                 return write(m_root, m_path, i_name, i_value);\r
67         }\r
68 \r
69         /// read tstring\r
70         bool read(const tstring &i_name, tstring *o_value,\r
71                           const tstring &i_defaultValue = _T("")) const {\r
72                 return read(m_root, m_path, i_name, o_value, i_defaultValue);\r
73         }\r
74         /// write tstring\r
75         bool write(const tstring &i_name, const tstring &i_value) const {\r
76                 return write(m_root, m_path, i_name, i_value);\r
77         }\r
78 \r
79 #ifndef USE_INI\r
80         /// read list of tstring\r
81         bool read(const tstring &i_name, tstrings *o_value,\r
82                           const tstrings &i_defaultValue = tstrings()) const {\r
83                 return read(m_root, m_path, i_name, o_value, i_defaultValue);\r
84         }\r
85         /// write list of tstring\r
86         bool write(const tstring &i_name, const tstrings &i_value) const {\r
87                 return write(m_root, m_path, i_name, i_value);\r
88         }\r
89 #endif //!USE_INI\r
90 \r
91         /// read binary data\r
92         bool read(const tstring &i_name, BYTE *o_value, DWORD *i_valueSize,\r
93                           const BYTE *i_defaultValue = NULL, DWORD i_defaultValueSize = 0)\r
94         const {\r
95                 return read(m_root, m_path, i_name, o_value, i_valueSize, i_defaultValue,\r
96                                         i_defaultValueSize);\r
97         }\r
98         /// write binary data\r
99         bool write(const tstring &i_name, const BYTE *i_value,\r
100                            DWORD i_valueSize) const {\r
101                 return write(m_root, m_path, i_name, i_value, i_valueSize);\r
102         }\r
103 \r
104 public:\r
105         /// remove\r
106         static bool remove(HKEY i_root, const tstring &i_path,\r
107                                            const tstring &i_name = _T(""));\r
108 \r
109         /// does exist the key ?\r
110         static bool doesExist(HKEY i_root, const tstring &i_path);\r
111 \r
112         /// read DWORD\r
113         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
114                                          int *o_value, int i_defaultValue = 0);\r
115         /// write DWORD\r
116         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
117                                           int i_value);\r
118 \r
119         /// read tstring\r
120         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
121                                          tstring *o_value, const tstring &i_defaultValue = _T(""));\r
122         /// write tstring\r
123         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
124                                           const tstring &i_value);\r
125 \r
126 #ifndef USE_INI\r
127         /// read list of tstring\r
128         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
129                                          tstrings *o_value, const tstrings &i_defaultValue = tstrings());\r
130         /// write list of tstring\r
131         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
132                                           const tstrings &i_value);\r
133 #endif //!USE_INI\r
134 \r
135         /// read binary data\r
136         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
137                                          BYTE *o_value, DWORD *i_valueSize,\r
138                                          const BYTE *i_defaultValue = NULL,\r
139                                          DWORD i_defaultValueSize = 0);\r
140         /// write binary data\r
141         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
142                                           const BYTE *i_value, DWORD i_valueSize);\r
143         /// read LOGFONT\r
144         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
145                                          LOGFONT *o_value, const tstring &i_defaultStringValue);\r
146         /// write LOGFONT\r
147         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
148                                           const LOGFONT &i_value);\r
149 };\r
150 \r
151 \r
152 #endif // !_REGISTRY_H\r