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 | |
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 '')
-rw-r--r-- | src/unstable/settings.cpp | 2 | ||||
-rw-r--r-- | src/unstable/settingsdriverregistry.cpp | 88 | ||||
-rw-r--r-- | src/unstable/settingsdriverregistry.h | 28 |
3 files changed, 118 insertions, 0 deletions
diff --git a/src/unstable/settings.cpp b/src/unstable/settings.cpp index ac3975f..792aff9 100644 --- a/src/unstable/settings.cpp +++ b/src/unstable/settings.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "bu/settings.h" | 1 | #include "bu/settings.h" |
2 | 2 | ||
3 | #include "bu/settingsdrivertaf.h" | 3 | #include "bu/settingsdrivertaf.h" |
4 | #include "bu/settingsdriverregistry.h" | ||
4 | 5 | ||
5 | Bu::Settings::Settings( const Bu::UtfString &sCompany, | 6 | Bu::Settings::Settings( const Bu::UtfString &sCompany, |
6 | const Bu::UtfString &sProduct, Bu::Settings::Driver eDriver ) : | 7 | const Bu::UtfString &sProduct, Bu::Settings::Driver eDriver ) : |
@@ -12,6 +13,7 @@ Bu::Settings::Settings( const Bu::UtfString &sCompany, | |||
12 | { | 13 | { |
13 | case DriverNative: | 14 | case DriverNative: |
14 | #if defined( WIN32 ) | 15 | #if defined( WIN32 ) |
16 | pDriver = new Bu::SettingsDriverRegistry(); | ||
15 | #else | 17 | #else |
16 | pDriver = new Bu::SettingsDriverTaf(); | 18 | pDriver = new Bu::SettingsDriverTaf(); |
17 | #endif | 19 | #endif |
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 | |||
diff --git a/src/unstable/settingsdriverregistry.h b/src/unstable/settingsdriverregistry.h new file mode 100644 index 0000000..2d718d2 --- /dev/null +++ b/src/unstable/settingsdriverregistry.h | |||
@@ -0,0 +1,28 @@ | |||
1 | #ifndef BU_SETTINGS_DRIVER_REGISTRY_H | ||
2 | #define BU_SETTINGS_DRIVER_REGISTRY_H | ||
3 | |||
4 | #ifdef WIN32 | ||
5 | |||
6 | #include "bu/settingsdriver.h" | ||
7 | |||
8 | namespace Bu | ||
9 | { | ||
10 | class SettingsDriverRegistry : public SettingsDriver | ||
11 | { | ||
12 | public: | ||
13 | SettingsDriverRegistry(); | ||
14 | virtual ~SettingsDriverRegistry(); | ||
15 | |||
16 | protected: | ||
17 | virtual void init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct ); | ||
18 | virtual void set( const Bu::UtfString &sKey, const Bu::UtfString &sValue ); | ||
19 | virtual Bu::UtfString get( const Bu::UtfString &sKey, const Bu::UtfString &sValue ); | ||
20 | |||
21 | private: | ||
22 | void *rphKey; | ||
23 | }; | ||
24 | }; | ||
25 | |||
26 | #endif | ||
27 | |||
28 | #endif | ||