aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/settingsdriverregistry.cpp
blob: 89eda7b9dc3e83024ea460b8d88d93d4aabe88cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifdef WIN32

#include "bu/settingsdriverregistry.h"
#include <windows.h>
#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 ) );
}

#endif