From 481bbae8eefb7ec228454c4b6df0201f8e6210df Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 19 Nov 2016 21:12:04 +0100 Subject: [PATCH] Changed: Use wide versions of Win32 API --HG-- branch : develop --- .../ryzom/client/src/bg_downloader_access.cpp | 2 +- code/ryzom/client/src/permanent_ban.cpp | 16 +++++---- .../src/game_share/bg_downloader_msg.cpp | 2 +- .../common/src/game_share/bg_downloader_msg.h | 2 +- .../common/src/game_share/login_registry.cpp | 35 ++++++++++--------- .../common/src/game_share/login_registry.h | 2 -- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/code/ryzom/client/src/bg_downloader_access.cpp b/code/ryzom/client/src/bg_downloader_access.cpp index 1603cae0f..d4aac9169 100644 --- a/code/ryzom/client/src/bg_downloader_access.cpp +++ b/code/ryzom/client/src/bg_downloader_access.cpp @@ -385,7 +385,7 @@ bool CBGDownloaderAccess::CDownloadCoTask::isDownloaderProcessRunning() { // the downloader creates a system-wide mutex, so if present, assume that the downloader is running // - HANDLE mutex = CreateMutex (NULL, FALSE, BGDownloader::DownloaderMutexName); + HANDLE mutex = CreateMutexW (NULL, FALSE, BGDownloader::DownloaderMutexName); if (mutex) { if (GetLastError() == ERROR_ALREADY_EXISTS) diff --git a/code/ryzom/client/src/permanent_ban.cpp b/code/ryzom/client/src/permanent_ban.cpp index cbd39d93f..dab097c79 100644 --- a/code/ryzom/client/src/permanent_ban.cpp +++ b/code/ryzom/client/src/permanent_ban.cpp @@ -25,8 +25,8 @@ using namespace NLMISC; -#define REGKEY_RYZOM_PATH "Software\\Nevrax\\ryzom" -#define REGKEY_PERMANENT_BAN "PB" +#define REGKEY_RYZOM_PATH L"Software\\Nevrax\\ryzom" +#define REGKEY_PERMANENT_BAN L"PB" // ************************************************************ @@ -36,10 +36,11 @@ static void setPermanentBanRegistryKey(bool on) nlinfo("Not implemented"); #else HKEY hKey; - if (RegCreateKey(HKEY_CURRENT_USER, REGKEY_RYZOM_PATH, &hKey)==ERROR_SUCCESS) + if (RegCreateKeyW(HKEY_CURRENT_USER, REGKEY_RYZOM_PATH, &hKey)==ERROR_SUCCESS) { DWORD permanentBan = on ? 1 : 0; - LONG result = RegSetValueEx(hKey, REGKEY_PERMANENT_BAN, 0, REG_DWORD, (LPBYTE)&permanentBan, 4); + LONG result = RegSetValueExW(hKey, REGKEY_PERMANENT_BAN, 0, REG_DWORD, (LPBYTE)&permanentBan, 4); + if (result != ERROR_SUCCESS) { nlwarning("pb key not created"); @@ -59,17 +60,20 @@ static bool getPermanentBanRegistryKey() return false; // not implemented #else HKEY hKey; - if (RegOpenKeyEx(HKEY_CURRENT_USER, REGKEY_RYZOM_PATH, 0, KEY_READ, &hKey)==ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_CURRENT_USER, REGKEY_RYZOM_PATH, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { DWORD permanentBan; DWORD type; DWORD dataSize = sizeof(DWORD); - RegQueryValueEx (hKey, REGKEY_PERMANENT_BAN, 0, &type, (LPBYTE)&permanentBan, &dataSize); + + RegQueryValueExW(hKey, REGKEY_PERMANENT_BAN, 0, &type, (LPBYTE)&permanentBan, &dataSize); + if (type == REG_DWORD && dataSize == sizeof(DWORD)) { return permanentBan != 0; } } + return false; #endif } diff --git a/code/ryzom/common/src/game_share/bg_downloader_msg.cpp b/code/ryzom/common/src/game_share/bg_downloader_msg.cpp index 8f00b4c3f..297770ddb 100644 --- a/code/ryzom/common/src/game_share/bg_downloader_msg.cpp +++ b/code/ryzom/common/src/game_share/bg_downloader_msg.cpp @@ -24,7 +24,7 @@ namespace BGDownloader { -const char *DownloaderMutexName = "RyzomBgDownloader"; +const wchar_t *DownloaderMutexName = L"RyzomBgDownloader"; ucstring getWrittenSize(uint32 nSize) { diff --git a/code/ryzom/common/src/game_share/bg_downloader_msg.h b/code/ryzom/common/src/game_share/bg_downloader_msg.h index e33224b70..da903493f 100644 --- a/code/ryzom/common/src/game_share/bg_downloader_msg.h +++ b/code/ryzom/common/src/game_share/bg_downloader_msg.h @@ -133,7 +133,7 @@ const uint RYZOM_PID_SHM_ID = 0x6b833f31; // name of the background downloader system-wide mutex -extern const char *DownloaderMutexName; +extern const wchar_t *DownloaderMutexName; // get patch written size in megabytes diff --git a/code/ryzom/common/src/game_share/login_registry.cpp b/code/ryzom/common/src/game_share/login_registry.cpp index f9947c392..489c8b22b 100644 --- a/code/ryzom/common/src/game_share/login_registry.cpp +++ b/code/ryzom/common/src/game_share/login_registry.cpp @@ -21,45 +21,47 @@ #include - -const char *CLoginRegistry::AppRegEntry = "Software\\Nevrax\\RyzomInstall"; -static const char *LoginStepKeyHandle = "LoginStep"; -static const char *InstallIdKeyHandle = "InstallId"; +static const wchar_t *AppRegEntry = L"Software\\Nevrax\\RyzomInstall"; +static const wchar_t *LoginStepKeyHandle = L"LoginStep"; +static const wchar_t *InstallIdKeyHandle = L"InstallId"; //=========================================================================================== std::string CLoginRegistry::getProductInstallId() { - - // read value HKEY hKey; - if (RegOpenKeyEx(HKEY_CURRENT_USER, AppRegEntry, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { const uint keyMaxLength = 1024; DWORD dwType = 0L; DWORD dwSize = keyMaxLength; - char buffer[keyMaxLength]; - if(RegQueryValueEx(hKey, InstallIdKeyHandle, NULL, &dwType, (unsigned char *) buffer, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ) + wchar_t buffer[keyMaxLength]; + if (RegQueryValueExW(hKey, InstallIdKeyHandle, NULL, &dwType, (BYTE *) buffer, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ) { RegCloseKey(hKey); - return buffer; + return wideToUtf8(buffer); } RegCloseKey(hKey); } + DWORD dwDisp; + // do not exist, create a new key - if(RegCreateKeyEx(HKEY_CURRENT_USER, AppRegEntry, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) == ERROR_SUCCESS) + if (RegCreateKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) == ERROR_SUCCESS) { srand((uint32)nl_time(0)); uint32 r = rand(); r <<= 16; r |= rand(); + std::string id = NLMISC::toString(r); - if (RegSetValueEx(hKey, InstallIdKeyHandle, 0L, REG_SZ, (const BYTE *) id.c_str(), (DWORD)(id.size())+1) == ERROR_SUCCESS) + + if (RegSetValueExW(hKey, InstallIdKeyHandle, 0L, REG_SZ, (const BYTE *) utf8ToWice(id), (DWORD)(id.size())+1) == ERROR_SUCCESS) { return id; } } + return ""; } @@ -67,17 +69,18 @@ std::string CLoginRegistry::getProductInstallId() uint CLoginRegistry::getLoginStep() { HKEY hKey; - if (RegOpenKeyEx(HKEY_CURRENT_USER, AppRegEntry, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { DWORD loginStep = 0; DWORD type; DWORD dataSize = sizeof(DWORD); - RegQueryValueEx (hKey, LoginStepKeyHandle, 0, &type, (LPBYTE) &loginStep, &dataSize); + RegQueryValueExW(hKey, LoginStepKeyHandle, 0, &type, (LPBYTE) &loginStep, &dataSize); if (type == REG_DWORD && dataSize == sizeof(DWORD)) { return (uint) loginStep; } } + return 0; } @@ -86,10 +89,10 @@ void CLoginRegistry::setLoginStep(uint step) { HKEY hKey; DWORD dwDisp; - if(RegCreateKeyEx(HKEY_CURRENT_USER, AppRegEntry, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) == ERROR_SUCCESS) + if (RegCreateKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) == ERROR_SUCCESS) { DWORD loginStep = step; - RegSetValueEx(hKey, LoginStepKeyHandle, 0L, REG_DWORD, (const BYTE *) &loginStep, sizeof(DWORD)); + RegSetValueExW(hKey, LoginStepKeyHandle, 0L, REG_DWORD, (const BYTE *) &loginStep, sizeof(DWORD)); } } diff --git a/code/ryzom/common/src/game_share/login_registry.h b/code/ryzom/common/src/game_share/login_registry.h index 954b48e7c..a0520b0cc 100644 --- a/code/ryzom/common/src/game_share/login_registry.h +++ b/code/ryzom/common/src/game_share/login_registry.h @@ -19,8 +19,6 @@ struct CLoginRegistry { - // key for the login registry infos - static const char *AppRegEntry; // Utility function to get a unique install id from the registry static std::string getProductInstallId(); // retrieve login step from the registry (0 if no step yet)