Changeset 96572 in vbox for trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp
- Timestamp:
- Sep 1, 2022 8:36:22 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp
r96428 r96572 35 35 #endif 36 36 37 #include <VBox/version.h>38 39 #include <wchar.h>40 #include <stdio.h>41 42 37 #include <msi.h> 43 38 #include <msiquery.h> … … 46 41 #include <iprt/win/windows.h> 47 42 48 #include <assert.h>49 43 #include <shellapi.h> 50 44 #define INITGUID … … 53 47 #include <devguid.h> 54 48 55 #include <iprt/alloca.h>56 #include <iprt/string.h> /* RT_ZERO */57 #include <iprt/path.h> /* RTPATH_MAX, RTPATH_IS_SLASH */58 59 49 #include <iprt/win/objbase.h> 60 50 #include <iprt/win/setupapi.h> 61 51 #include <iprt/win/shlobj.h> 62 52 53 #include <VBox/version.h> 54 55 #include <iprt/assert.h> 56 #include <iprt/alloca.h> 57 #include <iprt/mem.h> 58 #include <iprt/path.h> /* RTPATH_MAX, RTPATH_IS_SLASH */ 59 #include <iprt/string.h> /* RT_ZERO */ 60 #include <iprt/utf16.h> 61 63 62 #include "VBoxCommon.h" 64 65 63 #ifndef VBOX_OSE 66 64 # include "internal/VBoxSerial.h" … … 72 70 *********************************************************************************************************************************/ 73 71 #ifdef DEBUG 74 # define NonStandardAssert(_expr) assert(_expr)72 # define NonStandardAssert(_expr) Assert(_expr) 75 73 #else 76 74 # define NonStandardAssert(_expr) do{ }while(0) … … 88 86 { 89 87 RT_NOREF(hInst, uReason, pReserved); 88 89 #if 0 90 /* 91 * This is a trick for allowing the debugger to be attached, don't know if 92 * there is an official way to do that, but this is a pretty efficient. 93 * 94 * Monitor the debug output in DbgView and be ready to start windbg when 95 * the message below appear. This will happen 3-4 times during install, 96 * and 2-3 times during uninstall. 97 * 98 * Note! The DIFxApp.DLL will automatically trigger breakpoints when a 99 * debugger is attached. Just continue on these. 100 */ 101 if (uReason == DLL_PROCESS_ATTACH) 102 { 103 WCHAR wszMsg[128]; 104 RTUtf16Printf(wszMsg, RT_ELEMENTS(wszMsg), "Waiting for debugger to attach: windbg -g -G -p %u\n", GetCurrentProcessId()); 105 for (unsigned i = 0; i < 128 && !IsDebuggerPresent(); i++) 106 { 107 OutputDebugStringW(wszMsg); 108 Sleep(1001); 109 } 110 Sleep(1002); 111 __debugbreak(); 112 } 113 #endif 114 90 115 return TRUE; 91 116 } … … 94 119 * Format and add message to the MSI log. 95 120 * 96 * UTF-16 strings are formatted using '% s' (lowercase).97 * ANSI strings are formatted using '% S' (uppercase).121 * UTF-16 strings are formatted using '%ls' (lowercase). 122 * ANSI strings are formatted using '%s' (uppercase). 98 123 */ 99 static UINT logStringF(MSIHANDLE hInstall, const wchar_t *pwszFmt, ...)124 static UINT logStringF(MSIHANDLE hInstall, const char *pszFmt, ...) 100 125 { 101 126 PMSIHANDLE hMSI = MsiCreateRecord(2 /* cParms */); … … 104 129 wchar_t wszBuf[RTPATH_MAX + 256]; 105 130 va_list va; 106 va_start(va, p wszFmt);107 ssize_t cwc = _vsnwprintf(wszBuf, RT_ELEMENTS(wszBuf), pwszFmt, va);131 va_start(va, pszFmt); 132 ssize_t cwc = RTUtf16PrintfV(wszBuf, RT_ELEMENTS(wszBuf), pszFmt, va); 108 133 va_end(va); 109 wszBuf[RT_ELEMENTS(wszBuf) - 1] = '\0';110 134 111 135 MsiRecordSetStringW(hMSI, 0, wszBuf); … … 151 175 * Construct a full command line. 152 176 */ 153 size_t const cwcImage = wcslen(pwszImage);154 size_t const cwcArgs = wcslen(pwszArgs);177 size_t const cwcImage = RTUtf16Len(pwszImage); 178 size_t const cwcArgs = RTUtf16Len(pwszArgs); 155 179 156 180 wchar_t *pwszCmdLine = (wchar_t *)alloca((1 + cwcImage + 1 + 1 + cwcArgs + 1) * sizeof(wchar_t)); … … 184 208 0 /*fFlags*/, NULL /*pwszEnv*/, NULL /*pwszCwd*/, &StartupInfo, &ChildInfo)) 185 209 { 186 logStringF(hModule, L"procRun: Info: Started process %u: %s", ChildInfo.dwProcessId, pwszCmdLine);210 logStringF(hModule, "procRun: Info: Started process %u: %ls", ChildInfo.dwProcessId, pwszCmdLine); 187 211 CloseHandle(ChildInfo.hThread); 188 212 DWORD const dwWait = WaitForSingleObject(ChildInfo.hProcess, RT_MS_30SEC); … … 192 216 if (dwExitCode == 0) 193 217 { 194 logStringF(hModule, L"procRun: Info: Process '%s' terminated exit code zero", pwszCmdLine);218 logStringF(hModule, "procRun: Info: Process '%ls' terminated exit code zero", pwszCmdLine); 195 219 rcWin = ERROR_SUCCESS; 196 220 } 197 221 else 198 222 { 199 logStringF(hModule, L"procRun: Process '%s' terminated with non-zero exit code: %u (%#x)",223 logStringF(hModule, "procRun: Process '%ls' terminated with non-zero exit code: %u (%#x)", 200 224 pwszCmdLine, dwExitCode, dwExitCode); 201 225 rcWin = ERROR_GEN_FAILURE; … … 205 229 { 206 230 rcWin = GetLastError(); 207 logStringF(hModule, L"procRun: Process '%s' is probably still running: rcWin=%u dwWait=%u (%#x)",231 logStringF(hModule, "procRun: Process '%ls' is probably still running: rcWin=%u dwWait=%u (%#x)", 208 232 pwszCmdLine, rcWin, dwWait, dwWait); 209 233 } … … 212 236 { 213 237 rcWin = GetLastError(); 214 logStringF(hModule, L"procRun: Creating process '%s' failed: rcWin=%u\n", pwszCmdLine, rcWin);238 logStringF(hModule, "procRun: Creating process '%ls' failed: rcWin=%u\n", pwszCmdLine, rcWin); 215 239 } 216 240 return rcWin; … … 308 332 cwc += RT_ELEMENTS(s_wszPythonExe) - 1; 309 333 wszBuf[cwc] = '\0'; 310 logStringF(hModule, L"getPythonPath: Found: \"%s\"", wszBuf);334 logStringF(hModule, "getPythonPath: Found: \"%ls\"", wszBuf); 311 335 312 336 NonStandardAssert(cwcPythonPath > cwc); … … 316 340 } 317 341 else 318 logStringF(hModule, L"getPythonPath: Warning: Skipping \"%s\": is a directory (%#x)", wszBuf, fAttribs);342 logStringF(hModule, "getPythonPath: Warning: Skipping \"%ls\": is a directory (%#x)", wszBuf, fAttribs); 319 343 } 320 344 else 321 logStringF(hModule, L"getPythonPath: Warning: Skipping \"%s\": Does not exist (%u)", wszBuf, GetLastError());345 logStringF(hModule, "getPythonPath: Warning: Skipping \"%ls\": Does not exist (%u)", wszBuf, GetLastError()); 322 346 } 323 347 } … … 326 350 RegCloseKey(hKeyPythonCore); 327 351 if (rcWinRet != ERROR_SUCCESS) 328 logStringF(hModule, L"getPythonPath: Unable to find python");352 logStringF(hModule, "getPythonPath: Unable to find python"); 329 353 return rcWinRet; 330 354 } … … 374 398 * This is a prerequisite for setting up the VBox API. 375 399 */ 376 logStringF(hModule, L"checkPythonDependencies: Checking for win32api extensions ...");400 logStringF(hModule, "checkPythonDependencies: Checking for win32api extensions ..."); 377 401 378 402 UINT rcWin = procRun(hModule, pwszPythonExe, L"-c \"import win32api\""); 379 403 if (rcWin == ERROR_SUCCESS) 380 logStringF(hModule, L"checkPythonDependencies: win32api found\n");404 logStringF(hModule, "checkPythonDependencies: win32api found\n"); 381 405 else 382 logStringF(hModule, L"checkPythonDependencies: Importing win32api failed with %u (%#x)\n", rcWin, rcWin);406 logStringF(hModule, "checkPythonDependencies: Importing win32api failed with %u (%#x)\n", rcWin, rcWin); 383 407 384 408 return rcWin; … … 402 426 if (rcWin == ERROR_SUCCESS) 403 427 { 404 logStringF(hModule, L"IsPythonInstalled: Python installation found at \"%s\"", wszPythonPath);428 logStringF(hModule, "IsPythonInstalled: Python installation found at \"%ls\"", wszPythonPath); 405 429 VBoxSetMsiProp(hModule, L"VBOX_PYTHON_PATH", wszPythonPath); 406 430 VBoxSetMsiProp(hModule, L"VBOX_PYTHON_INSTALLED", L"1"); … … 408 432 else 409 433 { 410 logStringF(hModule, L"IsPythonInstalled: Error: No suitable Python installation found (%u), skipping installation.", rcWin);411 logStringF(hModule, L"IsPythonInstalled: Python seems not to be installed; please download + install the Python Core package.");434 logStringF(hModule, "IsPythonInstalled: Error: No suitable Python installation found (%u), skipping installation.", rcWin); 435 logStringF(hModule, "IsPythonInstalled: Python seems not to be installed; please download + install the Python Core package."); 412 436 VBoxSetMsiProp(hModule, L"VBOX_PYTHON_INSTALLED", L"0"); 413 437 } … … 434 458 dwErr = checkPythonDependencies(hModule, wszPythonExe); 435 459 if (dwErr == ERROR_SUCCESS) 436 logStringF(hModule, L"ArePythonAPIDepsInstalled: Dependencies look good.");460 logStringF(hModule, "ArePythonAPIDepsInstalled: Dependencies look good."); 437 461 } 438 462 439 463 if (dwErr != ERROR_SUCCESS) 440 logStringF(hModule, L"ArePythonAPIDepsInstalled: Failed with dwErr=%u", dwErr);464 logStringF(hModule, "ArePythonAPIDepsInstalled: Failed with dwErr=%u", dwErr); 441 465 442 466 VBoxSetMsiProp(hModule, L"VBOX_PYTHON_DEPS_INSTALLED", dwErr == ERROR_SUCCESS ? L"1" : L"0"); … … 462 486 { 463 487 HKEY hKeyVS = NULL; 464 LSTATUS dwErr= RegOpenKeyExW(HKEY_LOCAL_MACHINE,465 466 467 if ( dwErr== ERROR_SUCCESS)488 LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 489 L"SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X64", 490 0, KEY_READ, &hKeyVS); 491 if (lrc == ERROR_SUCCESS) 468 492 { 469 493 DWORD dwVal = 0; 470 494 DWORD cbVal = sizeof(dwVal); 471 DWORD dwValueType = REG_DWORD; 472 473 dwErr = RegQueryValueExW(hKeyVS, L"Installed", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal); 474 if (dwErr == ERROR_SUCCESS) 495 DWORD dwValueType = REG_DWORD; /** @todo r=bird: output only parameter, optional, so pointless. */ 496 lrc = RegQueryValueExW(hKeyVS, L"Installed", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal); 497 if (lrc == ERROR_SUCCESS) 475 498 { 476 499 if (dwVal >= 1) 477 500 { 478 DWORD dwM in, dwMaj;479 dwErr= RegQueryValueExW(hKeyVS, L"Major", NULL, &dwValueType, (LPBYTE)&dwMaj, &cbVal);480 if ( dwErr== ERROR_SUCCESS)501 DWORD dwMaj = 0; /** @todo r=bird: It's purdent to initialize values if you don't bother to check the type and size! */ 502 lrc = RegQueryValueExW(hKeyVS, L"Major", NULL, &dwValueType, (LPBYTE)&dwMaj, &cbVal); 503 if (lrc == ERROR_SUCCESS) 481 504 { 482 505 VBoxSetMsiPropDWORD(hModule, L"VBOX_MSCRT_VER_MAJ", dwMaj); 483 506 484 dwErr = RegQueryValueExW(hKeyVS, L"Minor", NULL, &dwValueType, (LPBYTE)&dwMin, &cbVal); 485 if (dwErr == ERROR_SUCCESS) 507 DWORD dwMin = 0; 508 lrc = RegQueryValueExW(hKeyVS, L"Minor", NULL, &dwValueType, (LPBYTE)&dwMin, &cbVal); 509 if (lrc == ERROR_SUCCESS) 486 510 { 487 511 VBoxSetMsiPropDWORD(hModule, L"VBOX_MSCRT_VER_MIN", dwMin); 488 512 489 logStringF(hModule, L"IsMSCRTInstalled: Found v%ld.%ld\n", dwMaj, dwMin);513 logStringF(hModule, "IsMSCRTInstalled: Found v%u.%u\n", dwMaj, dwMin); 490 514 491 515 /* Check for at least 2019. */ … … 494 518 } 495 519 else 496 logStringF(hModule, L"IsMSCRTInstalled: Found, but 'Minor' key not present");520 logStringF(hModule, "IsMSCRTInstalled: Found, but 'Minor' key not present (lrc=%d)", lrc); 497 521 } 498 522 else 499 logStringF(hModule, L"IsMSCRTInstalled: Found, but 'Major' key not present");523 logStringF(hModule, "IsMSCRTInstalled: Found, but 'Major' key not present (lrc=%d)", lrc); 500 524 } 501 525 else 502 526 { 503 logStringF(hModule, L"IsMSCRTInstalled: Found, but not marked as installed");504 dwErr= ERROR_NOT_INSTALLED;527 logStringF(hModule, "IsMSCRTInstalled: Found, but not marked as installed"); 528 lrc = ERROR_NOT_INSTALLED; 505 529 } 506 530 } 507 531 else 508 logStringF(hModule, L"IsMSCRTInstalled: Found, but 'Installed' key not present");509 } 510 511 if ( dwErr!= ERROR_SUCCESS)512 logStringF(hModule, L"IsMSCRTInstalled: Failed with dwErr=%ld", dwErr);532 logStringF(hModule, "IsMSCRTInstalled: Found, but 'Installed' key not present (lrc=%d)", lrc); 533 } 534 535 if (lrc != ERROR_SUCCESS) 536 logStringF(hModule, "IsMSCRTInstalled: Failed with lrc=%ld", lrc); 513 537 514 538 return ERROR_SUCCESS; /* Never return failure. */ … … 533 557 */ 534 558 HKEY hKeyCurVer = NULL; 535 LSTATUS dwErr= RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKeyCurVer);536 if ( dwErr== ERROR_SUCCESS)559 LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKeyCurVer); 560 if (lrc == ERROR_SUCCESS) 537 561 { 538 562 DWORD dwVal = 0; 539 563 DWORD cbVal = sizeof(dwVal); 540 DWORD dwValueType = REG_DWORD; 541 dwErr= RegQueryValueExW(hKeyCurVer, L"CurrentMajorVersionNumber", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal);542 if ( dwErr== ERROR_SUCCESS)543 { 544 logStringF(hModule, L"IsWindows10/CurrentMajorVersionNumber: %ld", dwVal);564 DWORD dwValueType = REG_DWORD; /** @todo r=bird: Again, the type is an optional output parameter. pointless to init or pass it unless you check. */ 565 lrc = RegQueryValueExW(hKeyCurVer, L"CurrentMajorVersionNumber", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal); 566 if (lrc == ERROR_SUCCESS) 567 { 568 logStringF(hModule, "IsWindows10/CurrentMajorVersionNumber: %u", dwVal); 545 569 546 570 VBoxSetMsiProp(hModule, L"VBOX_IS_WINDOWS_10", dwVal >= 10 ? L"1" : L""); 547 571 } 548 572 else 549 logStringF(hModule, L"IsWindows10/RegOpenKeyExW: Error reading CurrentMajorVersionNumber (%ld)", dwErr);573 logStringF(hModule, "IsWindows10/RegOpenKeyExW: Error reading CurrentMajorVersionNumber (%ld)", lrc); 550 574 551 575 RegCloseKey(hKeyCurVer); 552 576 } 553 577 else 554 logStringF(hModule, L"IsWindows10/RegOpenKeyExW: Error opening CurrentVersion key (%ld)", dwErr);578 logStringF(hModule, "IsWindows10/RegOpenKeyExW: Error opening CurrentVersion key (%ld)", lrc); 555 579 556 580 return ERROR_SUCCESS; /* Never return failure. */ … … 569 593 UINT __stdcall InstallPythonAPI(MSIHANDLE hModule) 570 594 { 571 logStringF(hModule, L"InstallPythonAPI: Checking for installed Python environment(s) ...");595 logStringF(hModule, "InstallPythonAPI: Checking for installed Python environment(s) ..."); 572 596 573 597 /** @todo r=bird: Can't we get the VBOX_PYTHON_PATH property here? */ … … 585 609 /* Get the VBox API setup string. */ 586 610 WCHAR wszVBoxSDKPath[RTPATH_MAX]; 587 rcWin = VBoxGetMsiProp(hModule, L"CustomActionData", wszVBoxSDKPath, sizeof(wszVBoxSDKPath));611 rcWin = VBoxGetMsiProp(hModule, L"CustomActionData", wszVBoxSDKPath, RT_ELEMENTS(wszVBoxSDKPath)); 588 612 if (rcWin == ERROR_SUCCESS) 589 613 { … … 594 618 if (SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszVBoxSDKPath)) 595 619 { 596 logStringF(hModule, L"InstallPythonAPI: Invoking vboxapisetup.py in \"%s\" ...", wszVBoxSDKPath);620 logStringF(hModule, "InstallPythonAPI: Invoking vboxapisetup.py in \"%ls\" ...", wszVBoxSDKPath); 597 621 598 622 rcWin = procRun(hModule, wszPythonExe, L"vboxapisetup.py install"); 599 623 if (rcWin == ERROR_SUCCESS) 600 624 { 601 logStringF(hModule, L"InstallPythonAPI: Installation of vboxapisetup.py successful");625 logStringF(hModule, "InstallPythonAPI: Installation of vboxapisetup.py successful"); 602 626 603 627 /* 604 628 * Do some sanity checking if the VBox API works. 605 629 */ 606 logStringF(hModule, L"InstallPythonAPI: Validating VBox API ...");630 logStringF(hModule, "InstallPythonAPI: Validating VBox API ..."); 607 631 608 632 rcWin = procRun(hModule, wszPythonExe, L"-c \"from vboxapi import VirtualBoxManager\""); 609 633 if (rcWin == ERROR_SUCCESS) 610 634 { 611 logStringF(hModule, L"InstallPythonAPI: VBox API looks good.");635 logStringF(hModule, "InstallPythonAPI: VBox API looks good."); 612 636 VBoxSetMsiProp(hModule, L"VBOX_API_INSTALLED", L"1"); 613 637 return ERROR_SUCCESS; … … 615 639 616 640 /* failed */ 617 logStringF(hModule, L"InstallPythonAPI: Validating VBox API failed with %u (%#x)", rcWin, rcWin);641 logStringF(hModule, "InstallPythonAPI: Validating VBox API failed with %u (%#x)", rcWin, rcWin); 618 642 } 619 643 else 620 logStringF(hModule, L"InstallPythonAPI: Calling vboxapisetup.py failed with %u (%#x)", rcWin, rcWin);644 logStringF(hModule, "InstallPythonAPI: Calling vboxapisetup.py failed with %u (%#x)", rcWin, rcWin); 621 645 } 622 646 else 623 logStringF(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH: LastError=%u",647 logStringF(hModule, "InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH: LastError=%u", 624 648 GetLastError()); 625 649 } 626 650 else 627 logStringF(hModule, L"InstallPythonAPI: Could set working directory to \"%s\": LastError=%u",651 logStringF(hModule, "InstallPythonAPI: Could set working directory to \"%ls\": LastError=%u", 628 652 wszVBoxSDKPath, GetLastError()); 629 653 } 630 654 else 631 logStringF(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation directory: rcWin=%u (%#x)", rcWin, rcWin);655 logStringF(hModule, "InstallPythonAPI: Unable to retrieve VBox installation directory: rcWin=%u (%#x)", rcWin, rcWin); 632 656 633 657 VBoxSetMsiProp(hModule, L"VBOX_API_INSTALLED", L"0"); 634 logStringF(hModule, L"InstallPythonAPI: Installation failed");658 logStringF(hModule, "InstallPythonAPI: Installation failed"); 635 659 return ERROR_SUCCESS; /* Do not fail here. */ 636 660 } … … 642 666 { 643 667 LONG rc; 644 WCHAR wszValue[ _MAX_PATH];668 WCHAR wszValue[MAX_PATH]; 645 669 if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL, wszValue, sizeof(wszValue), pwszFileName) > 0) 646 670 { 647 WCHAR wszKey[ _MAX_PATH + 64];648 if ( wcsicmp(L"General", pwszSection) != 0)649 swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%S\\VirtualBox\\Branding\\%s", VBOX_VENDOR_SHORT, pwszSection);671 WCHAR wszKey[MAX_PATH + 64]; 672 if (RTUtf16ICmpAscii(pwszSection, "General") != 0) 673 RTUtf16Printf(wszKey, RT_ELEMENTS(wszKey), "SOFTWARE\\%s\\VirtualBox\\Branding\\%ls", VBOX_VENDOR_SHORT, pwszSection); 650 674 else 651 swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%S\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);675 RTUtf16Printf(wszKey, RT_ELEMENTS(wszKey), "SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT); 652 676 653 677 HKEY hkBranding = NULL; … … 660 684 REG_SZ, 661 685 (BYTE *)wszValue, 662 (DWORD) wcslen(wszValue));686 (DWORD)RTUtf16Len(wszValue)); 663 687 if (rc != ERROR_SUCCESS) 664 logStringF(hModule, L"InstallBranding: Could not write value %s! Error %d", pwszValue, rc);688 logStringF(hModule, "InstallBranding: Could not write value %s! Error %d", pwszValue, rc); 665 689 RegCloseKey(hkBranding); 666 690 } … … 676 700 static UINT CopyDir(MSIHANDLE hModule, const WCHAR *pwszzDstDir, const WCHAR *pwszzSrcDir) 677 701 { 678 NonStandardAssert(pwszzDstDir[ wcslen(pwszzDstDir) + 1] == '\0');679 NonStandardAssert(pwszzSrcDir[ wcslen(pwszzSrcDir) + 1] == '\0');702 NonStandardAssert(pwszzDstDir[RTUtf16Len(pwszzDstDir) + 1] == '\0'); 703 NonStandardAssert(pwszzSrcDir[RTUtf16Len(pwszzSrcDir) + 1] == '\0'); 680 704 681 705 SHFILEOPSTRUCTW s = {0}; … … 689 713 | FOF_NOERRORUI; 690 714 691 logStringF(hModule, L"CopyDir: pwszzDstDir=%s, pwszzSrcDir=%s", pwszzDstDir, pwszzSrcDir);715 logStringF(hModule, "CopyDir: pwszzDstDir=%ls, pwszzSrcDir=%ls", pwszzDstDir, pwszzSrcDir); 692 716 int r = SHFileOperationW(&s); 693 717 if (r == 0) 694 718 return ERROR_SUCCESS; 695 logStringF(hModule, L"CopyDir: Copy operation returned status %#x", r);719 logStringF(hModule, "CopyDir: Copy operation returned status %#x", r); 696 720 return ERROR_GEN_FAILURE; 697 721 } … … 702 726 static UINT RemoveDir(MSIHANDLE hModule, const WCHAR *pwszzDstDir) 703 727 { 704 NonStandardAssert(pwszzDstDir[ wcslen(pwszzDstDir) + 1] == '\0');728 NonStandardAssert(pwszzDstDir[RTUtf16Len(pwszzDstDir) + 1] == '\0'); 705 729 706 730 SHFILEOPSTRUCTW s = {0}; … … 713 737 | FOF_NOERRORUI; 714 738 715 logStringF(hModule, L"RemoveDir: pwszzDstDir=%s", pwszzDstDir);739 logStringF(hModule, "RemoveDir: pwszzDstDir=%ls", pwszzDstDir); 716 740 int r = SHFileOperationW(&s); 717 741 if (r == 0) 718 742 return ERROR_SUCCESS; 719 logStringF(hModule, L"RemoveDir: Remove operation returned status %#x", r);743 logStringF(hModule, "RemoveDir: Remove operation returned status %#x", r); 720 744 return ERROR_GEN_FAILURE; 721 745 } … … 726 750 static UINT RenameDir(MSIHANDLE hModule, const WCHAR *pwszzDstDir, const WCHAR *pwszzSrcDir) 727 751 { 728 NonStandardAssert(pwszzDstDir[ wcslen(pwszzDstDir) + 1] == '\0');729 NonStandardAssert(pwszzSrcDir[ wcslen(pwszzSrcDir) + 1] == '\0');752 NonStandardAssert(pwszzDstDir[RTUtf16Len(pwszzDstDir) + 1] == '\0'); 753 NonStandardAssert(pwszzSrcDir[RTUtf16Len(pwszzSrcDir) + 1] == '\0'); 730 754 731 755 SHFILEOPSTRUCTW s = {0}; … … 739 763 | FOF_NOERRORUI; 740 764 741 logStringF(hModule, L"RenameDir: pwszzDstDir=%s, pwszzSrcDir=%s", pwszzDstDir, pwszzSrcDir);765 logStringF(hModule, "RenameDir: pwszzDstDir=%ls, pwszzSrcDir=%ls", pwszzDstDir, pwszzSrcDir); 742 766 int r = SHFileOperationW(&s); 743 767 if (r == 0) 744 768 return ERROR_SUCCESS; 745 logStringF(hModule, L"RenameDir: Rename operation returned status %#x", r);769 logStringF(hModule, "RenameDir: Rename operation returned status %#x", r); 746 770 return ERROR_GEN_FAILURE; 747 771 } … … 750 774 static UINT AppendToPath(wchar_t *pwszPath, size_t cwcPath, wchar_t *pwszAppend, bool fDoubleTerm = false) 751 775 { 752 size_t cwcCurPath = wcslen(pwszPath);776 size_t cwcCurPath = RTUtf16Len(pwszPath); 753 777 size_t cwcSlash = cwcCurPath > 1 && RTPATH_IS_SLASH(pwszPath[cwcCurPath - 1]) ? 0 : 1; 754 778 while (RTPATH_IS_SLASH(*pwszAppend)) 755 779 pwszAppend++; 756 size_t cwcAppend = wcslen(pwszAppend);780 size_t cwcAppend = RTUtf16Len(pwszAppend); 757 781 if (cwcCurPath + cwcCurPath + cwcAppend + fDoubleTerm < cwcPath) 758 782 { … … 770 794 static UINT JoinPaths(wchar_t *pwszPath, size_t cwcPath, wchar_t *pwszPath1, wchar_t *pwszAppend, bool fDoubleTerm = false) 771 795 { 772 size_t cwcCurPath = wcslen(pwszPath1);796 size_t cwcCurPath = RTUtf16Len(pwszPath1); 773 797 if (cwcCurPath < cwcPath) 774 798 { … … 781 805 UINT __stdcall UninstallBranding(MSIHANDLE hModule) 782 806 { 783 logStringF(hModule, L"UninstallBranding: Handling branding file ...");807 logStringF(hModule, "UninstallBranding: Handling branding file ..."); 784 808 785 809 WCHAR wszPath[RTPATH_MAX]; 786 UINT rc = VBoxGetMsiProp(hModule, L"CustomActionData", wszPath, sizeof(wszPath));810 UINT rc = VBoxGetMsiProp(hModule, L"CustomActionData", wszPath, RT_ELEMENTS(wszPath)); 787 811 if (rc == ERROR_SUCCESS) 788 812 { 789 size_t const cwcPath = wcslen(wszPath);813 size_t const cwcPath = RTUtf16Len(wszPath); 790 814 rc = AppendToPath(wszPath, RTPATH_MAX, L"custom", true /*fDoubleTerm*/); 791 815 if (rc == ERROR_SUCCESS) … … 799 823 } 800 824 801 logStringF(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);825 logStringF(hModule, "UninstallBranding: Handling done. (rc=%u (ignored))", rc); 802 826 return ERROR_SUCCESS; /* Do not fail here. */ 803 827 } … … 805 829 UINT __stdcall InstallBranding(MSIHANDLE hModule) 806 830 { 807 logStringF(hModule, L"InstallBranding: Handling branding file ...");831 logStringF(hModule, "InstallBranding: Handling branding file ..."); 808 832 809 833 /* … … 842 866 } 843 867 844 logStringF(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);868 logStringF(hModule, "InstallBranding: Handling done. (rc=%u (ignored))", rc); 845 869 return ERROR_SUCCESS; /* Do not fail here. */ 846 870 } … … 863 887 static UINT _uninstallNetLwf(MSIHANDLE hModule); 864 888 865 static VOID vboxDrvLoggerCallback(VBOXDRVCFG_LOG_SEVERITY enmSeverity, char *pszMsg, void *pvContext)889 static VOID vboxDrvLoggerCallback(VBOXDRVCFG_LOG_SEVERITY_T enmSeverity, char *pszMsg, void *pvContext) 866 890 { 867 891 RT_NOREF1(pvContext); … … 873 897 case VBOXDRVCFG_LOG_SEVERITY_REL: 874 898 if (g_hCurrentModule) 875 logStringF(g_hCurrentModule, L"%S", pszMsg);899 logStringF(g_hCurrentModule, "%s", pszMsg); 876 900 break; 877 901 default: … … 883 907 { 884 908 if (g_hCurrentModule) 885 logStringF(g_hCurrentModule, L"%S", pszString);909 logStringF(g_hCurrentModule, "%s", pszString); 886 910 } 887 911 … … 920 944 case NETCFG_S_REBOOT: 921 945 { 922 logStringF(hModule, L"Reboot required, setting REBOOT property to \"force\"");946 logStringF(hModule, "Reboot required, setting REBOOT property to \"force\""); 923 947 HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force"); 924 948 if (hr2 != ERROR_SUCCESS) 925 logStringF(hModule, L"Failed to set REBOOT property, error = %#x", hr2);949 logStringF(hModule, "Failed to set REBOOT property, error = %#x", hr2); 926 950 uRet = ERROR_SUCCESS; /* Never fail here. */ 927 951 break; … … 929 953 930 954 default: 931 logStringF(hModule, L"Converting unhandled HRESULT (%#x) to ERROR_GEN_FAILURE", hr);955 logStringF(hModule, "Converting unhandled HRESULT (%#x) to ERROR_GEN_FAILURE", hr); 932 956 uRet = ERROR_GEN_FAILURE; 933 957 } … … 943 967 if (uErr != ERROR_SUCCESS) 944 968 { 945 logStringF(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = %#x", uErr);969 logStringF(hModule, "createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = %#x", uErr); 946 970 MsiCloseHandle(hRecord); 947 971 hRecord = NULL; … … 949 973 } 950 974 else 951 logStringF(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record");975 logStringF(hModule, "createNetCfgLockedMsgRecord: Failed to create a record"); 952 976 953 977 return hRecord; … … 968 992 { 969 993 if (FAILED(hr)) 970 logStringF(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = %#x", hr);994 logStringF(hModule, "doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = %#x", hr); 971 995 uErr = errorConvertFromHResult(hModule, hr); 972 996 break; … … 977 1001 if (!lpszLockedBy) 978 1002 { 979 logStringF(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking");1003 logStringF(hModule, "doNetCfgInit: lpszLockedBy == NULL, breaking"); 980 1004 break; 981 1005 } … … 988 1012 * rather than waiting for a longer period of time before displaying it */ 989 1013 if ( cRetries < VBOX_NETCFG_MAX_RETRIES 990 && !wcscmp(lpszLockedBy, L"6to4svc.dll"))1014 && RTUtf16ICmpAscii(lpszLockedBy, "6to4svc.dll") == 0) 991 1015 { 992 1016 cRetries++; 993 logStringF(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);1017 logStringF(hModule, "doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES); 994 1018 MsgResult = IDRETRY; 995 1019 } … … 1001 1025 if (!hMsg) 1002 1026 { 1003 logStringF(hModule, L"doNetCfgInit: Failed to create a message record, breaking");1027 logStringF(hModule, "doNetCfgInit: Failed to create a message record, breaking"); 1004 1028 CoTaskMemFree(lpszLockedBy); 1005 1029 break; … … 1011 1035 if (rTmp != ERROR_SUCCESS) 1012 1036 { 1013 logStringF(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = #%x", rTmp);1037 logStringF(hModule, "doNetCfgInit: MsiRecordSetStringW failed, error = #%x", rTmp); 1014 1038 CoTaskMemFree(lpszLockedBy); 1015 1039 break; … … 1018 1042 MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg); 1019 1043 NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL); 1020 logStringF(hModule, L"doNetCfgInit: MsiProcessMessage returned (%#x)", MsgResult);1044 logStringF(hModule, "doNetCfgInit: MsiProcessMessage returned (%#x)", MsgResult); 1021 1045 } 1022 1046 CoTaskMemFree(lpszLockedBy); … … 1029 1053 } 1030 1054 1031 static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize) 1032 { 1033 DWORD dwBuf = dwSize - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH)); 1034 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &dwBuf); 1055 static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, DWORD cwcPtInf, 1056 OUT LPWSTR pwszMpInf, DWORD cwcMpInf) 1057 { 1058 DWORD cwcEffBuf = cwcPtInf - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH)) / sizeof(WCHAR); 1059 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &cwcEffBuf); 1035 1060 if ( uErr == ERROR_SUCCESS 1036 && dwBuf) 1037 { 1038 wcscpy(pwszMpInf, pwszPtInf); 1039 1040 wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH)); 1041 logStringF(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf); 1042 1043 wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH)); 1044 logStringF(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf); 1061 && cwcEffBuf > 0) 1062 { 1063 int vrc = RTUtf16Copy(pwszMpInf, cwcMpInf, pwszPtInf); 1064 AssertRCReturn(vrc, ERROR_BUFFER_OVERFLOW); 1065 1066 vrc = RTUtf16Cat(pwszPtInf, cwcPtInf, NETFLT_PT_INF_REL_PATH); 1067 AssertRCReturn(vrc, ERROR_BUFFER_OVERFLOW); 1068 logStringF(hModule, "vboxNetFltQueryInfArray: INF 1: %ls", pwszPtInf); 1069 1070 vrc = RTUtf16Cat(pwszMpInf, cwcMpInf, NETFLT_MP_INF_REL_PATH); 1071 AssertRCReturn(vrc, ERROR_BUFFER_OVERFLOW); 1072 logStringF(hModule, "vboxNetFltQueryInfArray: INF 2: %ls", pwszMpInf); 1045 1073 } 1046 1074 else if (uErr != ERROR_SUCCESS) 1047 logStringF(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr);1075 logStringF(hModule, "vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr); 1048 1076 else 1049 1077 { 1050 logStringF(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");1078 logStringF(hModule, "vboxNetFltQueryInfArray: Empty installation directory"); 1051 1079 uErr = ERROR_GEN_FAILURE; 1052 1080 } … … 1069 1097 __try 1070 1098 { 1071 logStringF(hModule, L"Uninstalling NetFlt");1099 logStringF(hModule, "Uninstalling NetFlt"); 1072 1100 1073 1101 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 1076 1104 HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg); 1077 1105 if (hr != S_OK) 1078 logStringF(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);1106 logStringF(hModule, "UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr); 1079 1107 1080 1108 uErr = errorConvertFromHResult(hModule, hr); … … 1082 1110 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 1083 1111 1084 logStringF(hModule, L"Uninstalling NetFlt done, error = %#x", uErr);1112 logStringF(hModule, "Uninstalling NetFlt done, error = %#x", uErr); 1085 1113 } 1086 1114 else 1087 logStringF(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = %#x", uErr);1115 logStringF(hModule, "UninstallNetFlt: doNetCfgInit failed, error = %#x", uErr); 1088 1116 } 1089 1117 __finally … … 1121 1149 { 1122 1150 1123 logStringF(hModule, L"InstallNetFlt: Installing NetFlt");1151 logStringF(hModule, "InstallNetFlt: Installing NetFlt"); 1124 1152 1125 1153 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 1128 1156 WCHAR wszPtInf[MAX_PATH]; 1129 1157 WCHAR wszMpInf[MAX_PATH]; 1130 uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, wszMpInf, sizeof(wszMpInf));1158 uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, RT_ELEMENTS(wszPtInf), wszMpInf, RT_ELEMENTS(wszMpInf)); 1131 1159 if (uErr == ERROR_SUCCESS) 1132 1160 { … … 1134 1162 HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs)); 1135 1163 if (FAILED(hr)) 1136 logStringF(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = %#x", hr);1164 logStringF(hModule, "InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = %#x", hr); 1137 1165 1138 1166 uErr = errorConvertFromHResult(hModule, hr); 1139 1167 } 1140 1168 else 1141 logStringF(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = %#x", uErr);1169 logStringF(hModule, "InstallNetFlt: vboxNetFltQueryInfArray failed, error = %#x", uErr); 1142 1170 1143 1171 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 1144 1172 1145 logStringF(hModule, L"InstallNetFlt: Done");1173 logStringF(hModule, "InstallNetFlt: Done"); 1146 1174 } 1147 1175 else 1148 logStringF(hModule, L"InstallNetFlt: doNetCfgInit failed, error = %#x", uErr);1176 logStringF(hModule, "InstallNetFlt: doNetCfgInit failed, error = %#x", uErr); 1149 1177 } 1150 1178 __finally … … 1182 1210 __try 1183 1211 { 1184 logStringF(hModule, L"Uninstalling NetLwf");1212 logStringF(hModule, "Uninstalling NetLwf"); 1185 1213 1186 1214 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 1189 1217 HRESULT hr = VBoxNetCfgWinNetLwfUninstall(pNetCfg); 1190 1218 if (hr != S_OK) 1191 logStringF(hModule, L"UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);1219 logStringF(hModule, "UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr); 1192 1220 1193 1221 uErr = errorConvertFromHResult(hModule, hr); … … 1195 1223 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 1196 1224 1197 logStringF(hModule, L"Uninstalling NetLwf done, error = %#x", uErr);1225 logStringF(hModule, "Uninstalling NetLwf done, error = %#x", uErr); 1198 1226 } 1199 1227 else 1200 logStringF(hModule, L"UninstallNetLwf: doNetCfgInit failed, error = %#x", uErr);1228 logStringF(hModule, "UninstallNetLwf: doNetCfgInit failed, error = %#x", uErr); 1201 1229 } 1202 1230 __finally … … 1234 1262 { 1235 1263 1236 logStringF(hModule, L"InstallNetLwf: Installing NetLwf");1264 logStringF(hModule, "InstallNetLwf: Installing NetLwf"); 1237 1265 1238 1266 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 1252 1280 } 1253 1281 1254 wcscat(wszInf, NETLWF_INF_NAME); 1282 int vrc = RTUtf16Cat(wszInf, RT_ELEMENTS(wszInf), NETLWF_INF_NAME); 1283 AssertRC(vrc); 1255 1284 1256 1285 HRESULT hr = VBoxNetCfgWinNetLwfInstall(pNetCfg, wszInf); 1257 1286 if (FAILED(hr)) 1258 logStringF(hModule, L"InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = %#x", hr);1287 logStringF(hModule, "InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = %#x", hr); 1259 1288 1260 1289 uErr = errorConvertFromHResult(hModule, hr); … … 1262 1291 else 1263 1292 { 1264 logStringF(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");1293 logStringF(hModule, "vboxNetFltQueryInfArray: Empty installation directory"); 1265 1294 uErr = ERROR_GEN_FAILURE; 1266 1295 } 1267 1296 } 1268 1297 else 1269 logStringF(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr);1298 logStringF(hModule, "vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr); 1270 1299 1271 1300 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 1272 1301 1273 logStringF(hModule, L"InstallNetLwf: Done");1302 logStringF(hModule, "InstallNetLwf: Done"); 1274 1303 } 1275 1304 else 1276 logStringF(hModule, L"InstallNetLwf: doNetCfgInit failed, error = %#x", uErr);1305 logStringF(hModule, "InstallNetLwf: doNetCfgInit failed, error = %#x", uErr); 1277 1306 } 1278 1307 __finally … … 1336 1365 ULONG cbName = sizeof(ConnectoinName); 1337 1366 1338 HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName 1367 HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(DevName, ConnectoinName, &cbName); 1339 1368 NonStandardAssert(hr == S_OK); 1340 1369 if (SUCCEEDED(hr)) … … 1363 1392 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); 1364 1393 1365 logStringF(hModule, L"CreateHostOnlyInterface: Creating host-only interface");1394 logStringF(hModule, "CreateHostOnlyInterface: Creating host-only interface"); 1366 1395 1367 1396 HRESULT hr = E_FAIL; 1368 1397 GUID guid; 1369 1398 WCHAR wszMpInf[MAX_PATH]; 1370 DWORD c chMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)wcslen(pwszInfName) - 1 - 1;1399 DWORD cwcMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)RTUtf16Len(pwszInfName) - 1 - 1; 1371 1400 LPCWSTR pwszInfPath = NULL; 1372 1401 bool fIsFile = false; 1373 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &c chMpInf);1402 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cwcMpInf); 1374 1403 if (uErr == ERROR_SUCCESS) 1375 1404 { 1376 if (cchMpInf) 1377 { 1378 logStringF(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf); 1379 if (wszMpInf[cchMpInf - 1] != L'\\') 1380 { 1381 wszMpInf[cchMpInf++] = L'\\'; 1382 wszMpInf[cchMpInf] = L'\0'; 1383 } 1384 1385 wcscat(wszMpInf, pwszInfName); 1405 if (cwcMpInf) 1406 { 1407 logStringF(hModule, "CreateHostOnlyInterface: NetAdpDir property = %ls", wszMpInf); 1408 if (wszMpInf[cwcMpInf - 1] != L'\\') 1409 { 1410 wszMpInf[cwcMpInf++] = L'\\'; 1411 wszMpInf[cwcMpInf] = L'\0'; 1412 } 1413 1414 int vrc = RTUtf16Cat(wszMpInf, RT_ELEMENTS(wszMpInf), pwszInfName); 1415 AssertRC(vrc); 1416 1386 1417 pwszInfPath = wszMpInf; 1387 1418 fIsFile = true; 1388 1419 1389 logStringF(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath);1420 logStringF(hModule, "CreateHostOnlyInterface: Resulting INF path = %ls", pwszInfPath); 1390 1421 } 1391 1422 else 1392 logStringF(hModule, L"CreateHostOnlyInterface: VBox installation path is empty");1423 logStringF(hModule, "CreateHostOnlyInterface: VBox installation path is empty"); 1393 1424 } 1394 1425 else 1395 logStringF(hModule, L"CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = %#x", uErr);1426 logStringF(hModule, "CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = %#x", uErr); 1396 1427 1397 1428 /* Make sure the inf file is installed. */ 1398 1429 if (pwszInfPath != NULL && fIsFile) 1399 1430 { 1400 logStringF(hModule, L"CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath);1431 logStringF(hModule, "CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%ls)", pwszInfPath); 1401 1432 hr = VBoxDrvCfgInfInstall(pwszInfPath); 1402 logStringF(hModule, L"CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns %#x", hr);1433 logStringF(hModule, "CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns %#x", hr); 1403 1434 if (FAILED(hr)) 1404 logStringF(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = %#x", hr);1435 logStringF(hModule, "CreateHostOnlyInterface: Failed to install INF file, error = %#x", hr); 1405 1436 } 1406 1437 … … 1414 1445 if (fRebootRequired) 1415 1446 { 1416 logStringF(hModule, L"CreateHostOnlyInterface: Reboot required for update, setting REBOOT property to force");1447 logStringF(hModule, "CreateHostOnlyInterface: Reboot required for update, setting REBOOT property to force"); 1417 1448 HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force"); 1418 1449 if (hr2 != ERROR_SUCCESS) 1419 logStringF(hModule, L"CreateHostOnlyInterface: Failed to set REBOOT property for update, error = %#x", hr2);1450 logStringF(hModule, "CreateHostOnlyInterface: Failed to set REBOOT property for update, error = %#x", hr2); 1420 1451 } 1421 1452 } … … 1423 1454 { 1424 1455 //in fail case call CreateHostOnlyInterface 1425 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr);1426 logStringF(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");1456 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr); 1457 logStringF(hModule, "CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface"); 1427 1458 #ifdef VBOXNETCFG_DELAYEDRENAME 1428 1459 BSTR devId; … … 1431 1462 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, NULL, NULL); 1432 1463 #endif /* !VBOXNETCFG_DELAYEDRENAME */ 1433 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns %#x", hr);1464 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns %#x", hr); 1434 1465 if (SUCCEEDED(hr)) 1435 1466 { 1436 1467 ULONG ip = inet_addr("192.168.56.1"); 1437 1468 ULONG mask = inet_addr("255.255.255.0"); 1438 logStringF(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");1469 logStringF(hModule, "CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig"); 1439 1470 hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask); 1440 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns %#x", hr);1471 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns %#x", hr); 1441 1472 if (FAILED(hr)) 1442 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = %#x", hr);1473 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = %#x", hr); 1443 1474 #ifdef VBOXNETCFG_DELAYEDRENAME 1444 1475 hr = VBoxNetCfgWinRenameHostOnlyConnection(&guid, devId, NULL); 1445 1476 if (FAILED(hr)) 1446 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRenameHostOnlyConnection failed, error = %#x", hr);1477 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinRenameHostOnlyConnection failed, error = %#x", hr); 1447 1478 SysFreeString(devId); 1448 1479 #endif /* VBOXNETCFG_DELAYEDRENAME */ 1449 1480 } 1450 1481 else 1451 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = %#x", hr);1482 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = %#x", hr); 1452 1483 } 1453 1484 } 1454 1485 1455 1486 if (SUCCEEDED(hr)) 1456 logStringF(hModule, L"CreateHostOnlyInterface: Creating host-only interface done");1487 logStringF(hModule, "CreateHostOnlyInterface: Creating host-only interface done"); 1457 1488 1458 1489 /* Restore original setup mode. */ 1459 logStringF(hModule, L"CreateHostOnlyInterface: Almost done...");1490 logStringF(hModule, "CreateHostOnlyInterface: Almost done..."); 1460 1491 if (fSetupModeInteractive) 1461 1492 SetupSetNonInteractiveMode(fSetupModeInteractive); … … 1465 1496 #endif /* VBOX_WITH_NETFLT */ 1466 1497 1467 logStringF(hModule, L"CreateHostOnlyInterface: Returns success (ignoring all failures)");1498 logStringF(hModule, "CreateHostOnlyInterface: Returns success (ignoring all failures)"); 1468 1499 /* Never fail the install even if we did not succeed. */ 1469 1500 return ERROR_SUCCESS; … … 1477 1508 UINT __stdcall Ndis6CreateHostOnlyInterface(MSIHANDLE hModule) 1478 1509 { 1510 #if 0 /* Trick for allowing the debugger to be attached. */ 1511 for (unsigned i = 0; i < 128 && !IsDebuggerPresent(); i++) 1512 { 1513 logStringF(hModule, "Waiting for debugger to attach: windbg -p %u", GetCurrentProcessId()); 1514 Sleep(1001); 1515 } 1516 Sleep(1002); 1517 __debugbreak(); 1518 #endif 1479 1519 return _createHostOnlyInterface(hModule, NETADP_ID, L"VBoxNetAdp6.inf"); 1480 1520 } … … 1485 1525 netCfgLoggerEnable(hModule); 1486 1526 1487 logStringF(hModule, L"RemoveHostOnlyInterfaces: Removing all host-only interfaces");1527 logStringF(hModule, "RemoveHostOnlyInterfaces: Removing all host-only interfaces"); 1488 1528 1489 1529 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); … … 1494 1534 hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", pwszId, SUOI_FORCEDELETE/* could be SUOI_FORCEDELETE */); 1495 1535 if (FAILED(hr)) 1496 logStringF(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files");1536 logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files"); 1497 1537 else 1498 logStringF(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully");1538 logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstalled successfully"); 1499 1539 } 1500 1540 else 1501 logStringF(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = %#x", hr);1541 logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = %#x", hr); 1502 1542 1503 1543 /* Restore original setup mode. */ … … 1522 1562 netCfgLoggerEnable(hModule); 1523 1563 1524 logStringF(hModule, L"StopHostOnlyInterfaces: Stopping all host-only interfaces");1564 logStringF(hModule, "StopHostOnlyInterfaces: Stopping all host-only interfaces"); 1525 1565 1526 1566 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); … … 1528 1568 HRESULT hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(pwszId, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE); 1529 1569 if (SUCCEEDED(hr)) 1530 logStringF(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = %#x", hr);1570 logStringF(hModule, "StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = %#x", hr); 1531 1571 else 1532 logStringF(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces failed, hr = %#x", hr);1572 logStringF(hModule, "StopHostOnlyInterfaces: Disabling host interfaces failed, hr = %#x", hr); 1533 1573 1534 1574 /* Restore original setup mode. */ … … 1553 1593 netCfgLoggerEnable(hModule); 1554 1594 1555 logStringF(hModule, L"UpdateHostOnlyInterfaces: Updating all host-only interfaces");1595 logStringF(hModule, "UpdateHostOnlyInterfaces: Updating all host-only interfaces"); 1556 1596 1557 1597 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); 1558 1598 1559 1599 WCHAR wszMpInf[MAX_PATH]; 1560 DWORD c chMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)wcslen(pwszInfName) - 1 - 1;1600 DWORD cwcMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)RTUtf16Len(pwszInfName) - 1 - 1; 1561 1601 LPCWSTR pwszInfPath = NULL; 1562 1602 bool fIsFile = false; 1563 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &c chMpInf);1603 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cwcMpInf); 1564 1604 if (uErr == ERROR_SUCCESS) 1565 1605 { 1566 if (cchMpInf) 1567 { 1568 logStringF(hModule, L"UpdateHostOnlyInterfaces: NetAdpDir property = %s", wszMpInf); 1569 if (wszMpInf[cchMpInf - 1] != L'\\') 1570 { 1571 wszMpInf[cchMpInf++] = L'\\'; 1572 wszMpInf[cchMpInf] = L'\0'; 1573 } 1574 1575 wcscat(wszMpInf, pwszInfName); 1606 if (cwcMpInf) 1607 { 1608 logStringF(hModule, "UpdateHostOnlyInterfaces: NetAdpDir property = %ls", wszMpInf); 1609 if (wszMpInf[cwcMpInf - 1] != L'\\') 1610 { 1611 wszMpInf[cwcMpInf++] = L'\\'; 1612 wszMpInf[cwcMpInf] = L'\0'; 1613 } 1614 1615 int vrc = RTUtf16Cat(wszMpInf, RT_ELEMENTS(wszMpInf), pwszInfName); 1616 AssertRC(vrc); 1576 1617 pwszInfPath = wszMpInf; 1577 1618 fIsFile = true; 1578 1619 1579 logStringF(hModule, L"UpdateHostOnlyInterfaces: Resulting INF path = %s", pwszInfPath);1620 logStringF(hModule, "UpdateHostOnlyInterfaces: Resulting INF path = %ls", pwszInfPath); 1580 1621 1581 1622 DWORD attrFile = GetFileAttributesW(pwszInfPath); … … 1583 1624 { 1584 1625 DWORD dwErr = GetLastError(); 1585 logStringF(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" not found, dwErr=%ld", pwszInfPath, dwErr);1626 logStringF(hModule, "UpdateHostOnlyInterfaces: File \"%ls\" not found, dwErr=%ld", pwszInfPath, dwErr); 1586 1627 } 1587 1628 else 1588 1629 { 1589 logStringF(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" exists", pwszInfPath);1630 logStringF(hModule, "UpdateHostOnlyInterfaces: File \"%ls\" exists", pwszInfPath); 1590 1631 1591 1632 BOOL fRebootRequired = FALSE; … … 1595 1636 if (fRebootRequired) 1596 1637 { 1597 logStringF(hModule, L"UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");1638 logStringF(hModule, "UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force"); 1598 1639 HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force"); 1599 1640 if (hr2 != ERROR_SUCCESS) 1600 logStringF(hModule, L"UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = %#x", hr2);1641 logStringF(hModule, "UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = %#x", hr2); 1601 1642 } 1602 1643 } 1603 1644 else 1604 logStringF(hModule, L"UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr);1645 logStringF(hModule, "UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr); 1605 1646 } 1606 1647 } 1607 1648 else 1608 logStringF(hModule, L"UpdateHostOnlyInterfaces: VBox installation path is empty");1649 logStringF(hModule, "UpdateHostOnlyInterfaces: VBox installation path is empty"); 1609 1650 } 1610 1651 else 1611 logStringF(hModule, L"UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = %#x", uErr);1652 logStringF(hModule, "UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = %#x", uErr); 1612 1653 1613 1654 /* Restore original setup mode. */ … … 1644 1685 __try 1645 1686 { 1646 logStringF(hModule, L"Uninstalling NetAdp");1687 logStringF(hModule, "Uninstalling NetAdp"); 1647 1688 1648 1689 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 1651 1692 HRESULT hr = VBoxNetCfgWinNetAdpUninstall(pNetCfg, pwszId); 1652 1693 if (hr != S_OK) 1653 logStringF(hModule, L"UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);1694 logStringF(hModule, "UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr); 1654 1695 1655 1696 uErr = errorConvertFromHResult(hModule, hr); … … 1657 1698 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 1658 1699 1659 logStringF(hModule, L"Uninstalling NetAdp done, error = %#x", uErr);1700 logStringF(hModule, "Uninstalling NetAdp done, error = %#x", uErr); 1660 1701 } 1661 1702 else 1662 logStringF(hModule, L"UninstallNetAdp: doNetCfgInit failed, error = %#x", uErr);1703 logStringF(hModule, "UninstallNetAdp: doNetCfgInit failed, error = %#x", uErr); 1663 1704 } 1664 1705 __finally … … 1724 1765 lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen); 1725 1766 1726 if ( ! wcscmp(wszNetCfgInstanceId, pwszGUID)1727 && ! wcscmp(wszNetProductName, L"VirtualBox TAP Adapter")1728 && ( (! wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */1729 || (! wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */1730 || (! wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */1767 if ( !RTUtf16Cmp(wszNetCfgInstanceId, pwszGUID) 1768 && !RTUtf16Cmp(wszNetProductName, L"VirtualBox TAP Adapter") 1769 && ( (!RTUtf16Cmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */ 1770 || (!RTUtf16Cmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */ 1771 || (!RTUtf16Cmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */ 1731 1772 ) 1732 1773 ) … … 1746 1787 } 1747 1788 1748 /** @todo r=andy BUGBUG WTF! Why do we a) set the rc to 0 (success), and b) need this macro at all!? */ 1789 /** @todo r=andy BUGBUG WTF! Why do we a) set the rc to 0 (success), and b) need this macro at all!? 1790 * 1791 * @todo r=bird: Because it's returning a bool, not int? The return code is 1792 * ignored anyway, both internally in removeNetworkInterface and in it's caller. 1793 * There is similar code in VBoxNetCfg.cpp, which is probably where it was copied from. */ 1749 1794 #define SetErrBreak(args) \ 1750 1795 if (1) { \ … … 1769 1814 { 1770 1815 WCHAR wszRegLocation[256]; 1771 swprintf_s(wszRegLocation, RT_ELEMENTS(wszRegLocation),1772 L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", pwszGUID);1773 LONG l Status= RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);1774 if (l Status!= ERROR_SUCCESS || !hkeyNetwork)1775 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)![1]",1776 wszRegLocation ));1777 1778 l Status= RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);1779 if (l Status!= ERROR_SUCCESS || !hkeyConnection)1780 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)![2]",1781 wszRegLocation ));1816 RTUtf16Printf(wszRegLocation, RT_ELEMENTS(wszRegLocation), 1817 "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%ls", pwszGUID); 1818 LONG lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork); 1819 if (lrc != ERROR_SUCCESS || !hkeyNetwork) 1820 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%ls)! (lrc=%d) [1]", 1821 wszRegLocation, lrc)); 1822 1823 lrc = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection); 1824 if (lrc != ERROR_SUCCESS || !hkeyConnection) 1825 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%ls)! (lrc=%d) [2]", 1826 wszRegLocation, lrc)); 1782 1827 1783 1828 DWORD len = sizeof(wszPnPInstanceId); 1784 1829 DWORD dwKeyType; 1785 l Status= RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);1786 if (l Status != ERROR_SUCCESS || (dwKeyType != REG_SZ))1787 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)![3]",1788 wszRegLocation ));1830 lrc = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len); 1831 if (lrc != ERROR_SUCCESS || dwKeyType != REG_SZ) 1832 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%ls)! (lrc=%d) [3]", 1833 wszRegLocation, lrc)); 1789 1834 } 1790 1835 while (0); … … 1805 1850 do /* break-loop */ 1806 1851 { 1852 /* initialize the structure size */ 1853 SP_DEVINFO_DATA DeviceInfoData = { sizeof(DeviceInfoData) }; 1854 1855 /* copy the net class GUID */ 1807 1856 GUID netGuid; 1808 SP_DEVINFO_DATA DeviceInfoData;1809 DWORD index = 0;1810 DWORD size = 0;1811 1812 /* initialize the structure size */1813 DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);1814 1815 /* copy the net class GUID */1816 1857 memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET)); 1817 1858 … … 1820 1861 if (hDeviceInfo == INVALID_HANDLE_VALUE) 1821 1862 { 1822 logStringF(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError()); 1823 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!")); 1824 } 1825 1863 logStringF(hModule, "VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError()); 1864 SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!")); 1865 } 1866 1867 /* enumerate the driver info list */ 1826 1868 BOOL fFoundDevice = FALSE; 1827 1828 /* enumerate the driver info list */ 1829 while (TRUE) 1830 { 1831 WCHAR *pwszDeviceHwid; 1832 1869 for (DWORD index = 0;; index++) 1870 { 1833 1871 fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData); 1834 1872 if (!fResult) … … 1836 1874 if (GetLastError() == ERROR_NO_MORE_ITEMS) 1837 1875 break; 1838 else 1839 { 1840 index++; 1841 continue; 1842 } 1876 continue; 1843 1877 } 1844 1878 1845 1879 /* try to get the hardware ID registry property */ 1880 WCHAR *pwszDeviceHwid; 1881 DWORD size = 0; 1846 1882 fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo, 1847 1883 &DeviceInfoData, … … 1854 1890 { 1855 1891 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) 1892 continue; 1893 1894 pwszDeviceHwid = (WCHAR *)RTMemAllocZ(size); 1895 if (!pwszDeviceHwid) 1896 continue; 1897 1898 fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo, 1899 &DeviceInfoData, 1900 SPDRP_HARDWAREID, 1901 NULL, 1902 (PBYTE)pwszDeviceHwid, 1903 size, 1904 &size); 1905 if (!fResult) 1856 1906 { 1857 index++;1907 RTMemFree(pwszDeviceHwid); 1858 1908 continue; 1859 }1860 1861 pwszDeviceHwid = (WCHAR *)malloc(size);1862 if (pwszDeviceHwid)1863 {1864 fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,1865 &DeviceInfoData,1866 SPDRP_HARDWAREID,1867 NULL,1868 (PBYTE)pwszDeviceHwid,1869 size,1870 NULL);1871 if (!fResult)1872 {1873 free(pwszDeviceHwid);1874 pwszDeviceHwid = NULL;1875 index++;1876 continue;1877 }1878 1909 } 1879 1910 } … … 1881 1912 { 1882 1913 /* something is wrong. This shouldn't have worked with a NULL buffer */ 1883 index++;1884 1914 continue; 1885 1915 } 1886 1916 1887 1917 for (WCHAR *t = pwszDeviceHwid; 1888 t &&*t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];1889 t += wcslen(t) + 1)1918 *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)]; 1919 t += RTUtf16Len(t) + 1) 1890 1920 { 1891 if ( !_wcsicmp(L"vboxtap", t))1921 if (RTUtf16ICmpAscii(t, "vboxtap") == 0) 1892 1922 { 1893 /* get the device instance ID */ 1894 WCHAR wszDevID[MAX_DEVICE_ID_LEN]; 1895 if (CM_Get_Device_IDW(DeviceInfoData.DevInst, 1896 wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS) 1897 { 1898 /* compare to what we determined before */ 1899 if (!wcscmp(wszDevID, wszPnPInstanceId)) 1900 { 1901 fFoundDevice = TRUE; 1902 break; 1903 } 1904 } 1923 /* get the device instance ID */ 1924 WCHAR wszDevID[MAX_DEVICE_ID_LEN]; 1925 if (CM_Get_Device_IDW(DeviceInfoData.DevInst, wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS) 1926 { 1927 /* compare to what we determined before */ 1928 if (RTUtf16Cmp(wszDevID, wszPnPInstanceId) == 0) 1929 { 1930 fFoundDevice = TRUE; 1931 break; 1932 } 1933 } 1905 1934 } 1906 1935 } 1907 1936 1908 if (pwszDeviceHwid) 1909 { 1910 free(pwszDeviceHwid); 1911 pwszDeviceHwid = NULL; 1912 } 1937 RTMemFree(pwszDeviceHwid); 1913 1938 1914 1939 if (fFoundDevice) 1915 1940 break; 1916 1917 index++;1918 1941 } 1919 1942 … … 1923 1946 if (!fResult) 1924 1947 { 1925 logStringF(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());1926 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));1948 logStringF(hModule, "VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError()); 1949 SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!")); 1927 1950 } 1928 1951 … … 1930 1953 if (!fResult) 1931 1954 { 1932 logStringF(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());1933 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));1955 logStringF(hModule, "VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError()); 1956 SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!")); 1934 1957 } 1935 1958 } 1936 1959 else 1937 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network device not found!"));1960 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network device not found!")); 1938 1961 } while (0); 1939 1962 … … 1950 1973 HKEY hCtrlNet; 1951 1974 1952 L ONG lStatus= RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);1953 if (l Status== ERROR_SUCCESS)1954 { 1955 logStringF(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");1975 LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet); 1976 if (lrc == ERROR_SUCCESS) 1977 { 1978 logStringF(hModule, "VBox HostInterfaces: Enumerating interfaces ..."); 1956 1979 for (int i = 0; ; ++i) 1957 1980 { 1958 1981 WCHAR wszNetworkGUID[256] = { 0 }; 1959 1982 DWORD dwLen = (DWORD)sizeof(wszNetworkGUID); 1960 l Status= RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);1961 if (l Status!= ERROR_SUCCESS)1962 { 1963 switch (l Status)1983 lrc = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL); 1984 if (lrc != ERROR_SUCCESS) 1985 { 1986 switch (lrc) 1964 1987 { 1965 1988 case ERROR_NO_MORE_ITEMS: 1966 logStringF(hModule, L"VBox HostInterfaces: No interfaces found.");1989 logStringF(hModule, "VBox HostInterfaces: No interfaces found."); 1967 1990 break; 1968 1991 default: 1969 logStringF(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);1992 logStringF(hModule, "VBox HostInterfaces: Enumeration failed: %ld", lrc); 1970 1993 break; 1971 1994 } … … 1975 1998 if (isTAPDevice(wszNetworkGUID)) 1976 1999 { 1977 logStringF(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);2000 logStringF(hModule, "VBox HostInterfaces: Removing interface \"%ls\" ...", wszNetworkGUID); 1978 2001 removeNetworkInterface(hModule, wszNetworkGUID); 1979 l Status= RegDeleteKeyW(hCtrlNet, wszNetworkGUID);2002 lrc = RegDeleteKeyW(hCtrlNet, wszNetworkGUID); 1980 2003 } 1981 2004 } 1982 2005 RegCloseKey(hCtrlNet); 1983 logStringF(hModule, L"VBox HostInterfaces: Removing interfaces done.");2006 logStringF(hModule, "VBox HostInterfaces: Removing interfaces done."); 1984 2007 } 1985 2008 return ERROR_SUCCESS; … … 2016 2039 QueryServiceStatus(hService, &Status); 2017 2040 if (Status.dwCurrentState == SERVICE_STOPPED) 2018 logStringF(hModule, L"VBoxDrv: The service old service was already stopped");2041 logStringF(hModule, "VBoxDrv: The service old service was already stopped"); 2019 2042 else 2020 2043 { 2021 logStringF(hModule, L"VBoxDrv: Stopping the service (state %u)", Status.dwCurrentState);2044 logStringF(hModule, "VBoxDrv: Stopping the service (state %u)", Status.dwCurrentState); 2022 2045 if (ControlService(hService, SERVICE_CONTROL_STOP, &Status)) 2023 2046 { … … 2031 2054 2032 2055 if (Status.dwCurrentState == SERVICE_STOPPED) 2033 logStringF(hModule, L"VBoxDrv: Stopped service");2056 logStringF(hModule, "VBoxDrv: Stopped service"); 2034 2057 else 2035 logStringF(hModule, L"VBoxDrv: Failed to stop the service, status: %u", Status.dwCurrentState);2058 logStringF(hModule, "VBoxDrv: Failed to stop the service, status: %u", Status.dwCurrentState); 2036 2059 } 2037 2060 else … … 2040 2063 if ( Status.dwCurrentState == SERVICE_STOP_PENDING 2041 2064 && dwErr == ERROR_SERVICE_CANNOT_ACCEPT_CTRL) 2042 logStringF(hModule, L"VBoxDrv: Failed to stop the service: stop pending, not accepting control messages");2065 logStringF(hModule, "VBoxDrv: Failed to stop the service: stop pending, not accepting control messages"); 2043 2066 else 2044 logStringF(hModule, L"VBoxDrv: Failed to stop the service: dwErr=%u status=%u", dwErr, Status.dwCurrentState);2067 logStringF(hModule, "VBoxDrv: Failed to stop the service: dwErr=%u status=%u", dwErr, Status.dwCurrentState); 2045 2068 } 2046 2069 } … … 2050 2073 */ 2051 2074 if (DeleteService(hService)) 2052 logStringF(hModule, L"VBoxDrv: Successfully delete service");2075 logStringF(hModule, "VBoxDrv: Successfully delete service"); 2053 2076 else 2054 logStringF(hModule, L"VBoxDrv: Failed to delete the service: %u", GetLastError());2077 logStringF(hModule, "VBoxDrv: Failed to delete the service: %u", GetLastError()); 2055 2078 2056 2079 CloseServiceHandle(hService); … … 2060 2083 DWORD const dwErr = GetLastError(); 2061 2084 if (dwErr == ERROR_SERVICE_DOES_NOT_EXIST) 2062 logStringF(hModule, L"VBoxDrv: Nothing to do, the old service does not exist");2085 logStringF(hModule, "VBoxDrv: Nothing to do, the old service does not exist"); 2063 2086 else 2064 logStringF(hModule, L"VBoxDrv: Failed to open the service: %u", dwErr);2087 logStringF(hModule, "VBoxDrv: Failed to open the service: %u", dwErr); 2065 2088 } 2066 2089 … … 2068 2091 } 2069 2092 else 2070 logStringF(hModule, L"VBoxDrv: Failed to open service manager (%u).", GetLastError());2093 logStringF(hModule, "VBoxDrv: Failed to open service manager (%u).", GetLastError()); 2071 2094 2072 2095 return ERROR_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.