xref: /aosp_15_r20/external/lzma/CPP/Windows/Registry.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // Windows/Registry.h
2 
3 #ifndef ZIP7_INC_WINDOWS_REGISTRY_H
4 #define ZIP7_INC_WINDOWS_REGISTRY_H
5 
6 #include "../Common/MyBuffer.h"
7 #include "../Common/MyString.h"
8 
9 namespace NWindows {
10 namespace NRegistry {
11 
12 LONG SetValue(HKEY parentKey, LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value);
13 
14 class CKey
15 {
16   HKEY _object;
17 
QueryValueEx(LPCTSTR lpValueName,LPDWORD lpType,LPBYTE lpData,LPDWORD lpcbData)18   LONG QueryValueEx(LPCTSTR lpValueName, LPDWORD lpType,
19       LPBYTE lpData, LPDWORD lpcbData)
20   {
21     return RegQueryValueEx(_object, lpValueName, NULL, lpType, lpData, lpcbData);
22   }
23 
24 public:
CKey()25   CKey(): _object(NULL) {}
~CKey()26   ~CKey() { Close(); }
27 
HKEY()28   operator HKEY() const { return _object; }
Attach(HKEY key)29   void Attach(HKEY key) { _object = key; }
Detach()30   HKEY Detach()
31   {
32     const HKEY key = _object;
33     _object = NULL;
34     return key;
35   }
36 
37   LONG Create(HKEY parentKey, LPCTSTR keyName,
38       LPTSTR keyClass = REG_NONE,
39       DWORD options = REG_OPTION_NON_VOLATILE,
40       REGSAM accessMask = KEY_ALL_ACCESS,
41       LPSECURITY_ATTRIBUTES securityAttributes = NULL,
42       LPDWORD disposition = NULL) throw();
43   LONG Open(HKEY parentKey, LPCTSTR keyName, REGSAM accessMask = KEY_ALL_ACCESS) throw();
44 
45   LONG Close() throw();
46 
47   LONG DeleteSubKey(LPCTSTR subKeyName) throw();
48   LONG RecurseDeleteKey(LPCTSTR subKeyName) throw();
49 
50   LONG DeleteValue(LPCTSTR name) throw();
51 #ifndef _UNICODE
52   LONG DeleteValue(LPCWSTR name);
53 #endif
54 
55   LONG SetValue(LPCTSTR valueName, UInt32 value) throw();
56   LONG SetValue(LPCTSTR valueName, bool value) throw();
57   LONG SetValue(LPCTSTR valueName, LPCTSTR value) throw();
58   // LONG SetValue(LPCTSTR valueName, const CSysString &value);
59 #ifndef _UNICODE
60   LONG SetValue(LPCWSTR name, LPCWSTR value);
61   // LONG SetValue(LPCWSTR name, const UString &value);
62 #endif
63 
64   LONG SetValue(LPCTSTR name, const void *value, UInt32 size) throw();
65 
66   LONG SetValue_Strings(LPCTSTR valueName, const UStringVector &strings);
67   LONG GetValue_Strings(LPCTSTR valueName, UStringVector &strings);
68 
69   LONG SetKeyValue(LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value) throw();
70 
71   // GetValue_[type]_IfOk():
72   //   if (return_result == ERROR_SUCCESS), (value) variable was read from registry
73   //   if (return_result != ERROR_SUCCESS), (value) variable was not changed
74   LONG GetValue_UInt32_IfOk(LPCTSTR name, UInt32 &value) throw();
75   LONG GetValue_UInt64_IfOk(LPCTSTR name, UInt64 &value) throw();
76   LONG GetValue_bool_IfOk(LPCTSTR name, bool &value) throw();
77 
78   // QueryValue():
79   //   if (return_result == ERROR_SUCCESS), (value) string was read from registry
80   //   if (return_result != ERROR_SUCCESS), (value) string was cleared
81   LONG QueryValue(LPCTSTR name, CSysString &value);
82 #ifndef _UNICODE
83   LONG QueryValue(LPCWSTR name, UString &value);
84 #endif
85 
86   // QueryValue_Binary():
87   //   if (return_result == ERROR_SUCCESS), (value) buffer was read from registry (BINARY data)
88   //   if (return_result != ERROR_SUCCESS), (value) buffer was cleared
89   LONG QueryValue_Binary(LPCTSTR name, CByteBuffer &value);
90 
91   LONG EnumKeys(CSysStringVector &keyNames);
92 };
93 
94 }}
95 
96 #endif
97