1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
21 #include "login_registry.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()
36 if (RegOpenKeyExW(HKEY_CURRENT_USER
, AppRegEntry
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
38 const uint keyMaxLength
= 1024;
40 DWORD dwSize
= keyMaxLength
;
41 wchar_t buffer
[keyMaxLength
];
42 if (RegQueryValueExW(hKey
, InstallIdKeyHandle
, NULL
, &dwType
, (BYTE
*) buffer
, &dwSize
) == ERROR_SUCCESS
&& dwType
== REG_SZ
)
45 return NLMISC::wideToUtf8(buffer
);
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));
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
)
75 //===========================================================================================
76 uint
CLoginRegistry::getLoginStep()
79 if (RegOpenKeyExW(HKEY_CURRENT_USER
, AppRegEntry
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
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
;
94 //===========================================================================================
95 void CLoginRegistry::setLoginStep(uint step
)
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
));
108 static uint LoginStep
= 0;
110 //===========================================================================================
111 std::string
CLoginRegistry::getProductInstallId()
113 srand((uint32
)nl_time(0));
117 return NLMISC::toString(r
);
120 //===========================================================================================
121 uint
CLoginRegistry::getLoginStep()
126 //===========================================================================================
127 void CLoginRegistry::setLoginStep(uint step
)