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 Win32 registry API. |
| 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 private: |
| 51 RegKey(const RegKey&); |
| 52 RegKey& operator=(const RegKey&); |
| 53 |
| 54 HKEY key_; |
| 55 }; // class RegKey |
| 56 |
| 57 |
| 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); |
| 62 |
| 63 } // namespace mini_installer |
| 64 |
| 65 #endif // CHROME_INSTALLER_MINI_INSTALLER_REGKEY_H_ |
OLD | NEW |