| 1 | /** |
|---|
| 2 | @file RegistryUtil.h |
|---|
| 3 | |
|---|
| 4 | @created 2006-04-06 |
|---|
| 5 | @edited 2006-04-06 |
|---|
| 6 | |
|---|
| 7 | Copyright 2000-2006, Morgan McGuire. |
|---|
| 8 | All rights reserved. |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | #ifndef G3D_REGISTRYUTIL_H |
|---|
| 12 | #define G3D_REGISTRYUTIL_H |
|---|
| 13 | |
|---|
| 14 | #include "G3D/platform.h" |
|---|
| 15 | #include "G3D/g3dmath.h" |
|---|
| 16 | |
|---|
| 17 | // This file is only used on Windows |
|---|
| 18 | #ifdef G3D_WIN32 |
|---|
| 19 | |
|---|
| 20 | #include <string> |
|---|
| 21 | |
|---|
| 22 | namespace G3D { |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | Provides generalized Windows registry querying. |
|---|
| 26 | |
|---|
| 27 | All key names are one string in the format: |
|---|
| 28 | "[base key]\[sub-keys]\value" |
|---|
| 29 | |
|---|
| 30 | [base key] can be any of the following: |
|---|
| 31 | HKEY_CLASSES_ROOT |
|---|
| 32 | HKEY_CURRENT_CONFIG |
|---|
| 33 | HKEY_CURRENT_USER |
|---|
| 34 | HKEY_LOCAL_MACHINE |
|---|
| 35 | HKEY_PERFORMANCE_DATA |
|---|
| 36 | HKEY_PERFORMANCE_NLSTEXT |
|---|
| 37 | HKEY_PERFORMANCE_TEXT |
|---|
| 38 | HKEY_USERS |
|---|
| 39 | |
|---|
| 40 | keyExists() should be used to validate a key before reading or writing |
|---|
| 41 | to ensure that a debug assert or false return is for a different error. |
|---|
| 42 | */ |
|---|
| 43 | class RegistryUtil { |
|---|
| 44 | |
|---|
| 45 | public: |
|---|
| 46 | /** returns true if the key exists */ |
|---|
| 47 | static bool keyExists(const std::string& key); |
|---|
| 48 | |
|---|
| 49 | /** returns false if the key could not be read for any reason. */ |
|---|
| 50 | static bool readInt32(const std::string& key, int32& valueData); |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | Reads an arbitrary amount of data from a binary registry key. |
|---|
| 54 | returns false if the key could not be read for any reason. |
|---|
| 55 | |
|---|
| 56 | @beta |
|---|
| 57 | @param valueData pointer to the output buffer of sufficient size. Pass NULL as valueData in order to have available data size returned in dataSize. |
|---|
| 58 | @param dataSize size of the output buffer. When NULL is passed for valueData, contains the size of available data on successful return. |
|---|
| 59 | */ |
|---|
| 60 | static bool readBytes(const std::string& key, uint8* valueData, uint32& dataSize); |
|---|
| 61 | |
|---|
| 62 | /** returns false if the key could not be read for any reason. */ |
|---|
| 63 | static bool readString(const std::string& key, std::string& valueData); |
|---|
| 64 | |
|---|
| 65 | /** returns false if the key could not be written for any reason. */ |
|---|
| 66 | static bool writeInt32(const std::string& key, int32 valueData); |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | Writes an arbitrary amount of data to a binary registry key. |
|---|
| 70 | returns false if the key could not be written for any reason. |
|---|
| 71 | |
|---|
| 72 | @param valueData pointer to the input buffer |
|---|
| 73 | @param dataSize size of the input buffer that should be written |
|---|
| 74 | */ |
|---|
| 75 | static bool writeBytes(const std::string& key, const uint8* valueData, uint32 dataSize); |
|---|
| 76 | |
|---|
| 77 | /** returns false if the key could not be written for any reason. */ |
|---|
| 78 | static bool writeString(const std::string& key, const std::string& valueData); |
|---|
| 79 | |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | } // namespace G3D |
|---|
| 83 | |
|---|
| 84 | #endif // G3D_WIN32 |
|---|
| 85 | |
|---|
| 86 | #endif // G3D_REGISTRYTUIL_H |
|---|