Index: src/shared/Registry.h |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/src/shared/Registry.h |
@@ -0,0 +1,65 @@ |
+#include <string> |
+#include <Windows.h> |
+ |
+namespace AdblockPlus |
+{ |
+ /** |
+ * An open key in the system registry. |
+ */ |
+ class Registry_Key |
Oleksandr
2014/07/25 22:23:46
Formatting is incorrect in this file as well
|
+ { |
+ /** |
+ * Handle to an open registry key. |
+ */ |
+ HKEY key; |
+ |
+ /** |
+ * Flag whether the registry key is predefined or not. |
+ * |
+ * Predefined key values are considered "always open" and should not be closed in the destructor. |
+ */ |
+ bool is_predefined; |
+ |
+ public: |
+ /** |
+ * Enumeration for predefined root keys. |
+ */ |
+ enum class Predefined |
+ : unsigned int |
+ { |
+ HKCR = 0, // HKEY_CLASSES_ROOT |
+ HKCC, // HKEY_CURRENT_CONFIG |
+ HKCU, // HKEY_CURRENT_USER |
+ HKLM, // HKEY_LOCAL_MACHINE |
+ HKU // HKEY_USERS |
+ }; |
+ |
+ /** |
+ * Constructor to open a key under one of the predefined roots. |
+ * Opens the key with read-only access. |
+ * |
+ * Because the invariant of this class is that the underlying registry key is open, |
+ * this constructor throws if 'key_name' is not found. |
+ */ |
+ Registry_Key( Predefined root, std::wstring key_name ); |
+ |
+ /** |
+ * Constructor for one of the predefined roots. |
+ */ |
+ Registry_Key( Predefined root ); |
+ |
+ /** |
+ * Destructor closes the key if it's not a predefined one. |
+ */ |
+ ~Registry_Key(); |
+ |
+ /** |
+ * Retrieve a value from a name-value pair within the present key. |
+ * |
+ * Throws if the name is not found within the dictionary. |
+ * Throws if the name is found but is not a string. |
+ */ |
+ std::wstring value_wstring( std::wstring name ) const; |
+ }; |
+} |
+ |