Improve: Remove redundant code for reading the registry
This commit is contained in:
@@ -16,80 +16,6 @@
|
||||
#include "KernelManager.h"
|
||||
#include <iniFile.h>
|
||||
|
||||
#define REG_SETTINGS "Software\\ServerD11\\Settings"
|
||||
|
||||
// д<><D0B4><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ֽڰ棩
|
||||
bool WriteAppSettingA(const std::string& keyName, const std::string& value) {
|
||||
HKEY hKey;
|
||||
|
||||
LONG result = RegCreateKeyExA(
|
||||
HKEY_CURRENT_USER,
|
||||
REG_SETTINGS,
|
||||
0,
|
||||
NULL,
|
||||
0,
|
||||
KEY_WRITE,
|
||||
NULL,
|
||||
&hKey,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (result != ERROR_SUCCESS) {
|
||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = RegSetValueExA(
|
||||
hKey,
|
||||
keyName.c_str(),
|
||||
0,
|
||||
REG_SZ,
|
||||
reinterpret_cast<const BYTE*>(value.c_str()),
|
||||
static_cast<DWORD>(value.length() + 1)
|
||||
);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
return result == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ֽڰ棩
|
||||
bool ReadAppSettingA(const std::string& keyName, std::string& outValue) {
|
||||
HKEY hKey;
|
||||
|
||||
LONG result = RegOpenKeyExA(
|
||||
HKEY_CURRENT_USER,
|
||||
REG_SETTINGS,
|
||||
0,
|
||||
KEY_READ,
|
||||
&hKey
|
||||
);
|
||||
|
||||
if (result != ERROR_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[256];
|
||||
DWORD bufferSize = sizeof(buffer);
|
||||
DWORD type = 0;
|
||||
|
||||
result = RegQueryValueExA(
|
||||
hKey,
|
||||
keyName.c_str(),
|
||||
nullptr,
|
||||
&type,
|
||||
reinterpret_cast<LPBYTE>(buffer),
|
||||
&bufferSize
|
||||
);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (result == ERROR_SUCCESS && type == REG_SZ) {
|
||||
outValue = buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD WINAPI ThreadProc(LPVOID lParam)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user