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.
5 #ifndef CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_
6 #define CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_
10 namespace mini_installer
{
12 // A helper class used to manipulate the Windows registry. Typically, members
13 // return Windows last-error codes a la Win32 registry API.
16 RegKey() : key_(NULL
) { }
17 ~RegKey() { Close(); }
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
);
23 // Returns true if a key is open.
24 bool is_valid() const { return key_
!= NULL
; }
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
,
32 size_t value_size
) const;
33 LONG
ReadDWValue(const wchar_t* value_name
, DWORD
* value
) const;
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
);
40 // Closes the key if it was open.
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
,
51 RegKey(const RegKey
&);
52 RegKey
& operator=(const RegKey
&);
58 // Helper function to get the RegKey associated with the "client state" of
59 // the given |app_guid|.
60 bool OpenClientStateKey(HKEY root_key
, const wchar_t* app_guid
,
61 REGSAM access
, RegKey
* key
);
63 } // namespace mini_installer
65 #endif // CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_