From 3c38c55a26df5b2d8827b88a99f5bb996c4d13c2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 24 Aug 2012 22:28:24 +0000 Subject: The basic registry interface works now. --- src/unstable/settingsdriverregistry.cpp | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/unstable/settingsdriverregistry.cpp (limited to 'src/unstable/settingsdriverregistry.cpp') 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 @@ +#include "bu/settingsdriverregistry.h" +#include +#include "bu/string.h" + +#define phKey ((HKEY *)rphKey) + +Bu::SettingsDriverRegistry::SettingsDriverRegistry() +{ +} + +Bu::SettingsDriverRegistry::~SettingsDriverRegistry() +{ + RegCloseKey( *phKey ); +} + +void Bu::SettingsDriverRegistry::init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct ) +{ + Bu::UtfString us("Software\\"); + us += sCompany; + us += "\\"; + us += sProduct; + rphKey = new HKEY; + RegCreateKeyExA( HKEY_CURRENT_USER, us.get().getStr(), 0, NULL, 0, KEY_ALL_ACCESS, NULL, phKey, NULL ); +} + +void Bu::SettingsDriverRegistry::set( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) +{ + Bu::StringList lPath = sKey.get().split('/'); + Bu::StringList::iterator i = lPath.begin(); + Bu::StringList::iterator in; + + Bu::String sPKey; + for(; i;) + { + in = i; + in++; + if( in ) + { + if( !sPKey.isEmpty() ) + sPKey += "\\"; + sPKey += *i; + } + i = in; + } + + HKEY key; + RegCreateKeyExA( *phKey, sPKey.getStr(), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL ); + Bu::String sTmp = sValue.get(); + RegSetValueExA( key, lPath.last().getStr(), 0, REG_SZ, (BYTE *)sTmp.getStr(), sTmp.getSize()+1 ); + RegCloseKey( key ); +} + +Bu::UtfString Bu::SettingsDriverRegistry::get( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) +{ + Bu::StringList lPath = sKey.get().split('/'); + Bu::StringList::iterator i = lPath.begin(); + Bu::StringList::iterator in; + + Bu::String sPKey; + for(; i;) + { + in = i; + in++; + if( in ) + { + if( !sPKey.isEmpty() ) + sPKey += "\\"; + sPKey += *i; + } + i = in; + } + + HKEY key; + if( RegOpenKeyExA( *phKey, sPKey.getStr(), 0, KEY_ALL_ACCESS, &key ) + != ERROR_SUCCESS ) + return sValue; + char buf[4096]; + DWORD iRet = 4096; + if( RegQueryValueEx( key, lPath.last().getStr(), NULL, NULL, (BYTE *)buf, &iRet ) != ERROR_SUCCESS ) + { + RegCloseKey( key ); + return sValue; + } + RegCloseKey( key ); + + return Bu::UtfString( Bu::String( buf, iRet ) ); +} + -- cgit v1.2.3