forked from JusicP/Launcher_CSNZ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.cpp
More file actions
134 lines (101 loc) · 2.34 KB
/
registry.cpp
File metadata and controls
134 lines (101 loc) · 2.34 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <windows.h>
#include "IRegistry.h"
class CRegistry : public IRegistry
{
public:
CRegistry(void);
virtual ~CRegistry(void);
public:
void Init(void);
void Shutdown(void);
int ReadInt(const char *key, int defaultValue = 0);
void WriteInt(const char *key, int value);
const char *ReadString(const char *key, const char *defaultValue = NULL);
void WriteString(const char *key, const char *value);
private:
bool m_bValid;
HKEY m_hKey;
};
static CRegistry g_Registry;
IRegistry *registry = (IRegistry *)&g_Registry;
CRegistry::CRegistry(void)
{
m_bValid = false;
m_hKey = 0;
}
CRegistry::~CRegistry(void)
{
}
int CRegistry::ReadInt(const char *key, int defaultValue)
{
LONG lResult;
DWORD dwType;
DWORD dwSize;
int value;
if (!m_bValid)
return defaultValue;
dwSize = sizeof(DWORD);
lResult = RegQueryValueEx(m_hKey, key, 0, &dwType, (LPBYTE)&value, &dwSize);
if (lResult != ERROR_SUCCESS)
return defaultValue;
if (dwType != REG_DWORD)
return defaultValue;
return value;
}
void CRegistry::WriteInt(const char *key, int value)
{
DWORD dwSize;
if (!m_bValid)
return;
dwSize = sizeof(DWORD);
RegSetValueEx(m_hKey, key, 0, REG_DWORD, (LPBYTE)&value, dwSize);
}
const char *CRegistry::ReadString(const char *key, const char *defaultValue)
{
LONG lResult;
DWORD dwType;
DWORD dwSize = 512;
static char value[512];
value[0] = 0;
if (!m_bValid)
return defaultValue;
lResult = RegQueryValueEx(m_hKey, key, 0, &dwType, (unsigned char *)value, &dwSize);
if (lResult != ERROR_SUCCESS)
return defaultValue;
if (dwType != REG_SZ)
return defaultValue;
return value;
}
void CRegistry::WriteString(const char *key, const char *value)
{
DWORD dwSize;
if (!m_bValid)
return;
dwSize = strlen(value) + 1;
RegSetValueEx(m_hKey, key, 0, REG_SZ, (LPBYTE)value, dwSize);
}
static char *GetPlatformName(void)
{
return "CStrike-Online";
}
void CRegistry::Init(void)
{
LONG lResult;
DWORD dwDisposition;
char szModelKey[1024];
wsprintf(szModelKey, "Software\\Nexon\\%s\\Settings\\", GetPlatformName());
lResult = RegCreateKeyEx(HKEY_CURRENT_USER, szModelKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &m_hKey, &dwDisposition);
if (lResult != ERROR_SUCCESS)
{
m_bValid = false;
return;
}
m_bValid = true;
}
void CRegistry::Shutdown(void)
{
if (!m_bValid)
return;
m_bValid = false;
RegCloseKey(m_hKey);
}