1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 # include "stringtool.h"
12 /// registry access class
15 HKEY m_root; /// registry root
16 tstring m_path; /// path from registry root
19 typedef std::list<tstring> tstrings;
23 Registry() : m_root(NULL) { setRoot(NULL, _T("")); }
25 Registry(HKEY i_root, const tstring &i_path)
26 : m_root(i_root), m_path(i_path) { setRoot(i_root, i_path); }
28 /// set registry root and path
29 void setRoot(HKEY i_root, const tstring &i_path)
33 _TCHAR exePath[GANA_MAX_PATH];
34 _TCHAR exeDrive[GANA_MAX_PATH];
35 _TCHAR exeDir[GANA_MAX_PATH];
36 GetModuleFileName(NULL, exePath, GANA_MAX_PATH);
37 _tsplitpath_s(exePath, exeDrive, GANA_MAX_PATH, exeDir, GANA_MAX_PATH, NULL, 0, NULL, 0);
40 m_path += _T("yamy.ini");
44 bool remove(const tstring &i_name = _T("")) const
45 { return remove(m_root, m_path, i_name); }
47 /// does exist the key ?
48 bool doesExist() const { return doesExist(m_root, m_path); }
51 bool read(const tstring &i_name, int *o_value, int i_defaultValue = 0)
53 { return read(m_root, m_path, i_name, o_value, i_defaultValue); }
55 bool write(const tstring &i_name, int i_value) const
56 { return write(m_root, m_path, i_name, i_value); }
59 bool read(const tstring &i_name, tstring *o_value,
60 const tstring &i_defaultValue = _T("")) const
61 { return read(m_root, m_path, i_name, o_value, i_defaultValue); }
63 bool write(const tstring &i_name, const tstring &i_value) const
64 { return write(m_root, m_path, i_name, i_value); }
67 /// read list of tstring
68 bool read(const tstring &i_name, tstrings *o_value,
69 const tstrings &i_defaultValue = tstrings()) const
70 { return read(m_root, m_path, i_name, o_value, i_defaultValue); }
71 /// write list of tstring
72 bool write(const tstring &i_name, const tstrings &i_value) const
73 { return write(m_root, m_path, i_name, i_value); }
76 bool read(const tstring &i_name, BYTE *o_value, DWORD i_valueSize,
77 const BYTE *i_defaultValue = NULL, DWORD i_defaultValueSize = 0)
79 { return read(m_root, m_path, i_name, o_value, i_valueSize, i_defaultValue,
80 i_defaultValueSize); }
82 bool write(const tstring &i_name, const BYTE *i_value,
83 DWORD i_valueSize) const
84 { return write(m_root, m_path, i_name, i_value, i_valueSize); }
89 static bool remove(HKEY i_root, const tstring &i_path,
90 const tstring &i_name = _T(""));
92 /// does exist the key ?
93 static bool doesExist(HKEY i_root, const tstring &i_path);
96 static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
97 int *o_value, int i_defaultValue = 0);
99 static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
103 static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
104 tstring *o_value, const tstring &i_defaultValue = _T(""));
106 static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
107 const tstring &i_value);
110 /// read list of tstring
111 static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
112 tstrings *o_value, const tstrings &i_defaultValue = tstrings());
113 /// write list of tstring
114 static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
115 const tstrings &i_value);
118 static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
119 BYTE *o_value, DWORD i_valueSize,
120 const BYTE *i_defaultValue = NULL,
121 DWORD i_defaultValueSize = 0);
122 /// write binary data
123 static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
124 const BYTE *i_value, DWORD i_valueSize);
127 static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
128 LOGFONT *o_value, const tstring &i_defaultStringValue);
130 static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
131 const LOGFONT &i_value);
135 #endif // !_REGISTRY_H