diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-08-24 22:28:24 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-08-24 22:28:24 +0000 |
commit | 3c38c55a26df5b2d8827b88a99f5bb996c4d13c2 (patch) | |
tree | 1a28e7c740638760dd55f71ec8ebd66d19a7ad3d /src/unstable/settingsdriverregistry.cpp | |
parent | d7d2c0929a5d7871e913451fd542e03ae4561183 (diff) | |
download | libbu++-3c38c55a26df5b2d8827b88a99f5bb996c4d13c2.tar.gz libbu++-3c38c55a26df5b2d8827b88a99f5bb996c4d13c2.tar.bz2 libbu++-3c38c55a26df5b2d8827b88a99f5bb996c4d13c2.tar.xz libbu++-3c38c55a26df5b2d8827b88a99f5bb996c4d13c2.zip |
The basic registry interface works now.
Diffstat (limited to 'src/unstable/settingsdriverregistry.cpp')
-rw-r--r-- | src/unstable/settingsdriverregistry.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/unstable/settingsdriverregistry.cpp b/src/unstable/settingsdriverregistry.cpp new file mode 100644 index 0000000..40a08ac --- /dev/null +++ b/src/unstable/settingsdriverregistry.cpp | |||
@@ -0,0 +1,88 @@ | |||
1 | #include "bu/settingsdriverregistry.h" | ||
2 | #include <windows.h> | ||
3 | #include "bu/string.h" | ||
4 | |||
5 | #define phKey ((HKEY *)rphKey) | ||
6 | |||
7 | Bu::SettingsDriverRegistry::SettingsDriverRegistry() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | Bu::SettingsDriverRegistry::~SettingsDriverRegistry() | ||
12 | { | ||
13 | RegCloseKey( *phKey ); | ||
14 | } | ||
15 | |||
16 | void Bu::SettingsDriverRegistry::init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct ) | ||
17 | { | ||
18 | Bu::UtfString us("Software\\"); | ||
19 | us += sCompany; | ||
20 | us += "\\"; | ||
21 | us += sProduct; | ||
22 | rphKey = new HKEY; | ||
23 | RegCreateKeyExA( HKEY_CURRENT_USER, us.get().getStr(), 0, NULL, 0, KEY_ALL_ACCESS, NULL, phKey, NULL ); | ||
24 | } | ||
25 | |||
26 | void Bu::SettingsDriverRegistry::set( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) | ||
27 | { | ||
28 | Bu::StringList lPath = sKey.get().split('/'); | ||
29 | Bu::StringList::iterator i = lPath.begin(); | ||
30 | Bu::StringList::iterator in; | ||
31 | |||
32 | Bu::String sPKey; | ||
33 | for(; i;) | ||
34 | { | ||
35 | in = i; | ||
36 | in++; | ||
37 | if( in ) | ||
38 | { | ||
39 | if( !sPKey.isEmpty() ) | ||
40 | sPKey += "\\"; | ||
41 | sPKey += *i; | ||
42 | } | ||
43 | i = in; | ||
44 | } | ||
45 | |||
46 | HKEY key; | ||
47 | RegCreateKeyExA( *phKey, sPKey.getStr(), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL ); | ||
48 | Bu::String sTmp = sValue.get(); | ||
49 | RegSetValueExA( key, lPath.last().getStr(), 0, REG_SZ, (BYTE *)sTmp.getStr(), sTmp.getSize()+1 ); | ||
50 | RegCloseKey( key ); | ||
51 | } | ||
52 | |||
53 | Bu::UtfString Bu::SettingsDriverRegistry::get( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) | ||
54 | { | ||
55 | Bu::StringList lPath = sKey.get().split('/'); | ||
56 | Bu::StringList::iterator i = lPath.begin(); | ||
57 | Bu::StringList::iterator in; | ||
58 | |||
59 | Bu::String sPKey; | ||
60 | for(; i;) | ||
61 | { | ||
62 | in = i; | ||
63 | in++; | ||
64 | if( in ) | ||
65 | { | ||
66 | if( !sPKey.isEmpty() ) | ||
67 | sPKey += "\\"; | ||
68 | sPKey += *i; | ||
69 | } | ||
70 | i = in; | ||
71 | } | ||
72 | |||
73 | HKEY key; | ||
74 | if( RegOpenKeyExA( *phKey, sPKey.getStr(), 0, KEY_ALL_ACCESS, &key ) | ||
75 | != ERROR_SUCCESS ) | ||
76 | return sValue; | ||
77 | char buf[4096]; | ||
78 | DWORD iRet = 4096; | ||
79 | if( RegQueryValueEx( key, lPath.last().getStr(), NULL, NULL, (BYTE *)buf, &iRet ) != ERROR_SUCCESS ) | ||
80 | { | ||
81 | RegCloseKey( key ); | ||
82 | return sValue; | ||
83 | } | ||
84 | RegCloseKey( key ); | ||
85 | |||
86 | return Bu::UtfString( Bu::String( buf, iRet ) ); | ||
87 | } | ||
88 | |||