OSDN Git Service

fix invalid file permission
[yamy/yamy.git] / registry.h
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // registry.h
3
4
5 #ifndef _REGISTRY_H
6 #  define _REGISTRY_H
7
8 #  include "stringtool.h"
9 #  include <list>
10
11
12 /// registry access class
13 class Registry
14 {
15   HKEY m_root;                                  /// registry root
16   tstring m_path;                               /// path from registry root
17
18 public:
19   typedef std::list<tstring> tstrings;
20   
21 public:
22   ///
23   Registry() : m_root(NULL) { setRoot(NULL, _T("")); }
24   ///
25   Registry(HKEY i_root, const tstring &i_path)
26     : m_root(i_root), m_path(i_path) { setRoot(i_root, i_path); }
27   
28   /// set registry root and path
29   void setRoot(HKEY i_root, const tstring &i_path)
30   {
31     m_root = i_root;
32     m_path = 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);
38     m_path = exeDrive;
39     m_path += exeDir;
40     m_path += _T("yamy.ini");
41   }
42   
43   /// remvoe
44   bool remove(const tstring &i_name = _T("")) const
45   { return remove(m_root, m_path, i_name); }
46   
47   /// does exist the key ?
48   bool doesExist() const { return doesExist(m_root, m_path); }
49
50   /// read DWORD
51   bool read(const tstring &i_name, int *o_value, int i_defaultValue = 0)
52     const
53   { return read(m_root, m_path, i_name, o_value, i_defaultValue); }
54   /// write DWORD
55   bool write(const tstring &i_name, int i_value) const
56   { return write(m_root, m_path, i_name, i_value); }
57  
58   /// read tstring
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); }
62   /// write tstring
63   bool write(const tstring &i_name, const tstring &i_value) const
64   { return write(m_root, m_path, i_name, i_value); }
65
66 #ifndef USE_INI
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); }
74
75   /// read binary data
76   bool read(const tstring &i_name, BYTE *o_value, DWORD i_valueSize,
77             const BYTE *i_defaultValue = NULL, DWORD i_defaultValueSize = 0)
78     const
79   { return read(m_root, m_path, i_name, o_value, i_valueSize, i_defaultValue,
80                 i_defaultValueSize); }
81   /// write binary data
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); }
85 #endif //!USE_INI
86
87 public:
88   /// remove
89   static bool remove(HKEY i_root, const tstring &i_path,
90                      const tstring &i_name = _T(""));
91   
92   /// does exist the key ?
93   static bool doesExist(HKEY i_root, const tstring &i_path);
94   
95   /// read DWORD
96   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
97                    int *o_value, int i_defaultValue = 0);
98   /// write DWORD
99   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
100                     int i_value);
101
102   /// read tstring
103   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
104                    tstring *o_value, const tstring &i_defaultValue = _T(""));
105   /// write tstring
106   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
107                     const tstring &i_value);
108   
109 #ifndef USE_INI
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);
116   
117   /// read binary data
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);
125 #endif //!USE_INI
126   /// read LOGFONT
127   static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,
128                    LOGFONT *o_value, const tstring &i_defaultStringValue);
129   /// write LOGFONT
130   static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,
131                     const LOGFONT &i_value);
132 };
133
134
135 #endif // !_REGISTRY_H