Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / common / src / game_share / login_registry.cpp
blob46207fec5dac7fb54418fee337e8895a96b1cb1a
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
21 #include "login_registry.h"
23 #ifdef NL_OS_WINDOWS
25 #include <windows.h>
27 static const wchar_t *AppRegEntry = L"Software\\Nevrax\\RyzomInstall";
28 static const wchar_t *LoginStepKeyHandle = L"LoginStep";
29 static const wchar_t *InstallIdKeyHandle = L"InstallId";
31 //===========================================================================================
32 std::string CLoginRegistry::getProductInstallId()
34 // read value
35 HKEY hKey;
36 if (RegOpenKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
38 const uint keyMaxLength = 1024;
39 DWORD dwType = 0L;
40 DWORD dwSize = keyMaxLength;
41 wchar_t buffer[keyMaxLength];
42 if (RegQueryValueExW(hKey, InstallIdKeyHandle, NULL, &dwType, (BYTE *) buffer, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ)
44 RegCloseKey(hKey);
45 return NLMISC::wideToUtf8(buffer);
47 RegCloseKey(hKey);
50 DWORD dwDisp;
52 // do not exist, create a new key
53 if (RegCreateKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) == ERROR_SUCCESS)
55 srand((uint32)nl_time(0));
56 uint32 r = rand();
57 r <<= 16;
58 r |= rand();
60 std::string id = NLMISC::toString(r);
62 // copy wide string to a buffer
63 const uint keyMaxLength = 16;
64 std::wstring wid = NLMISC::utf8ToWide(id);
66 if (RegSetValueExW(hKey, InstallIdKeyHandle, 0L, REG_SZ, (const BYTE *)wid.c_str(), (DWORD)((wid.size() + 1) * sizeof(WCHAR))) == ERROR_SUCCESS)
68 return id;
72 return "";
75 //===========================================================================================
76 uint CLoginRegistry::getLoginStep()
78 HKEY hKey;
79 if (RegOpenKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
81 DWORD loginStep = 0;
82 DWORD type;
83 DWORD dataSize = sizeof(DWORD);
84 RegQueryValueExW(hKey, LoginStepKeyHandle, 0, &type, (LPBYTE) &loginStep, &dataSize);
85 if (type == REG_DWORD && dataSize == sizeof(DWORD))
87 return (uint) loginStep;
91 return 0;
94 //===========================================================================================
95 void CLoginRegistry::setLoginStep(uint step)
97 HKEY hKey;
98 DWORD dwDisp;
99 if (RegCreateKeyExW(HKEY_CURRENT_USER, AppRegEntry, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) == ERROR_SUCCESS)
101 DWORD loginStep = step;
102 RegSetValueExW(hKey, LoginStepKeyHandle, 0L, REG_DWORD, (const BYTE *) &loginStep, sizeof(DWORD));
106 #else
108 static uint LoginStep = 0;
110 //===========================================================================================
111 std::string CLoginRegistry::getProductInstallId()
113 srand((uint32)nl_time(0));
114 uint32 r = rand();
115 r <<= 16;
116 r |= rand();
117 return NLMISC::toString(r);
120 //===========================================================================================
121 uint CLoginRegistry::getLoginStep()
123 return LoginStep;
126 //===========================================================================================
127 void CLoginRegistry::setLoginStep(uint step)
129 LoginStep = step;
132 #endif