OSDN Git Service

8a283c26c1f87acd7c3fb76b8c99ea43d2a2a718
[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) { setRoot(NULL, _T("")); }\r
24   ///\r
25   Registry(HKEY i_root, const tstring &i_path)\r
26     : m_root(i_root), m_path(i_path) { setRoot(i_root, i_path); }\r
27   \r
28   /// set registry root and path\r
29   void setRoot(HKEY i_root, const tstring &i_path)\r
30   {\r
31     m_root = i_root;\r
32     m_path = i_path;\r
33     _TCHAR exePath[GANA_MAX_PATH];\r
34     _TCHAR exeDrive[GANA_MAX_PATH];\r
35     _TCHAR exeDir[GANA_MAX_PATH];\r
36     GetModuleFileName(NULL, exePath, GANA_MAX_PATH);\r
37     _tsplitpath_s(exePath, exeDrive, GANA_MAX_PATH, exeDir, GANA_MAX_PATH, NULL, 0, NULL, 0);\r
38     m_path = exeDrive;\r
39     m_path += exeDir;\r
40     m_path += _T("yamy.ini");\r
41   }\r
42   \r
43   /// remvoe\r
44   bool remove(const tstring &i_name = _T("")) const\r
45   { return remove(m_root, m_path, i_name); }\r
46   \r
47   /// does exist the key ?\r
48   bool doesExist() const { return doesExist(m_root, m_path); }\r
49 \r
50   /// read DWORD\r
51   bool read(const tstring &i_name, int *o_value, int i_defaultValue = 0)\r
52     const\r
53   { return read(m_root, m_path, i_name, o_value, i_defaultValue); }\r
54   /// write DWORD\r
55   bool write(const tstring &i_name, int i_value) const\r
56   { return write(m_root, m_path, i_name, i_value); }\r
57  \r
58   /// read tstring\r
59   bool read(const tstring &i_name, tstring *o_value, \r
60             const tstring &i_defaultValue = _T("")) const\r
61   { return read(m_root, m_path, i_name, o_value, i_defaultValue); }\r
62   /// write tstring\r
63   bool write(const tstring &i_name, const tstring &i_value) const\r
64   { return write(m_root, m_path, i_name, i_value); }\r
65 \r
66 #ifndef USE_INI\r
67   /// read list of tstring\r
68   bool read(const tstring &i_name, tstrings *o_value, \r
69             const tstrings &i_defaultValue = tstrings()) const\r
70   { return read(m_root, m_path, i_name, o_value, i_defaultValue); }\r
71   /// write list of tstring\r
72   bool write(const tstring &i_name, const tstrings &i_value) const\r
73   { return write(m_root, m_path, i_name, i_value); }\r
74 \r
75   /// read binary data\r
76   bool read(const tstring &i_name, BYTE *o_value, DWORD i_valueSize,\r
77             const BYTE *i_defaultValue = NULL, DWORD i_defaultValueSize = 0)\r
78     const\r
79   { return read(m_root, m_path, i_name, o_value, i_valueSize, i_defaultValue,\r
80                 i_defaultValueSize); }\r
81   /// write binary data\r
82   bool write(const tstring &i_name, const BYTE *i_value,\r
83              DWORD i_valueSize) const\r
84   { return write(m_root, m_path, i_name, i_value, i_valueSize); }\r
85 #endif //!USE_INI\r
86 \r
87 public:\r
88   /// remove\r
89   static bool remove(HKEY i_root, const tstring &i_path,\r
90                      const tstring &i_name = _T(""));\r
91   \r
92   /// does exist the key ?\r
93   static bool doesExist(HKEY i_root, const tstring &i_path);\r
94   \r
95   /// read DWORD\r
96   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
97                    int *o_value, int i_defaultValue = 0);\r
98   /// write DWORD\r
99   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
100                     int i_value);\r
101 \r
102   /// read tstring\r
103   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
104                    tstring *o_value, const tstring &i_defaultValue = _T(""));\r
105   /// write tstring\r
106   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
107                     const tstring &i_value);\r
108   \r
109 #ifndef USE_INI\r
110   /// read list of tstring\r
111   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
112                    tstrings *o_value, const tstrings &i_defaultValue = tstrings());\r
113   /// write list of tstring\r
114   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
115                     const tstrings &i_value);\r
116   \r
117   /// read binary data\r
118   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
119                    BYTE *o_value, DWORD i_valueSize,\r
120                    const BYTE *i_defaultValue = NULL,\r
121                    DWORD i_defaultValueSize = 0);\r
122   /// write binary data\r
123   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
124                     const BYTE *i_value, DWORD i_valueSize);\r
125 #endif //!USE_INI\r
126   /// read LOGFONT\r
127   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
128                    LOGFONT *o_value, const tstring &i_defaultStringValue);\r
129   /// write LOGFONT\r
130   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
131                     const LOGFONT &i_value);\r
132 };\r
133 \r
134 \r
135 #endif // !_REGISTRY_H\r