OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_ | |
6 #define CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_ | |
7 | |
8 #include <windows.h> | |
9 | |
10 namespace mini_installer { | |
11 | |
12 // A helper class used to manipulate the Windows registry. Typically, members | |
13 // return Windows last-error codes a la the Win32 registry API. | |
robertshield
2015/08/04 03:11:36
s/a la the/a la/
bcwhite
2015/08/04 19:34:31
Done.
| |
14 class RegKey { | |
15 public: | |
16 RegKey() : key_(NULL) { } | |
17 ~RegKey() { Close(); } | |
18 | |
19 // Opens the key named |sub_key| with given |access| rights. Returns | |
20 // ERROR_SUCCESS or some other error. | |
21 LONG Open(HKEY key, const wchar_t* sub_key, REGSAM access); | |
22 | |
23 // Returns true if a key is open. | |
24 bool is_valid() const { return key_ != NULL; } | |
25 | |
26 // Read a value from the registry into the memory indicated by |value| | |
27 // (of |value_size| wchar_t units). Returns ERROR_SUCCESS, | |
28 // ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA, or some other error. |value| is | |
29 // guaranteed to be null-terminated on success. | |
30 LONG ReadSZValue(const wchar_t* value_name, | |
31 wchar_t* value, | |
32 size_t value_size) const; | |
33 LONG ReadDWValue(const wchar_t* value_name, DWORD* value) const; | |
34 | |
35 // Write a value to the registry. SZ |value| must be null-terminated. | |
36 // Returns ERROR_SUCCESS or an error code. | |
37 LONG WriteSZValue(const wchar_t* value_name, const wchar_t* value); | |
38 LONG WriteDWValue(const wchar_t* value_name, DWORD value); | |
39 | |
40 // Closes the key if it was open. | |
41 void Close(); | |
42 | |
43 // Helper function to read a value from registry. Returns true if value | |
44 // is read successfully and stored in parameter value. Returns false | |
45 // otherwise. |size| is measured in wchar_t units. | |
46 static bool ReadSZValue(HKEY root_key, const wchar_t *sub_key, | |
47 const wchar_t *value_name, wchar_t *value, | |
48 size_t value_size); | |
49 | |
50 static bool OpenClientStateKey(HKEY root_key, const wchar_t* app_guid, | |
robertshield
2015/08/04 03:11:36
Layering-wise, it seems a little odd to tack this
bcwhite
2015/08/04 19:34:31
It needs to be someplace accessible by both config
| |
51 REGSAM access, RegKey* key); | |
52 | |
53 private: | |
54 RegKey(const RegKey&); | |
55 RegKey& operator=(const RegKey&); | |
56 | |
57 HKEY key_; | |
58 }; // class RegKey | |
59 | |
60 } // namespace mini_installer | |
61 | |
62 #endif // CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_ | |
OLD | NEW |