| 1 |
/* |
| 2 |
Copyright (C) 2009-2010 wxLauncher Team |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "apis/ProfileManager.h" |
| 20 |
#include "apis/PlatformProfileManager.h" |
| 21 |
#include "apis/JoystickManager.h" |
| 22 |
#include "global/BasicDefaults.h" |
| 23 |
#include "global/ProfileKeys.h" |
| 24 |
#include "global/RegistryKeys.h" |
| 25 |
#include "generated/configure_launcher.h" |
| 26 |
|
| 27 |
#include <wx/process.h> |
| 28 |
#include <wx/filename.h> |
| 29 |
#include <wx/stdpaths.h> |
| 30 |
#include <wx/wfstream.h> |
| 31 |
#if PLATFORM_USES_REGISTRY == 1 |
| 32 |
#include <Windows.h> |
| 33 |
#include <Sddl.h> |
| 34 |
|
| 35 |
#if _MSC_VER >= 1800 |
| 36 |
#include <VersionHelpers.h> |
| 37 |
#endif |
| 38 |
|
| 39 |
#endif |
| 40 |
|
| 41 |
#include "global/MemoryDebugging.h" |
| 42 |
|
| 43 |
#if PLATFORM_USES_REGISTRY == 1 |
| 44 |
#define ReturnChecker(retvalue, location) \ |
| 45 |
if ( retvalue != ERROR_SUCCESS ) {\ |
| 46 |
LPWSTR message = NULL;\ |
| 47 |
DWORD nchars = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,\ |
| 48 |
NULL,\ |
| 49 |
retvalue,\ |
| 50 |
0,\ |
| 51 |
(LPWSTR)&message,\ |
| 52 |
0,\ |
| 53 |
NULL);\ |
| 54 |
if ( nchars == 0 ) {\ |
| 55 |
wxLogFatalError(_T("An error occurred, but unable to generate error message"));\ |
| 56 |
} else {\ |
| 57 |
wxMBConvUTF16 conv;\ |
| 58 |
wxString msg(message, conv, nchars);\ |
| 59 |
wxLogError(_T("Unhandled error in setting HKLM key in registry! %s"), msg);\ |
| 60 |
}\ |
| 61 |
return ProMan::UnknownError;\ |
| 62 |
} |
| 63 |
|
| 64 |
#define UNKOWN_ERROR_MSG _T("Unhandled error number %ld from query above line %d") |
| 65 |
#define REG_DATA_NOT_DWORD _T("Registry key lookup above line %d is not a DWORD") |
| 66 |
#define REG_DATA_NOT_STRING _T("Registry key lookup above line %d is not a DWORD") |
| 67 |
#endif |
| 68 |
|
| 69 |
#if PLATFORM_USES_REGISTRY == 1 |
| 70 |
|
| 71 |
typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); |
| 72 |
|
| 73 |
class WinAPI |
| 74 |
{ |
| 75 |
private: |
| 76 |
static bool inited; |
| 77 |
|
| 78 |
static LPFN_ISWOW64PROCESS fnIsWOW64Process; |
| 79 |
public: |
| 80 |
static bool IsInited() |
| 81 |
{ |
| 82 |
return inited; |
| 83 |
} |
| 84 |
|
| 85 |
static bool GetUserSID(wxString& outStr) |
| 86 |
{ |
| 87 |
HANDLE hToken = NULL; |
| 88 |
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken) == FALSE) |
| 89 |
{ |
| 90 |
wxLogError(_("Failed to get process token. Error Code: 0x%08x"), GetLastError()); |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
DWORD dwBufferSize; |
| 95 |
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwBufferSize); |
| 96 |
|
| 97 |
PTOKEN_USER ptkUser = (PTOKEN_USER) new BYTE[dwBufferSize]; |
| 98 |
if (ptkUser == NULL) |
| 99 |
{ |
| 100 |
wxLogError(_T("ptkUser is NULL")); |
| 101 |
return false; |
| 102 |
} |
| 103 |
|
| 104 |
if (GetTokenInformation(hToken, TokenUser, ptkUser, dwBufferSize, &dwBufferSize) == 0) |
| 105 |
{ |
| 106 |
wxLogError(_("Failed to get token information. Error Code: 0x%08x"), GetLastError()); |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
if (IsValidSid(ptkUser->User.Sid) == FALSE) |
| 111 |
{ |
| 112 |
wxLogError(_("SID structure is Invalid")); |
| 113 |
delete[] ptkUser; |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
LPTSTR sidName = NULL; |
| 118 |
if (ConvertSidToStringSid(ptkUser->User.Sid, &sidName) == 0) |
| 119 |
{ |
| 120 |
wxLogError(_("Failed to convert SID structure to string. Error Code: 0x%08x"), |
| 121 |
GetLastError()); |
| 122 |
delete[] ptkUser; |
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
outStr.assign(sidName); |
| 127 |
|
| 128 |
LocalFree(sidName); |
| 129 |
delete[] ptkUser; |
| 130 |
|
| 131 |
return true; |
| 132 |
} |
| 133 |
|
| 134 |
static void Init() |
| 135 |
{ |
| 136 |
HMODULE hKernel32 = GetModuleHandle(TEXT("Kernel32")); |
| 137 |
fnIsWOW64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(hKernel32, "IsWow64Process"); |
| 138 |
|
| 139 |
/* Use "Version Helper APIs" if available because GetVersionEx may |
| 140 |
not be available in versions of Windows after 8.1 */ |
| 141 |
#if _MSC_VER >= 1800 |
| 142 |
if (IsWindowsVistaOrGreater()) |
| 143 |
{ |
| 144 |
#else |
| 145 |
OSVERSIONINFO versionInfo; |
| 146 |
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
| 147 |
GetVersionEx(&versionInfo); |
| 148 |
|
| 149 |
/* The first version of Windows to have registry virtualization is |
| 150 |
Vista, aka 6.0 */ |
| 151 |
if (versionInfo.dwMajorVersion >= 6) |
| 152 |
{ |
| 153 |
#endif |
| 154 |
userSIDValid = GetUserSID(userSID); |
| 155 |
} |
| 156 |
|
| 157 |
inited = true; |
| 158 |
} |
| 159 |
|
| 160 |
static bool IsWow64() |
| 161 |
{ |
| 162 |
BOOL bIsWow64 = FALSE; |
| 163 |
if (fnIsWOW64Process != NULL) |
| 164 |
{ |
| 165 |
if (!fnIsWOW64Process(GetCurrentProcess(), &bIsWow64)) |
| 166 |
{ |
| 167 |
wxLogDebug(_("Failed to determine if process runs under WOW64")); |
| 168 |
} |
| 169 |
} |
| 170 |
return bIsWow64 == TRUE; |
| 171 |
} |
| 172 |
|
| 173 |
static wxString userSID; |
| 174 |
static bool userSIDValid; |
| 175 |
}; |
| 176 |
|
| 177 |
bool WinAPI::inited = false; |
| 178 |
bool WinAPI::userSIDValid = false; |
| 179 |
wxString WinAPI::userSID(wxT_2("")); |
| 180 |
LPFN_ISWOW64PROCESS WinAPI::fnIsWOW64Process = NULL; |
| 181 |
|
| 182 |
HKEY GetRegistryKeyname(wxString& out_keyname) |
| 183 |
{ |
| 184 |
if (!WinAPI::IsInited()) |
| 185 |
{ |
| 186 |
WinAPI::Init(); |
| 187 |
} |
| 188 |
|
| 189 |
// Every compiler from Visual Studio 2008 onward should have support for UAC |
| 190 |
#if _MSC_VER > 1400 |
| 191 |
if (WinAPI::userSIDValid) |
| 192 |
{ |
| 193 |
if (WinAPI::IsWow64()) |
| 194 |
{ |
| 195 |
out_keyname = wxString::Format(wxT_2("%s_Classes\\VirtualStore\\Machine\\Software\\Wow6432Node\\%s"), |
| 196 |
WinAPI::userSID.c_str(), REG_KEY_FOLDER_LOCATION.c_str()); |
| 197 |
} |
| 198 |
else |
| 199 |
{ |
| 200 |
out_keyname = wxString::Format(wxT_2("%s_Classes\\VirtualStore\\Machine\\Software\\%s"), |
| 201 |
WinAPI::userSID.c_str(), REG_KEY_FOLDER_LOCATION.c_str()); |
| 202 |
} |
| 203 |
return HKEY_USERS; |
| 204 |
} |
| 205 |
else |
| 206 |
{ |
| 207 |
out_keyname = wxString::Format(wxT_2("Software\\%s"), |
| 208 |
REG_KEY_FOLDER_LOCATION.c_str()); |
| 209 |
return HKEY_LOCAL_MACHINE; |
| 210 |
} |
| 211 |
#else |
| 212 |
out_keyname = REG_KEY_FOLDER_LOCATION; |
| 213 |
return HKEY_LOCAL_MACHINE; |
| 214 |
#endif |
| 215 |
} |
| 216 |
|
| 217 |
#endif |
| 218 |
|
| 219 |
|
| 220 |
/* File contains the Win32 incatations for Pushing and Pulling the passed |
| 221 |
profile to/from the registry. */ |
| 222 |
|
| 223 |
ProMan::RegistryCodes RegistryPushProfile(wxFileConfig *cfg) { |
| 224 |
#if PLATFORM_USES_REGISTRY == 1 |
| 225 |
wxString keyName; |
| 226 |
HKEY useKey = GetRegistryKeyname(keyName); |
| 227 |
|
| 228 |
LONG ret = ERROR_SUCCESS; |
| 229 |
HKEY regHandle = 0; |
| 230 |
|
| 231 |
ret = RegCreateKeyExW(useKey, |
| 232 |
keyName.wc_str(), |
| 233 |
0, // Reserved |
| 234 |
NULL, |
| 235 |
REG_OPTION_NON_VOLATILE, |
| 236 |
KEY_WRITE, |
| 237 |
NULL, // default security. |
| 238 |
®Handle, |
| 239 |
NULL // I don't care if the key was created before opening |
| 240 |
); |
| 241 |
|
| 242 |
if ( ret != ERROR_SUCCESS ) { |
| 243 |
// Call failed |
| 244 |
LPWSTR message = NULL; |
| 245 |
DWORD nchars = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 246 |
NULL, |
| 247 |
ret, |
| 248 |
0, |
| 249 |
(LPWSTR)&message, |
| 250 |
0, |
| 251 |
NULL); |
| 252 |
if ( nchars == 0 ) { |
| 253 |
wxLogFatalError(_T("An error occurred, but unable to generate error message")); |
| 254 |
} else { |
| 255 |
wxMBConvUTF16 conv; |
| 256 |
wxString msg(message, conv, nchars); |
| 257 |
wxLogError(_T("Unhandled error in creating HKLM key in registry! %s"), msg); |
| 258 |
LocalFree(message); |
| 259 |
} |
| 260 |
return ProMan::AccessDenied; |
| 261 |
} |
| 262 |
|
| 263 |
// Video |
| 264 |
int width, height, bitdepth; |
| 265 |
cfg->Read(PRO_CFG_VIDEO_RESOLUTION_WIDTH, &width, DEFAULT_VIDEO_RESOLUTION_WIDTH); |
| 266 |
cfg->Read(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, &height, DEFAULT_VIDEO_RESOLUTION_HEIGHT); |
| 267 |
cfg->Read(PRO_CFG_VIDEO_BIT_DEPTH, &bitdepth, DEFAULT_VIDEO_BIT_DEPTH); |
| 268 |
|
| 269 |
wxString videocardValue = wxString::Format(_T("OGL -(%dx%d)x%d bit"), width, height, bitdepth); |
| 270 |
ret = RegSetValueExW( |
| 271 |
regHandle, |
| 272 |
REG_KEY_VIDEO_RESOLUTION_DEPTH.wc_str(), |
| 273 |
0, |
| 274 |
REG_SZ, |
| 275 |
(BYTE*)videocardValue.wc_str(), |
| 276 |
(videocardValue.size() + 1)*2); |
| 277 |
ReturnChecker(ret, __LINE__); |
| 278 |
|
| 279 |
|
| 280 |
wxString filterMethod; |
| 281 |
cfg->Read(PRO_CFG_VIDEO_TEXTURE_FILTER, &filterMethod, DEFAULT_VIDEO_TEXTURE_FILTER); |
| 282 |
int filterMethodValue = ( filterMethod.StartsWith(_T("Bilinear"))) ? 0 : 1; |
| 283 |
|
| 284 |
ret = RegSetValueExW( |
| 285 |
regHandle, |
| 286 |
REG_KEY_VIDEO_TEXTURE_FILTER.wc_str(), |
| 287 |
0, |
| 288 |
REG_DWORD, |
| 289 |
(BYTE*)&filterMethodValue, |
| 290 |
sizeof(filterMethodValue)); |
| 291 |
ReturnChecker(ret, __LINE__); |
| 292 |
|
| 293 |
|
| 294 |
int oglAnisotropicFilterInt; |
| 295 |
cfg->Read(PRO_CFG_VIDEO_ANISOTROPIC, |
| 296 |
&oglAnisotropicFilterInt, |
| 297 |
DEFAULT_VIDEO_ANISOTROPIC); |
| 298 |
|
| 299 |
// Since FSO expects anisotropic to be a string, we must convert it |
| 300 |
wxString oglAnisotropicFilter( |
| 301 |
wxString::Format(_T("%d"), oglAnisotropicFilterInt)); |
| 302 |
|
| 303 |
ret = RegSetValueExW( |
| 304 |
regHandle, |
| 305 |
REG_KEY_VIDEO_ANISOTROPIC.wc_str(), |
| 306 |
0, |
| 307 |
REG_SZ, |
| 308 |
(BYTE*)oglAnisotropicFilter.wc_str(), |
| 309 |
(oglAnisotropicFilter.size() + 1)*2); |
| 310 |
ReturnChecker(ret, __LINE__); |
| 311 |
|
| 312 |
|
| 313 |
int oglAntiAliasSample; |
| 314 |
cfg->Read(PRO_CFG_VIDEO_ANTI_ALIAS, &oglAntiAliasSample, DEFAULT_VIDEO_ANTI_ALIAS); |
| 315 |
|
| 316 |
ret = RegSetValueExW( |
| 317 |
regHandle, |
| 318 |
REG_KEY_VIDEO_ANTI_ALIAS.wc_str(), |
| 319 |
0, |
| 320 |
REG_DWORD, |
| 321 |
(BYTE*)&oglAntiAliasSample, |
| 322 |
sizeof(oglAntiAliasSample)); |
| 323 |
ReturnChecker(ret, __LINE__); |
| 324 |
|
| 325 |
|
| 326 |
// Audio |
| 327 |
wxString soundDevice; |
| 328 |
cfg->Read(PRO_CFG_OPENAL_DEVICE, &soundDevice, DEFAULT_AUDIO_OPENAL_DEVICE); |
| 329 |
|
| 330 |
ret = RegSetValueExW( |
| 331 |
regHandle, |
| 332 |
REG_KEY_AUDIO_OPENAL_DEVICE.wc_str(), |
| 333 |
0, |
| 334 |
REG_SZ, |
| 335 |
(BYTE*)soundDevice.wc_str(), |
| 336 |
(soundDevice.size() + 1)*2); |
| 337 |
ReturnChecker(ret, __LINE__); |
| 338 |
|
| 339 |
|
| 340 |
// Audio folder (for new sound code settings) |
| 341 |
HKEY audioRegHandle = 0; |
| 342 |
ret = RegCreateKeyExW( |
| 343 |
regHandle, |
| 344 |
REG_KEY_AUDIO_FOLDER_REGISTRY.wc_str(), |
| 345 |
0, |
| 346 |
NULL, |
| 347 |
REG_OPTION_NON_VOLATILE, |
| 348 |
KEY_WRITE, |
| 349 |
NULL, |
| 350 |
&audioRegHandle, |
| 351 |
NULL); // just want handle, don't care if it was created or opened |
| 352 |
ReturnChecker(ret, __LINE__); |
| 353 |
|
| 354 |
|
| 355 |
wxString playbackDevice; |
| 356 |
cfg->Read( |
| 357 |
PRO_CFG_OPENAL_DEVICE, |
| 358 |
&playbackDevice, |
| 359 |
DEFAULT_AUDIO_OPENAL_PLAYBACK_DEVICE); |
| 360 |
|
| 361 |
ret = RegSetValueExW( |
| 362 |
audioRegHandle, |
| 363 |
REG_KEY_AUDIO_OPENAL_PLAYBACK_DEVICE.wc_str(), |
| 364 |
0, |
| 365 |
REG_SZ, |
| 366 |
(BYTE*)playbackDevice.wc_str(), |
| 367 |
(playbackDevice.size() + 1)*2); |
| 368 |
ReturnChecker(ret, __LINE__); |
| 369 |
|
| 370 |
|
| 371 |
wxString captureDevice; |
| 372 |
bool hasEntry = cfg->Read( |
| 373 |
PRO_CFG_OPENAL_CAPTURE_DEVICE, |
| 374 |
&captureDevice, |
| 375 |
DEFAULT_AUDIO_OPENAL_CAPTURE_DEVICE); |
| 376 |
|
| 377 |
if (hasEntry) { |
| 378 |
ret = RegSetValueExW( |
| 379 |
audioRegHandle, |
| 380 |
REG_KEY_AUDIO_OPENAL_CAPTURE_DEVICE.wc_str(), |
| 381 |
0, |
| 382 |
REG_SZ, |
| 383 |
(BYTE*)captureDevice.wc_str(), |
| 384 |
(captureDevice.size() + 1)*2); |
| 385 |
ReturnChecker(ret, __LINE__); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
int enableEFX; |
| 390 |
hasEntry = cfg->Read(PRO_CFG_OPENAL_EFX, &enableEFX, DEFAULT_AUDIO_OPENAL_EFX); |
| 391 |
|
| 392 |
if (hasEntry) { |
| 393 |
ret = RegSetValueExW( |
| 394 |
audioRegHandle, |
| 395 |
REG_KEY_AUDIO_OPENAL_EFX.wc_str(), |
| 396 |
0, |
| 397 |
REG_DWORD, |
| 398 |
(BYTE*)&enableEFX, |
| 399 |
sizeof(enableEFX)); |
| 400 |
ReturnChecker(ret, __LINE__); |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
int sampleRate; |
| 405 |
cfg->Read( |
| 406 |
PRO_CFG_OPENAL_SAMPLE_RATE, |
| 407 |
&sampleRate, |
| 408 |
DEFAULT_AUDIO_OPENAL_SAMPLE_RATE); |
| 409 |
|
| 410 |
if (sampleRate != DEFAULT_AUDIO_OPENAL_SAMPLE_RATE) { |
| 411 |
ret = RegSetValueExW( |
| 412 |
audioRegHandle, |
| 413 |
REG_KEY_AUDIO_OPENAL_SAMPLE_RATE.wc_str(), |
| 414 |
0, |
| 415 |
REG_DWORD, |
| 416 |
(BYTE*)&sampleRate, |
| 417 |
sizeof(sampleRate)); |
| 418 |
ReturnChecker(ret, __LINE__); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
RegCloseKey(audioRegHandle); |
| 423 |
|
| 424 |
|
| 425 |
// Speech |
| 426 |
int speechVoice; |
| 427 |
cfg->Read(PRO_CFG_SPEECH_VOICE, &speechVoice, DEFAULT_SPEECH_VOICE); |
| 428 |
|
| 429 |
ret = RegSetValueExW( |
| 430 |
regHandle, |
| 431 |
REG_KEY_SPEECH_VOICE.wc_str(), |
| 432 |
0, |
| 433 |
REG_DWORD, |
| 434 |
(BYTE*)&speechVoice, |
| 435 |
sizeof(speechVoice)); |
| 436 |
ReturnChecker(ret, __LINE__); |
| 437 |
|
| 438 |
|
| 439 |
int speechVolume; |
| 440 |
cfg->Read(PRO_CFG_SPEECH_VOLUME, &speechVolume, DEFAULT_SPEECH_VOLUME); |
| 441 |
|
| 442 |
ret = RegSetValueExW( |
| 443 |
regHandle, |
| 444 |
REG_KEY_SPEECH_VOLUME.wc_str(), |
| 445 |
0, |
| 446 |
REG_DWORD, |
| 447 |
(BYTE*)&speechVolume, |
| 448 |
sizeof(speechVolume)); |
| 449 |
ReturnChecker(ret, __LINE__); |
| 450 |
|
| 451 |
|
| 452 |
int inTechroom, inBriefings, inGame, inMulti; |
| 453 |
cfg->Read(PRO_CFG_SPEECH_IN_TECHROOM, &inTechroom, DEFAULT_SPEECH_IN_TECHROOM); |
| 454 |
cfg->Read(PRO_CFG_SPEECH_IN_BRIEFINGS, &inBriefings, DEFAULT_SPEECH_IN_BRIEFINGS); |
| 455 |
cfg->Read(PRO_CFG_SPEECH_IN_GAME, &inGame, DEFAULT_SPEECH_IN_GAME); |
| 456 |
cfg->Read(PRO_CFG_SPEECH_IN_MULTI, &inMulti, DEFAULT_SPEECH_IN_MULTI); |
| 457 |
|
| 458 |
ret = RegSetValueExW( |
| 459 |
regHandle, |
| 460 |
REG_KEY_SPEECH_IN_TECHROOM.wc_str(), |
| 461 |
0, |
| 462 |
REG_DWORD, |
| 463 |
(BYTE*)&inTechroom, |
| 464 |
sizeof(inTechroom)); |
| 465 |
ReturnChecker(ret, __LINE__); |
| 466 |
|
| 467 |
ret = RegSetValueExW( |
| 468 |
regHandle, |
| 469 |
REG_KEY_SPEECH_IN_BRIEFINGS.wc_str(), |
| 470 |
0, |
| 471 |
REG_DWORD, |
| 472 |
(BYTE*)&inBriefings, |
| 473 |
sizeof(inBriefings)); |
| 474 |
ReturnChecker(ret, __LINE__); |
| 475 |
|
| 476 |
ret = RegSetValueExW( |
| 477 |
regHandle, |
| 478 |
REG_KEY_SPEECH_IN_GAME.wc_str(), |
| 479 |
0, |
| 480 |
REG_DWORD, |
| 481 |
(BYTE*)&inGame, |
| 482 |
sizeof(inGame)); |
| 483 |
ReturnChecker(ret, __LINE__); |
| 484 |
|
| 485 |
ret = RegSetValueExW( |
| 486 |
regHandle, |
| 487 |
REG_KEY_SPEECH_IN_MULTI.wc_str(), |
| 488 |
0, |
| 489 |
REG_DWORD, |
| 490 |
(BYTE*)&inMulti, |
| 491 |
sizeof(inMulti)); |
| 492 |
ReturnChecker(ret, __LINE__); |
| 493 |
|
| 494 |
|
| 495 |
// Joystick |
| 496 |
int currentJoystick; |
| 497 |
cfg->Read(PRO_CFG_JOYSTICK_ID, ¤tJoystick, DEFAULT_JOYSTICK_ID); |
| 498 |
|
| 499 |
ret = RegSetValueExW( |
| 500 |
regHandle, |
| 501 |
REG_KEY_JOYSTICK_ID.wc_str(), |
| 502 |
0, |
| 503 |
REG_DWORD, |
| 504 |
(BYTE*)¤tJoystick, |
| 505 |
sizeof(currentJoystick)); |
| 506 |
ReturnChecker(ret, __LINE__); |
| 507 |
|
| 508 |
// Joystick GUID |
| 509 |
wxString currentJoystickGUID = JoyMan::JoystickGUID(currentJoystick); |
| 510 |
|
| 511 |
ret = RegSetValueExW( |
| 512 |
regHandle, |
| 513 |
REG_KEY_JOYSTICK_GUID.wc_str(), |
| 514 |
0, |
| 515 |
REG_SZ, |
| 516 |
(BYTE*)currentJoystickGUID.wc_str(), |
| 517 |
(currentJoystickGUID.size() + 1) * 2); |
| 518 |
ReturnChecker(ret, __LINE__); |
| 519 |
|
| 520 |
|
| 521 |
int joystickForceFeedback; |
| 522 |
cfg->Read( |
| 523 |
PRO_CFG_JOYSTICK_FORCE_FEEDBACK, |
| 524 |
&joystickForceFeedback, |
| 525 |
DEFAULT_JOYSTICK_FORCE_FEEDBACK); |
| 526 |
|
| 527 |
ret = RegSetValueExW( |
| 528 |
regHandle, |
| 529 |
REG_KEY_JOYSTICK_FORCE_FEEDBACK.wc_str(), |
| 530 |
0, |
| 531 |
REG_DWORD, |
| 532 |
(BYTE*)&joystickForceFeedback, |
| 533 |
sizeof(joystickForceFeedback)); |
| 534 |
ReturnChecker(ret, __LINE__); |
| 535 |
|
| 536 |
|
| 537 |
int joystickHit; |
| 538 |
cfg->Read(PRO_CFG_JOYSTICK_DIRECTIONAL, &joystickHit, DEFAULT_JOYSTICK_DIRECTIONAL); |
| 539 |
|
| 540 |
ret = RegSetValueExW( |
| 541 |
regHandle, |
| 542 |
REG_KEY_JOYSTICK_DIRECTIONAL.wc_str(), |
| 543 |
0, |
| 544 |
REG_DWORD, |
| 545 |
(BYTE*)&joystickHit, |
| 546 |
sizeof(joystickHit)); |
| 547 |
ReturnChecker(ret, __LINE__); |
| 548 |
|
| 549 |
|
| 550 |
// Network |
| 551 |
wxString networkConnectionValue; |
| 552 |
cfg->Read(PRO_CFG_NETWORK_TYPE, &networkConnectionValue, DEFAULT_NETWORK_TYPE); |
| 553 |
|
| 554 |
ret = RegSetValueExW( |
| 555 |
regHandle, |
| 556 |
REG_KEY_NETWORK_TYPE.wc_str(), |
| 557 |
0, |
| 558 |
REG_SZ, |
| 559 |
(BYTE*)networkConnectionValue.wc_str(), |
| 560 |
(networkConnectionValue.size() + 1)*2); |
| 561 |
ReturnChecker(ret, __LINE__); |
| 562 |
|
| 563 |
|
| 564 |
wxString connectionSpeedValue; |
| 565 |
cfg->Read(PRO_CFG_NETWORK_SPEED, &connectionSpeedValue, DEFAULT_NETWORK_SPEED); |
| 566 |
|
| 567 |
ret = RegSetValueExW( |
| 568 |
regHandle, |
| 569 |
REG_KEY_NETWORK_SPEED.wc_str(), |
| 570 |
0, |
| 571 |
REG_SZ, |
| 572 |
(BYTE*)connectionSpeedValue.wc_str(), |
| 573 |
(connectionSpeedValue.size() + 1)*2); |
| 574 |
ReturnChecker(ret, __LINE__); |
| 575 |
|
| 576 |
|
| 577 |
int forcedport; |
| 578 |
cfg->Read(PRO_CFG_NETWORK_PORT, &forcedport, DEFAULT_NETWORK_PORT); |
| 579 |
|
| 580 |
if (forcedport != DEFAULT_NETWORK_PORT) { |
| 581 |
ret = RegSetValueExW( |
| 582 |
regHandle, |
| 583 |
REG_KEY_NETWORK_PORT.wc_str(), |
| 584 |
0, |
| 585 |
REG_DWORD, |
| 586 |
(BYTE*)&forcedport, |
| 587 |
sizeof(forcedport)); |
| 588 |
ReturnChecker(ret, __LINE__); |
| 589 |
} else { |
| 590 |
wxLogDebug(_T("Forced Port is default. Clearing entry if it exists.")); |
| 591 |
|
| 592 |
ret = RegDeleteValueW( |
| 593 |
regHandle, |
| 594 |
REG_KEY_NETWORK_PORT.wc_str()); |
| 595 |
|
| 596 |
if (ret != ERROR_FILE_NOT_FOUND) { // ignore if entry doesn't exist |
| 597 |
ReturnChecker(ret, __LINE__); |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
wxString networkIP; |
| 603 |
cfg->Read(PRO_CFG_NETWORK_IP, &networkIP, DEFAULT_NETWORK_IP); |
| 604 |
|
| 605 |
// Network folder (for custom IP address) |
| 606 |
HKEY networkRegHandle = 0; |
| 607 |
ret = RegCreateKeyExW( |
| 608 |
regHandle, |
| 609 |
REG_KEY_NETWORK_FOLDER_REGISTRY.wc_str(), |
| 610 |
0, |
| 611 |
NULL, |
| 612 |
REG_OPTION_NON_VOLATILE, |
| 613 |
KEY_WRITE, |
| 614 |
NULL, |
| 615 |
&networkRegHandle, |
| 616 |
NULL); // just want handle, don't care if it was created or opened |
| 617 |
ReturnChecker(ret, __LINE__); |
| 618 |
|
| 619 |
if (networkIP != DEFAULT_NETWORK_IP) { |
| 620 |
ret = RegSetValueExW( |
| 621 |
networkRegHandle, |
| 622 |
REG_KEY_NETWORK_IP.wc_str(), |
| 623 |
0, |
| 624 |
REG_SZ, |
| 625 |
(BYTE*)networkIP.wc_str(), |
| 626 |
(networkIP.size()+1)*2); |
| 627 |
ReturnChecker(ret, __LINE__); |
| 628 |
} else { |
| 629 |
wxLogDebug(_T("Custom IP is default. Clearing entry if it exists.")); |
| 630 |
|
| 631 |
ret = RegDeleteValueW( |
| 632 |
networkRegHandle, |
| 633 |
REG_KEY_NETWORK_IP.wc_str()); |
| 634 |
|
| 635 |
if (ret != ERROR_FILE_NOT_FOUND) { // ignore if entry doesn't exist |
| 636 |
ReturnChecker(ret, __LINE__); |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
RegCloseKey(networkRegHandle); |
| 641 |
|
| 642 |
|
| 643 |
RegCloseKey(regHandle); |
| 644 |
|
| 645 |
return PushCmdlineFSO(cfg); |
| 646 |
#else // PLATFORM_USES_REGISTRY |
| 647 |
return ProMan::SupportNotCompiledIn; |
| 648 |
#endif // PLATFORM_USES_REGISTRY |
| 649 |
} |
| 650 |
|
| 651 |
ProMan::RegistryCodes RegistryPullProfile(wxFileConfig *cfg) { |
| 652 |
#if PLATFORM_USES_REGISTRY == 1 |
| 653 |
wxString keyName; |
| 654 |
HKEY useKey = GetRegistryKeyname(keyName); |
| 655 |
|
| 656 |
LONG ret = ERROR_SUCCESS; |
| 657 |
HKEY regHandle = 0; |
| 658 |
|
| 659 |
ret = RegCreateKeyExW(useKey, |
| 660 |
keyName.wc_str(), |
| 661 |
0, // Reserved |
| 662 |
NULL, |
| 663 |
REG_OPTION_NON_VOLATILE, |
| 664 |
KEY_READ, |
| 665 |
NULL, // default security. |
| 666 |
®Handle, |
| 667 |
NULL // I don't care if the key was created before opening |
| 668 |
); |
| 669 |
|
| 670 |
if ( ret != ERROR_SUCCESS ) { |
| 671 |
// Call failed |
| 672 |
LPWSTR message = NULL; |
| 673 |
DWORD nchars = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 674 |
NULL, |
| 675 |
ret, |
| 676 |
0, |
| 677 |
(LPWSTR)&message, |
| 678 |
0, |
| 679 |
NULL); |
| 680 |
if ( nchars == 0 ) { |
| 681 |
wxLogFatalError(_T("An error occurred, but unable to generate error message")); |
| 682 |
} else { |
| 683 |
wxMBConvUTF16 conv; |
| 684 |
wxString msg(message, conv, nchars); |
| 685 |
wxLogError(_T("Unhandled error in creating HKLM key in registry! %s"), msg); |
| 686 |
LocalFree(message); |
| 687 |
} |
| 688 |
return ProMan::AccessDenied; |
| 689 |
} |
| 690 |
wxMBConvUTF16 textConv; |
| 691 |
DWORD type = 0; |
| 692 |
BYTE data[MAX_PATH*2]; |
| 693 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 694 |
DWORD dataSize = sizeof(data); |
| 695 |
|
| 696 |
// Video |
| 697 |
ret = RegQueryValueEx( |
| 698 |
regHandle, |
| 699 |
REG_KEY_VIDEO_RESOLUTION_DEPTH.wc_str(), |
| 700 |
NULL, // Reserved |
| 701 |
&type, |
| 702 |
data, |
| 703 |
&dataSize); |
| 704 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 705 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 706 |
return ProMan::UnknownError; |
| 707 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS ) { |
| 708 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 709 |
} else { |
| 710 |
// parses VideocardFS2open into its parts |
| 711 |
const char* data1 = reinterpret_cast<char*>(data); |
| 712 |
wxString videoCard(data1, textConv, dataSize); |
| 713 |
wxString rest, rest1, rest2, rest3; |
| 714 |
|
| 715 |
long width = 0, height = 0, bitdepth = 0; |
| 716 |
if ( videoCard.StartsWith(_T("OGL -("), &rest) ) { |
| 717 |
int xLocation = rest.Find(_T('x')); |
| 718 |
if ( xLocation != wxNOT_FOUND ) { |
| 719 |
wxString widthStr(rest.Mid(0, xLocation)); |
| 720 |
rest1 = rest.Mid(xLocation); |
| 721 |
if ( !widthStr.ToLong(&width, 10) ) { |
| 722 |
width = 0; |
| 723 |
} |
| 724 |
int bLocation = rest1.Find(_T(')')); |
| 725 |
if ( bLocation != wxNOT_FOUND ) { |
| 726 |
wxString heightStr(rest1.Mid(0, bLocation)); |
| 727 |
rest2 = rest1.Mid(bLocation+1); |
| 728 |
if ( !heightStr.ToLong(&height, 10) ) { |
| 729 |
height = 0; |
| 730 |
} |
| 731 |
int spaceLoc = rest2.Find(_T(' ')); |
| 732 |
if ( spaceLoc != wxNOT_FOUND ) { |
| 733 |
wxString bitStr(rest2.Mid(0, spaceLoc)); |
| 734 |
if ( !bitStr.ToLong(&bitdepth, 10) ) { |
| 735 |
bitdepth = 0; |
| 736 |
} |
| 737 |
} |
| 738 |
} |
| 739 |
} |
| 740 |
} |
| 741 |
if ( width > 0 ) { |
| 742 |
cfg->Write(PRO_CFG_VIDEO_RESOLUTION_WIDTH, width); |
| 743 |
} |
| 744 |
if ( height > 0 ) { |
| 745 |
cfg->Write(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, height); |
| 746 |
} |
| 747 |
if ( bitdepth > 0 ) { |
| 748 |
cfg->Write(PRO_CFG_VIDEO_BIT_DEPTH, bitdepth); |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
DWORD numberdata; |
| 754 |
|
| 755 |
type = 0; |
| 756 |
numberdata = 0; |
| 757 |
dataSize = sizeof(numberdata); |
| 758 |
|
| 759 |
ret = RegQueryValueExW( |
| 760 |
regHandle, |
| 761 |
REG_KEY_VIDEO_TEXTURE_FILTER.wc_str(), |
| 762 |
NULL, |
| 763 |
&type, |
| 764 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 765 |
&dataSize); |
| 766 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 767 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 768 |
return ProMan::UnknownError; |
| 769 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 770 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 771 |
} else { |
| 772 |
cfg->Write(PRO_CFG_VIDEO_TEXTURE_FILTER, static_cast<long>(numberdata)); |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
type = 0; |
| 777 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 778 |
dataSize = sizeof(data); |
| 779 |
|
| 780 |
ret = RegQueryValueExW( |
| 781 |
regHandle, |
| 782 |
REG_KEY_VIDEO_ANISOTROPIC.wc_str(), |
| 783 |
NULL, |
| 784 |
&type, |
| 785 |
data, |
| 786 |
&dataSize); |
| 787 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 788 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 789 |
return ProMan::UnknownError; |
| 790 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 791 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 792 |
} else { |
| 793 |
const char* data1 = reinterpret_cast<char*>(data); |
| 794 |
wxString ani(data1, textConv, dataSize); |
| 795 |
|
| 796 |
long anisotropic; |
| 797 |
if ( !ani.IsEmpty() && ani.ToLong(&anisotropic)) { |
| 798 |
cfg->Write(PRO_CFG_VIDEO_ANISOTROPIC, anisotropic); |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
type = 0; |
| 804 |
numberdata = 0; |
| 805 |
dataSize = sizeof(numberdata); |
| 806 |
|
| 807 |
ret = RegQueryValueExW( |
| 808 |
regHandle, |
| 809 |
REG_KEY_VIDEO_ANTI_ALIAS.wc_str(), |
| 810 |
NULL, |
| 811 |
&type, |
| 812 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 813 |
&dataSize); |
| 814 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 815 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 816 |
return ProMan::UnknownError; |
| 817 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 818 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 819 |
} else { |
| 820 |
cfg->Write(PRO_CFG_VIDEO_ANTI_ALIAS, static_cast<long>(numberdata)); |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
// Audio |
| 825 |
type = 0; |
| 826 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 827 |
dataSize = sizeof(data); |
| 828 |
|
| 829 |
ret = RegQueryValueExW( |
| 830 |
regHandle, |
| 831 |
REG_KEY_AUDIO_OPENAL_DEVICE.wc_str(), |
| 832 |
NULL, |
| 833 |
&type, |
| 834 |
data, |
| 835 |
&dataSize); |
| 836 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 837 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 838 |
return ProMan::UnknownError; |
| 839 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 840 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 841 |
} else { |
| 842 |
const char* data1 = reinterpret_cast<char*>(data); |
| 843 |
wxString soundDevice(data1, textConv, dataSize); |
| 844 |
|
| 845 |
if ( !soundDevice.IsEmpty() ) { |
| 846 |
cfg->Write(PRO_CFG_OPENAL_DEVICE, soundDevice); |
| 847 |
} |
| 848 |
} |
| 849 |
|
| 850 |
// Audio folder |
| 851 |
HKEY audioRegHandle = 0; |
| 852 |
ret = RegCreateKeyExW( |
| 853 |
regHandle, |
| 854 |
REG_KEY_AUDIO_FOLDER_REGISTRY.wc_str(), |
| 855 |
0, |
| 856 |
NULL, |
| 857 |
REG_OPTION_NON_VOLATILE, |
| 858 |
KEY_WRITE | KEY_READ, // need write to make sure we get the virtualized registry when reading. |
| 859 |
NULL, |
| 860 |
&audioRegHandle, |
| 861 |
NULL); // just want handle, don't care if it was created or opened |
| 862 |
ReturnChecker(ret, __LINE__); |
| 863 |
|
| 864 |
|
| 865 |
type = 0; |
| 866 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 867 |
dataSize = sizeof(data); |
| 868 |
|
| 869 |
ret = RegQueryValueExW( |
| 870 |
audioRegHandle, |
| 871 |
REG_KEY_AUDIO_OPENAL_PLAYBACK_DEVICE.wc_str(), |
| 872 |
NULL, |
| 873 |
&type, |
| 874 |
data, |
| 875 |
&dataSize); |
| 876 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 877 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 878 |
return ProMan::UnknownError; |
| 879 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 880 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 881 |
} else { |
| 882 |
const char* data1 = reinterpret_cast<char*>(data); |
| 883 |
wxString playbackDevice(data1, textConv, dataSize); |
| 884 |
|
| 885 |
if ( !playbackDevice.IsEmpty() && !cfg->Exists(PRO_CFG_OPENAL_DEVICE)) { |
| 886 |
cfg->Write(PRO_CFG_OPENAL_DEVICE, playbackDevice); |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
|
| 891 |
type = 0; |
| 892 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 893 |
dataSize = sizeof(data); |
| 894 |
|
| 895 |
ret = RegQueryValueExW( |
| 896 |
audioRegHandle, |
| 897 |
REG_KEY_AUDIO_OPENAL_CAPTURE_DEVICE.wc_str(), |
| 898 |
NULL, |
| 899 |
&type, |
| 900 |
data, |
| 901 |
&dataSize); |
| 902 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 903 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 904 |
return ProMan::UnknownError; |
| 905 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 906 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 907 |
} else { |
| 908 |
const char* data1 = reinterpret_cast<char*>(data); |
| 909 |
wxString captureDevice(data1, textConv, dataSize); |
| 910 |
|
| 911 |
if ( !captureDevice.IsEmpty() ) { |
| 912 |
cfg->Write(PRO_CFG_OPENAL_CAPTURE_DEVICE, captureDevice); |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
type = 0; |
| 918 |
numberdata = 0; |
| 919 |
dataSize = sizeof(numberdata); |
| 920 |
|
| 921 |
ret = RegQueryValueExW( |
| 922 |
audioRegHandle, |
| 923 |
REG_KEY_AUDIO_OPENAL_EFX.wc_str(), |
| 924 |
NULL, |
| 925 |
&type, |
| 926 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 927 |
&dataSize); |
| 928 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 929 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 930 |
return ProMan::UnknownError; |
| 931 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 932 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 933 |
} else { |
| 934 |
cfg->Write(PRO_CFG_OPENAL_EFX, static_cast<long>(numberdata)); |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
type = 0; |
| 939 |
numberdata = 0; |
| 940 |
dataSize = sizeof(numberdata); |
| 941 |
|
| 942 |
ret = RegQueryValueExW( |
| 943 |
audioRegHandle, |
| 944 |
REG_KEY_AUDIO_OPENAL_SAMPLE_RATE.wc_str(), |
| 945 |
NULL, |
| 946 |
&type, |
| 947 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 948 |
&dataSize); |
| 949 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 950 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 951 |
return ProMan::UnknownError; |
| 952 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 953 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 954 |
} else { |
| 955 |
cfg->Write(PRO_CFG_OPENAL_SAMPLE_RATE, static_cast<long>(numberdata)); |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
// Speech |
| 960 |
type = 0; |
| 961 |
numberdata = 0; |
| 962 |
dataSize = sizeof(numberdata); |
| 963 |
|
| 964 |
ret = RegQueryValueExW( |
| 965 |
regHandle, |
| 966 |
REG_KEY_SPEECH_VOICE.wc_str(), |
| 967 |
NULL, |
| 968 |
&type, |
| 969 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 970 |
&dataSize); |
| 971 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 972 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 973 |
return ProMan::UnknownError; |
| 974 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 975 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 976 |
} else { |
| 977 |
cfg->Write(PRO_CFG_SPEECH_VOICE, static_cast<long>(numberdata)); |
| 978 |
} |
| 979 |
|
| 980 |
|
| 981 |
type = 0; |
| 982 |
numberdata = 0; |
| 983 |
dataSize = sizeof(numberdata); |
| 984 |
|
| 985 |
ret = RegQueryValueExW( |
| 986 |
regHandle, |
| 987 |
REG_KEY_SPEECH_VOLUME.wc_str(), |
| 988 |
NULL, |
| 989 |
&type, |
| 990 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 991 |
&dataSize); |
| 992 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 993 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 994 |
return ProMan::UnknownError; |
| 995 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 996 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 997 |
} else { |
| 998 |
cfg->Write(PRO_CFG_SPEECH_VOLUME, static_cast<long>(numberdata)); |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
type = 0; |
| 1003 |
numberdata = 0; |
| 1004 |
dataSize = sizeof(numberdata); |
| 1005 |
|
| 1006 |
ret = RegQueryValueExW( |
| 1007 |
regHandle, |
| 1008 |
REG_KEY_SPEECH_IN_TECHROOM.wc_str(), |
| 1009 |
NULL, |
| 1010 |
&type, |
| 1011 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1012 |
&dataSize); |
| 1013 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1014 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1015 |
return ProMan::UnknownError; |
| 1016 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1017 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1018 |
} else { |
| 1019 |
cfg->Write(PRO_CFG_SPEECH_IN_TECHROOM, static_cast<long>(numberdata)); |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
type = 0; |
| 1024 |
numberdata = 0; |
| 1025 |
dataSize = sizeof(numberdata); |
| 1026 |
|
| 1027 |
ret = RegQueryValueExW( |
| 1028 |
regHandle, |
| 1029 |
REG_KEY_SPEECH_IN_BRIEFINGS.wc_str(), |
| 1030 |
NULL, |
| 1031 |
&type, |
| 1032 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1033 |
&dataSize); |
| 1034 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1035 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1036 |
return ProMan::UnknownError; |
| 1037 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1038 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1039 |
} else { |
| 1040 |
cfg->Write(PRO_CFG_SPEECH_IN_BRIEFINGS, static_cast<long>(numberdata)); |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
type = 0; |
| 1045 |
numberdata = 0; |
| 1046 |
dataSize = sizeof(numberdata); |
| 1047 |
|
| 1048 |
ret = RegQueryValueExW( |
| 1049 |
regHandle, |
| 1050 |
REG_KEY_SPEECH_IN_GAME.wc_str(), |
| 1051 |
NULL, |
| 1052 |
&type, |
| 1053 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1054 |
&dataSize); |
| 1055 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1056 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1057 |
return ProMan::UnknownError; |
| 1058 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1059 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1060 |
} else { |
| 1061 |
cfg->Write(PRO_CFG_SPEECH_IN_GAME, static_cast<long>(numberdata)); |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
type = 0; |
| 1066 |
numberdata = 0; |
| 1067 |
dataSize = sizeof(numberdata); |
| 1068 |
|
| 1069 |
ret = RegQueryValueExW( |
| 1070 |
regHandle, |
| 1071 |
REG_KEY_SPEECH_IN_MULTI.wc_str(), |
| 1072 |
NULL, |
| 1073 |
&type, |
| 1074 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1075 |
&dataSize); |
| 1076 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1077 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1078 |
return ProMan::UnknownError; |
| 1079 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1080 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1081 |
} else { |
| 1082 |
cfg->Write(PRO_CFG_SPEECH_IN_MULTI, static_cast<long>(numberdata)); |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
// Joystick |
| 1087 |
type = 0; |
| 1088 |
numberdata = 0; |
| 1089 |
dataSize = sizeof(numberdata); |
| 1090 |
|
| 1091 |
ret = RegQueryValueExW( |
| 1092 |
regHandle, |
| 1093 |
REG_KEY_JOYSTICK_ID.wc_str(), |
| 1094 |
NULL, |
| 1095 |
&type, |
| 1096 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1097 |
&dataSize); |
| 1098 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1099 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1100 |
return ProMan::UnknownError; |
| 1101 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1102 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1103 |
} else { |
| 1104 |
cfg->Write(PRO_CFG_JOYSTICK_ID, static_cast<long>(numberdata)); |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
type = 0; |
| 1109 |
numberdata = 0; |
| 1110 |
dataSize = sizeof(numberdata); |
| 1111 |
|
| 1112 |
ret = RegQueryValueExW( |
| 1113 |
regHandle, |
| 1114 |
REG_KEY_JOYSTICK_FORCE_FEEDBACK.wc_str(), |
| 1115 |
NULL, |
| 1116 |
&type, |
| 1117 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1118 |
&dataSize); |
| 1119 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1120 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1121 |
return ProMan::UnknownError; |
| 1122 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1123 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1124 |
} else { |
| 1125 |
cfg->Write(PRO_CFG_JOYSTICK_FORCE_FEEDBACK, static_cast<long>(numberdata)); |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
type = 0; |
| 1130 |
numberdata = 0; |
| 1131 |
dataSize = sizeof(numberdata); |
| 1132 |
|
| 1133 |
ret = RegQueryValueExW( |
| 1134 |
regHandle, |
| 1135 |
REG_KEY_JOYSTICK_DIRECTIONAL.wc_str(), |
| 1136 |
NULL, |
| 1137 |
&type, |
| 1138 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1139 |
&dataSize); |
| 1140 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1141 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1142 |
return ProMan::UnknownError; |
| 1143 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1144 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1145 |
} else { |
| 1146 |
cfg->Write(PRO_CFG_JOYSTICK_DIRECTIONAL, static_cast<long>(numberdata)); |
| 1147 |
} |
| 1148 |
|
| 1149 |
|
| 1150 |
// Network |
| 1151 |
type = 0; |
| 1152 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 1153 |
dataSize = sizeof(data); |
| 1154 |
|
| 1155 |
ret = RegQueryValueExW( |
| 1156 |
regHandle, |
| 1157 |
REG_KEY_NETWORK_TYPE.wc_str(), |
| 1158 |
NULL, |
| 1159 |
&type, |
| 1160 |
data, |
| 1161 |
&dataSize); |
| 1162 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1163 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1164 |
return ProMan::UnknownError; |
| 1165 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 1166 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 1167 |
} else { |
| 1168 |
const char* data1 = reinterpret_cast<char*>(data); |
| 1169 |
wxString connection(data1, textConv, dataSize); |
| 1170 |
|
| 1171 |
if ( !connection.IsEmpty() ) { |
| 1172 |
cfg->Write(PRO_CFG_NETWORK_TYPE, connection); |
| 1173 |
} |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
type = 0; |
| 1178 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 1179 |
dataSize = sizeof(data); |
| 1180 |
|
| 1181 |
ret = RegQueryValueExW( |
| 1182 |
regHandle, |
| 1183 |
REG_KEY_NETWORK_SPEED.wc_str(), |
| 1184 |
NULL, |
| 1185 |
&type, |
| 1186 |
data, |
| 1187 |
&dataSize); |
| 1188 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1189 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1190 |
return ProMan::UnknownError; |
| 1191 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 1192 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 1193 |
} else { |
| 1194 |
const char* data1 = reinterpret_cast<char*>(data); |
| 1195 |
wxString speed(data1, textConv, dataSize); |
| 1196 |
|
| 1197 |
if ( !speed.IsEmpty() ) { |
| 1198 |
cfg->Write(PRO_CFG_NETWORK_SPEED, speed); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
type = 0; |
| 1204 |
numberdata = 0; |
| 1205 |
dataSize = sizeof(numberdata); |
| 1206 |
|
| 1207 |
ret = RegQueryValueExW( |
| 1208 |
regHandle, |
| 1209 |
REG_KEY_NETWORK_PORT.wc_str(), |
| 1210 |
NULL, |
| 1211 |
&type, |
| 1212 |
reinterpret_cast<LPBYTE>(&numberdata), |
| 1213 |
&dataSize); |
| 1214 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1215 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1216 |
return ProMan::UnknownError; |
| 1217 |
} else if ( type != REG_DWORD && ret == ERROR_SUCCESS) { |
| 1218 |
wxLogWarning(REG_DATA_NOT_DWORD, __LINE__); |
| 1219 |
} else { |
| 1220 |
cfg->Write(PRO_CFG_NETWORK_PORT, static_cast<long>(numberdata)); |
| 1221 |
} |
| 1222 |
|
| 1223 |
|
| 1224 |
// Network folder |
| 1225 |
HKEY networkRegHandle = 0; |
| 1226 |
ret = RegCreateKeyExW( |
| 1227 |
regHandle, |
| 1228 |
REG_KEY_NETWORK_FOLDER_REGISTRY.wc_str(), |
| 1229 |
0, |
| 1230 |
NULL, |
| 1231 |
REG_OPTION_NON_VOLATILE, |
| 1232 |
KEY_WRITE | KEY_READ, // need write to make sure we get the virtualized registry when reading. |
| 1233 |
NULL, |
| 1234 |
&networkRegHandle, |
| 1235 |
NULL); // just want handle, don't care if it was created or opened |
| 1236 |
ReturnChecker(ret, __LINE__); |
| 1237 |
|
| 1238 |
|
| 1239 |
type = 0; |
| 1240 |
memset(static_cast<void*>(data), 0, MAX_PATH*2); |
| 1241 |
dataSize = sizeof(data); |
| 1242 |
|
| 1243 |
ret = RegQueryValueExW( |
| 1244 |
networkRegHandle, |
| 1245 |
REG_KEY_NETWORK_IP.wc_str(), |
| 1246 |
NULL, |
| 1247 |
&type, |
| 1248 |
data, |
| 1249 |
&dataSize); |
| 1250 |
if ( ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND ) { |
| 1251 |
wxLogError(UNKOWN_ERROR_MSG, ret, __LINE__); |
| 1252 |
return ProMan::UnknownError; |
| 1253 |
} else if ( type != REG_SZ && ret == ERROR_SUCCESS) { |
| 1254 |
wxLogWarning(REG_DATA_NOT_STRING, __LINE__); |
| 1255 |
} else { |
| 1256 |
const char* data1 = reinterpret_cast<char*>(data); |
| 1257 |
wxString ip(data1, textConv, dataSize); |
| 1258 |
|
| 1259 |
if ( !ip.IsEmpty() ) { |
| 1260 |
cfg->Write(PRO_CFG_NETWORK_IP, ip); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
RegCloseKey(audioRegHandle); |
| 1266 |
RegCloseKey(networkRegHandle); |
| 1267 |
RegCloseKey(regHandle); |
| 1268 |
|
| 1269 |
return ProMan::NoError; |
| 1270 |
#else // PLATFORM_USES_REGISTRY |
| 1271 |
return ProMan::SupportNotCompiledIn; |
| 1272 |
#endif // PLATFORM_USES_REGISTRY |
| 1273 |
} |