Changeset 86775 in vbox for trunk/src/VBox/Installer/win
- Timestamp:
- Oct 30, 2020 6:24:36 PM (4 years ago)
- Location:
- trunk/src/VBox/Installer/win/InstallHelper
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/win/InstallHelper/Makefile.kmk
r82968 r86775 20 20 21 21 DLLS += VBoxInstallHelper 22 VBoxInstallHelper_TEMPLATE = VB OXR3STATIC22 VBoxInstallHelper_TEMPLATE = VBoxR3Static 23 23 VBoxInstallHelper_DEFS = _WIN32_WINNT=0x0501 _UNICODE UNICODE 24 24 VBoxInstallHelper_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV) … … 36 36 endif 37 37 VBoxInstallHelper_SDKS = ReorderCompilerIncs $(VBOX_WINPSDK) $(VBOX_WINDDK) 38 VBoxInstallHelper_LIBS 38 VBoxInstallHelper_LIBS += $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Msi.lib 39 39 ifdef VBOX_WITH_NETFLT 40 40 VBoxInstallHelper_LIBS += \ -
trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp
r82968 r86775 21 21 *********************************************************************************************************************************/ 22 22 #include <iprt/win/windows.h> 23 23 24 #include <tchar.h> 24 25 #include <stdio.h> … … 26 27 #include <msi.h> 27 28 #include <msiquery.h> 29 30 #include <iprt/utf16.h> 28 31 29 32 … … 40 43 #endif 41 44 42 UINT VBoxGet Property(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue, DWORD a_dwSize)45 UINT VBoxGetMsiProp(MSIHANDLE hMsi, WCHAR *pwszName, WCHAR *pwszValue, DWORD dwSize) 43 46 { 44 47 DWORD dwBuffer = 0; 45 UINT uiRet = MsiGetPropertyW( a_hModule, a_pwszName, L"", &dwBuffer);48 UINT uiRet = MsiGetPropertyW(hMsi, pwszName, L"", &dwBuffer); 46 49 if (uiRet == ERROR_MORE_DATA) 47 50 { 48 51 ++dwBuffer; /* On output does not include terminating null, so add 1. */ 49 52 50 if (dwBuffer > a_dwSize)53 if (dwBuffer > dwSize) 51 54 return ERROR_MORE_DATA; 52 55 53 ZeroMemory( a_pwszValue, a_dwSize);54 uiRet = MsiGetPropertyW( a_hModule, a_pwszName, a_pwszValue, &dwBuffer);56 ZeroMemory(pwszValue, dwSize); 57 uiRet = MsiGetPropertyW(hMsi, pwszName, pwszValue, &dwBuffer); 55 58 } 56 59 return uiRet; 57 60 } 58 61 59 UINT VBoxSetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue) 62 /** 63 * Retrieves a MSI property (in UTF-8). 64 * 65 * Convenience function for VBoxGetMsiProp(). 66 * 67 * @returns VBox status code. 68 * @param hMsi MSI handle to use. 69 * @param pcszName Name of property to retrieve. 70 * @param ppszValue Where to store the allocated value on success. 71 * Must be free'd using RTStrFree() by the caller. 72 */ 73 int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue) 60 74 { 61 return MsiSetPropertyW(a_hModule, a_pwszName, a_pwszValue); 75 PRTUTF16 pwszName; 76 int rc = RTStrToUtf16(pcszName, &pwszName); 77 if (RT_SUCCESS(rc)) 78 { 79 WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */ 80 if (VBoxGetMsiProp(hMsi, pwszName, wszValue, sizeof(wszValue)) == ERROR_SUCCESS) 81 { 82 rc = RTUtf16ToUtf8(wszValue, ppszValue); 83 } 84 else 85 rc = VERR_NOT_FOUND; 86 87 RTUtf16Free(pwszName); 88 } 89 90 return rc; 62 91 } 63 92 93 UINT VBoxSetMsiProp(MSIHANDLE hMsi, WCHAR *pwszName, WCHAR *pwszValue) 94 { 95 return MsiSetPropertyW(hMsi, pwszName, pwszValue); 96 } 97 -
trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.h
r82968 r86775 26 26 #endif 27 27 28 UINT VBoxGetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue, DWORD a_dwSize); 29 UINT VBoxSetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue); 28 UINT VBoxGetMsiProp(MSIHANDLE hMsi, WCHAR *pwszName, WCHAR *pwszValue, DWORD dwSize); 29 int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue); 30 UINT VBoxSetMsiProp(MSIHANDLE hMsi, WCHAR *pwszName, WCHAR *pwszValue); 30 31 31 32 #endif /* !VBOX_INCLUDED_SRC_InstallHelper_VBoxCommon_h */ -
trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp
r85121 r86775 27 27 #include <VBox/version.h> 28 28 29 #include <iprt/win/windows.h>30 29 #include <wchar.h> 31 30 #include <stdio.h> … … 36 35 #define _WIN32_DCOM 37 36 #include <iprt/win/windows.h> 37 38 38 #include <assert.h> 39 39 #include <shellapi.h> 40 40 #define INITGUID 41 41 #include <guiddef.h> 42 #include <cfgmgr32.h> 42 43 #include <devguid.h> 44 45 #include <iprt/env.h> 46 #include <iprt/err.h> 47 #include <iprt/initterm.h> 48 #include <iprt/path.h> 49 #include <iprt/process.h> 50 #include <iprt/utf16.h> 51 43 52 #include <iprt/win/objbase.h> 44 53 #include <iprt/win/setupapi.h> 45 54 #include <iprt/win/shlobj.h> 46 #include <cfgmgr32.h>47 55 48 56 #include "VBoxCommon.h" … … 66 74 67 75 68 BOOL APIENTRY DllMain(HANDLE hModule, DWORD uReason, LPVOID lpReserved) 69 { 70 RT_NOREF3(hModule, uReason, lpReserved); 76 BOOL WINAPI DllMain(HANDLE hInst, ULONG uReason, LPVOID pReserved) 77 { 78 RT_NOREF(hInst, pReserved); 79 80 switch (uReason) 81 { 82 case DLL_PROCESS_ATTACH: 83 RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); 84 break; 85 86 case DLL_PROCESS_DETACH: 87 break; 88 89 case DLL_THREAD_ATTACH: 90 break; 91 92 case DLL_THREAD_DETACH: 93 break; 94 95 default: 96 break; 97 } 98 71 99 return TRUE; 72 100 } 73 101 74 75 static void logString(MSIHANDLE hInstall, LPCSTR szString, ...) 76 { 77 PMSIHANDLE newHandle = MsiCreateRecord(2); 78 79 char szBuffer[1024]; 102 static int logStringF(MSIHANDLE hInstall, const char *pcszFmt, ...) 103 { 104 PMSIHANDLE hMSI = MsiCreateRecord(2 /* cParms */); 105 if (!hMSI) 106 return VERR_ACCESS_DENIED; 107 108 RTUTF16 wszBuf[_1K] = { 0 }; 109 80 110 va_list va; 81 va_start(va, szString);82 _vsnprintf(szBuffer, sizeof(szBuffer), szString, va);111 va_start(va, pcszFmt); 112 ssize_t cwch = RTUtf16PrintfV(wszBuf, RT_ELEMENTS(wszBuf), pcszFmt, va); 83 113 va_end(va); 84 114 85 MsiRecordSetStringA(newHandle, 0, szBuffer); 86 MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle); 87 MsiCloseHandle(newHandle); 88 89 #if 0/*def DEBUG - wrong? What does '%s' expect, wchar or char? */ 90 _tprintf(_T("Debug: %s\n"), szBuffer); 91 #endif 92 } 93 94 static void logStringW(MSIHANDLE hInstall, LPCWSTR pwszString, ...) 95 { 96 PMSIHANDLE newHandle = MsiCreateRecord(2); 97 98 WCHAR szBuffer[1024]; 99 va_list va; 100 va_start(va, pwszString); 101 _vsnwprintf(szBuffer, RT_ELEMENTS(szBuffer), pwszString, va); 102 va_end(va); 103 104 MsiRecordSetStringW(newHandle, 0, szBuffer); 105 MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle); 106 MsiCloseHandle(newHandle); 115 if (cwch <= 0) 116 return VERR_BUFFER_OVERFLOW; 117 118 MsiRecordSetStringW(hMSI, 0, wszBuf); 119 MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), hMSI); 120 MsiCloseHandle(hMSI); 121 122 return VINF_SUCCESS; 107 123 } 108 124 … … 110 126 { 111 127 #ifndef VBOX_OSE 112 /*BOOL bRet =*/ serialCheckNeeded(hModule);128 /*BOOL fRet =*/ serialCheckNeeded(hModule); 113 129 #else 114 RT_NOREF 1(hModule);130 RT_NOREF(hModule); 115 131 #endif 116 132 return ERROR_SUCCESS; … … 122 138 /*BOOL bRet =*/ serialIsValid(hModule); 123 139 #else 124 RT_NOREF 1(hModule);140 RT_NOREF(hModule); 125 141 #endif 126 142 return ERROR_SUCCESS; 127 143 } 128 144 129 DWORD Exec(MSIHANDLE hModule, 130 const WCHAR *pwszAppName, WCHAR *pwszCmdLine, const WCHAR *pwszWorkDir, 131 DWORD *pdwExitCode) 132 { 133 STARTUPINFOW si; 134 PROCESS_INFORMATION pi; 135 DWORD rc = ERROR_SUCCESS; 136 137 ZeroMemory(&si, sizeof(si)); 138 si.dwFlags = STARTF_USESHOWWINDOW; 139 #ifdef UNICODE 140 si.dwFlags |= CREATE_UNICODE_ENVIRONMENT; 145 /** 146 * Tries to retrieve the Python installation path on the system. 147 * 148 * @returns VBox status code. 149 * @param hModule Windows installer module handle. 150 * @param hKeyRoot Registry root key to use, e.g. HKEY_LOCAL_MACHINE. 151 * @param ppszPath Where to store the allocated Python path on success. 152 * Must be free'd by the caller using RTStrFree(). 153 */ 154 static int getPythonPath(MSIHANDLE hModule, HKEY hKeyRoot, char **ppszPath) 155 { 156 HKEY hkPythonCore = NULL; 157 LSTATUS dwErr = RegOpenKeyExW(hKeyRoot, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore); 158 if (dwErr != ERROR_SUCCESS) 159 return RTErrConvertFromWin32(dwErr); 160 161 char *pszPythonPath = NULL; 162 163 RTUTF16 wszKey [RTPATH_MAX] = { 0 }; 164 RTUTF16 wszKey2[RTPATH_MAX] = { 0 }; 165 RTUTF16 wszVal [RTPATH_MAX] = { 0 }; 166 167 int rc = VINF_SUCCESS; 168 169 /* Note: The loop ASSUMES that later found versions are higher, e.g. newer Python versions. 170 * For now we always go by the newest version. */ 171 for (int i = 0;; ++i) 172 { 173 DWORD dwKey = sizeof(wszKey); 174 DWORD dwKeyType = REG_SZ; 175 176 dwErr = RegEnumKeyExW(hkPythonCore, i, wszKey, &dwKey, NULL, NULL, NULL, NULL); 177 if (dwErr != ERROR_SUCCESS || dwKey <= 0) 178 break; 179 AssertBreakStmt(dwKey <= sizeof(wszKey), VERR_BUFFER_OVERFLOW); 180 181 if (RTUtf16Printf(wszKey2, sizeof(wszKey2), "%ls\\InstallPath", wszKey) <= 0) 182 { 183 rc = VERR_BUFFER_OVERFLOW; 184 break; 185 } 186 187 dwKey = sizeof(wszKey2); /* Re-initialize length. */ 188 189 HKEY hkPythonInstPath = NULL; 190 dwErr = RegOpenKeyExW(hkPythonCore, wszKey2, 0, KEY_READ, &hkPythonInstPath); 191 if (dwErr != ERROR_SUCCESS) 192 continue; 193 194 dwErr = RegQueryValueExW(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)wszVal, &dwKey); 195 if (dwErr == ERROR_SUCCESS) 196 logStringF(hModule, "InstallPythonAPI: Path \"%ls\" found.", wszVal); 197 198 if (pszPythonPath) /* Free former path, if any. */ 199 { 200 RTStrFree(pszPythonPath); 201 pszPythonPath = NULL; 202 } 203 204 rc = RTUtf16ToUtf8(wszVal, &pszPythonPath); 205 AssertRCBreak(rc); 206 207 if (!RTPathExists(pszPythonPath)) 208 { 209 logStringF(hModule, "InstallPythonAPI: Warning: Path \"%s\" does not exist, skipping.", wszVal); 210 rc = VERR_PATH_NOT_FOUND; 211 } 212 213 RegCloseKey(hkPythonInstPath); 214 } 215 216 RegCloseKey(hkPythonCore); 217 218 if (RT_FAILURE(rc)) 219 { 220 RTStrFree(pszPythonPath); 221 } 222 else 223 *ppszPath = pszPythonPath; 224 225 return rc; 226 } 227 228 /** 229 * Waits for a started process to terminate. 230 * 231 * @returns VBox status code. 232 * @param Process Handle of process to wait for. 233 * @param msTimeout Timeout (in ms) to wait for process to terminate. 234 * @param pProcSts Pointer to process status on return. 235 */ 236 int procWait(RTPROCESS Process, RTMSINTERVAL msTimeout, PRTPROCSTATUS pProcSts) 237 { 238 uint64_t tsStartMs = RTTimeMilliTS(); 239 240 while (RTTimeMilliTS() - tsStartMs <= msTimeout) 241 { 242 int rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, pProcSts); 243 if (rc == VERR_PROCESS_RUNNING) 244 continue; 245 else if (RT_FAILURE(rc)) 246 return rc; 247 248 if ( pProcSts->iStatus != 0 249 || pProcSts->enmReason != RTPROCEXITREASON_NORMAL) 250 { 251 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */ 252 } 253 254 return VINF_SUCCESS; 255 } 256 257 return VERR_TIMEOUT; 258 } 259 260 /** 261 * Checks for a valid Python installation on the system. 262 * 263 * Called from the MSI installer as custom action. 264 * 265 * @returns Always ERROR_SUCCESS. 266 * Sets public property VBOX_PYTHON_INSTALLED to "0" (false) or "1" (success). 267 * Sets public property VBOX_PYTHON_PATH to the Python installation path (if found). 268 * 269 * @param hModule Windows installer module handle. 270 */ 271 UINT __stdcall IsPythonInstalled(MSIHANDLE hModule) 272 { 273 char *pszPythonPath; 274 int rc = getPythonPath(hModule, HKEY_LOCAL_MACHINE, &pszPythonPath); 275 if (RT_FAILURE(rc)) 276 rc = getPythonPath(hModule, HKEY_CURRENT_USER, &pszPythonPath); 277 278 if (RT_SUCCESS(rc)) 279 { 280 logStringF(hModule, "IsPythonInstalled: Python installation found at \"%s\"", pszPythonPath); 281 282 PRTUTF16 pwszPythonPath; 283 rc = RTStrToUtf16(pszPythonPath, &pwszPythonPath); 284 if (RT_SUCCESS(rc)) 285 { 286 VBoxSetMsiProp(hModule, L"VBOX_PYTHON_PATH", pwszPythonPath); 287 288 RTUtf16Free(pwszPythonPath); 289 } 290 else 291 logStringF(hModule, "IsPythonInstalled: Error: Unable to convert path, rc=%Rrc", rc); 292 293 RTStrFree(pszPythonPath); 294 } 295 else 296 logStringF(hModule, "IsPythonInstalled: Error: No suitable Python installation found (%Rrc), skipping installation.", rc); 297 298 VBoxSetMsiProp(hModule, L"VBOX_PYTHON_INSTALLED", RT_SUCCESS(rc) ? L"1" : L"0"); 299 300 return ERROR_SUCCESS; /* Never return failure. */ 301 } 302 303 /** 304 * Installs and compiles the VBox Python bindings. 305 * 306 * Called from the MSI installer as custom action. 307 * 308 * @returns Always ERROR_SUCCESS. 309 * Sets public property VBOX_API_INSTALLED to "0" (false) or "1" (success). 310 * 311 * @param hModule Windows installer module handle. 312 */ 313 UINT __stdcall InstallPythonAPI(MSIHANDLE hModule) 314 { 315 logStringF(hModule, "InstallPythonAPI: Checking for installed Python environment(s) ..."); 316 317 char *pszPythonPath; 318 int rc = getPythonPath(hModule, HKEY_LOCAL_MACHINE, &pszPythonPath); 319 if (RT_FAILURE(rc)) 320 rc = getPythonPath(hModule, HKEY_CURRENT_USER, &pszPythonPath); 321 322 if (RT_FAILURE(rc)) 323 { 324 VBoxSetMsiProp(hModule, L"VBOX_API_INSTALLED", L"0"); 325 326 logStringF(hModule, "InstallPythonAPI: Python seems not to be installed (%Rrc); please download + install the Python Core package.", rc); 327 return ERROR_SUCCESS; 328 } 329 330 logStringF(hModule, "InstallPythonAPI: Python installation found at \"%s\".", pszPythonPath); 331 logStringF(hModule, "InstallPythonAPI: Checking for win32api extensions ..."); 332 333 uint32_t fProcess = 0; 334 #ifndef DEBUG 335 uint32_t fProcess |= RTPROC_FLAGS_HIDDEN; 141 336 #endif 142 si.wShowWindow = SW_HIDE; /* For debugging: SW_SHOW; */ 143 si.cb = sizeof(si); 144 ZeroMemory(&pi, sizeof(pi)); 145 146 logStringW(hModule, L"Executing command line: %s %s (Working Dir: %s)", 147 pwszAppName, pwszCmdLine, pwszWorkDir == NULL ? L"Current" : pwszWorkDir); 148 149 SetLastError(0); 150 if (!CreateProcessW(pwszAppName, /* Module name. */ 151 pwszCmdLine, /* Command line. */ 152 NULL, /* Process handle not inheritable. */ 153 NULL, /* Thread handle not inheritable. */ 154 FALSE, /* Set handle inheritance to FALSE .*/ 155 0, /* No creation flags. */ 156 NULL, /* Use parent's environment block. */ 157 pwszWorkDir, /* Use parent's starting directory. */ 158 &si, /* Pointer to STARTUPINFO structure. */ 159 &pi)) /* Pointer to PROCESS_INFORMATION structure. */ 160 { 161 rc = GetLastError(); 162 logStringW(hModule, L"Executing command line: CreateProcess() failed! Error: %ld", rc); 163 return rc; 164 } 165 166 /* Wait until child process exits. */ 167 if (WAIT_FAILED == WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */)) 168 { 169 rc = GetLastError(); 170 logStringW(hModule, L"Executing command line: WaitForSingleObject() failed! Error: %u", rc); 171 } 172 else 173 { 174 if (!GetExitCodeProcess(pi.hProcess, pdwExitCode)) 175 { 176 rc = GetLastError(); 177 logStringW(hModule, L"Executing command line: GetExitCodeProcess() failed! Error: %u", rc); 178 } 179 } 180 181 /* Close process and thread handles. */ 182 CloseHandle(pi.hProcess); 183 CloseHandle(pi.hThread); 184 185 logStringW(hModule, L"Executing command returned: %u (exit code %u)", rc, *pdwExitCode); 186 return rc; 187 } 188 189 UINT __stdcall InstallPythonAPI(MSIHANDLE hModule) 190 { 191 logStringW(hModule, L"InstallPythonAPI: Checking for installed Python environment ..."); 192 193 HKEY hkPythonCore = NULL; 194 BOOL bFound = FALSE; 195 LONG rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore); 196 if (rc != ERROR_SUCCESS) 197 { 198 logStringW(hModule, L"InstallPythonAPI: Python seems not to be installed."); 199 return ERROR_SUCCESS; 200 } 201 202 WCHAR wszPath[MAX_PATH] = { 0 }; 203 WCHAR wszVal[MAX_PATH] = { 0 }; 204 205 for (int i = 0;; ++i) 206 { 207 WCHAR wszRoot[MAX_PATH] = { 0 }; 208 DWORD dwLen = sizeof(wszPath); 209 DWORD dwKeyType = REG_SZ; 210 211 rc = RegEnumKeyExW(hkPythonCore, i, wszRoot, &dwLen, NULL, NULL, NULL, NULL); 212 if (rc != ERROR_SUCCESS || dwLen <= 0) 213 break; 214 215 swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\InstallPath", wszRoot); 216 dwLen = sizeof(wszVal); 217 218 HKEY hkPythonInstPath = NULL; 219 rc = RegOpenKeyExW(hkPythonCore, wszPath, 0, KEY_READ, &hkPythonInstPath); 220 if (rc != ERROR_SUCCESS) 221 continue; 222 223 rc = RegQueryValueExW(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)wszVal, &dwLen); 224 if (rc == ERROR_SUCCESS) 225 logStringW(hModule, L"InstallPythonAPI: Path \"%s\" detected.", wszVal); 226 227 RegCloseKey(hkPythonInstPath); 228 } 229 RegCloseKey(hkPythonCore); 230 231 /* Python path found? */ 232 WCHAR wszExec[MAX_PATH] = { 0 }; 233 WCHAR wszCmdLine[MAX_PATH] = { 0 }; 234 DWORD dwExitCode = 0; 235 if (wcslen(wszVal) > 0) 236 { 237 /* Cool, check for installed Win32 extensions. */ 238 logStringW(hModule, L"InstallPythonAPI: Python installed. Checking for Win32 extensions ..."); 239 swprintf_s(wszExec, RT_ELEMENTS(wszExec), L"%s\\python.exe", wszVal); 240 swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe -c \"import win32api\"", wszVal); 241 242 DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, NULL, &dwExitCode); 243 if ( (ERROR_SUCCESS == dwRetExec) 244 && ( 0 == dwExitCode)) 245 { 246 /* Did we get the correct error level (=0)? */ 247 logStringW(hModule, L"InstallPythonAPI: Win32 extensions installed."); 248 bFound = TRUE; 249 } 250 else 251 logStringW(hModule, L"InstallPythonAPI: Win32 extensions not found."); 252 } 253 254 BOOL bInstalled = FALSE; 255 if (bFound) /* Is Python and all required stuff installed? */ 256 { 257 /* Get the VBoxAPI setup string. */ 258 WCHAR wszPathTargetDir[MAX_PATH] = {0}; 259 VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir)); 260 if (wcslen(wszPathTargetDir)) 261 { 262 /* Set final path. */ 263 swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s", wszPathTargetDir); 264 265 /* Install our API module. */ 266 swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe vboxapisetup.py install", wszVal); 267 268 /* Set required environment variables. */ 269 if (!SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszPathTargetDir)) 270 logStringW(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!"); 271 else 272 { 273 DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, wszPath, &dwExitCode); 274 if ( (ERROR_SUCCESS == dwRetExec) 275 && ( 0 == dwExitCode)) 337 338 char szPythonPath[RTPATH_MAX] = { 0 }; 339 rc = RTPathAppend(szPythonPath, sizeof(szPythonPath), pszPythonPath); 340 if (RT_SUCCESS(rc)) 341 { 342 rc = RTPathAppend(szPythonPath, sizeof(szPythonPath), "python.exe"); 343 if (RT_SUCCESS(rc)) 344 { 345 /* 346 * Check if importing the win32api module works. 347 * This is a prerequisite for setting up the VBox API. 348 */ 349 RTPROCESS Process; 350 RT_ZERO(Process); 351 const char *papszArgs[4] = { szPythonPath, "-c", "import win32api", NULL}; 352 rc = RTProcCreate(szPythonPath, papszArgs, RTENV_DEFAULT, fProcess, &Process); 353 if (RT_SUCCESS(rc)) 354 { 355 RTPROCSTATUS ProcSts; 356 rc = procWait(Process, RT_MS_30SEC, &ProcSts); 357 if (RT_FAILURE(rc)) 358 logStringF(hModule, "InstallPythonAPI: Importing the win32api failed with %d (exit reason: %d)\n", 359 ProcSts.iStatus, ProcSts.enmReason); 360 } 361 } 362 } 363 364 /* 365 * Set up the VBox API. 366 */ 367 if (RT_SUCCESS(rc)) 368 { 369 /* Get the VBox API setup string. */ 370 char *pszVBoxSDKPath; 371 rc = VBoxGetMsiPropUtf8(hModule, "CustomActionData", &pszVBoxSDKPath); 372 if (RT_SUCCESS(rc)) 373 { 374 /* Make sure our current working directory is the VBox installation path. */ 375 rc = RTPathSetCurrent(pszVBoxSDKPath); 376 if (RT_SUCCESS(rc)) 377 { 378 /* Set required environment variables. */ 379 rc = RTEnvSet("VBOX_INSTALL_PATH", pszVBoxSDKPath); 380 if (RT_SUCCESS(rc)) 276 381 { 277 /* All done! */ 278 logStringW(hModule, L"InstallPythonAPI: VBoxAPI for Python successfully installed."); 279 bInstalled = TRUE; 382 RTPROCSTATUS ProcSts; 383 RT_ZERO(ProcSts); 384 385 logStringF(hModule, "InstallPythonAPI: Invoking vboxapisetup.py in \"%s\" ...\n", pszVBoxSDKPath); 386 387 RTPROCESS Process; 388 RT_ZERO(Process); 389 const char *papszArgs[4] = { szPythonPath, "vboxapisetup.py", "install", NULL}; 390 rc = RTProcCreate(szPythonPath, papszArgs, RTENV_DEFAULT, fProcess, &Process); 391 if (RT_SUCCESS(rc)) 392 { 393 rc = procWait(Process, RT_MS_30SEC, &ProcSts); 394 if (RT_SUCCESS(rc)) 395 logStringF(hModule, "InstallPythonAPI: Installation of vboxapisetup.py successful\n"); 396 } 397 398 if (RT_FAILURE(rc)) 399 logStringF(hModule, "InstallPythonAPI: Calling vboxapisetup.py failed with %Rrc (process status: %d, exit reason: %d)\n", 400 rc, ProcSts.iStatus, ProcSts.enmReason); 280 401 } 281 402 else 282 { 283 if (dwRetExec) 284 logStringW(hModule, L"InstallPythonAPI: Error while executing installation of VBox API: %ld", dwRetExec); 285 else 286 logStringW(hModule, L"InstallPythonAPI: Python reported an error while installing VBox API: %ld", dwExitCode); 287 } 288 } 403 logStringF(hModule, "InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH, rc=%Rrc\n", rc); 404 } 405 else 406 logStringF(hModule, "InstallPythonAPI: Could set working directory to \"%s\", rc=%Rrc\n", pszVBoxSDKPath, rc); 407 408 RTStrFree(pszVBoxSDKPath); 289 409 } 290 410 else 291 logStringW(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation path!"); 292 } 293 294 VBoxSetProperty(hModule, L"VBOX_PYTHON_IS_INSTALLED", bInstalled ? L"1" : L"0"); 295 296 if (!bInstalled) 297 logStringW(hModule, L"InstallPythonAPI: VBox API not installed."); 411 logStringF(hModule, "InstallPythonAPI: Unable to retrieve VBox installation directory, rc=%Rrc\n", rc); 412 } 413 414 /* 415 * Do some sanity checking if the VBox API works. 416 */ 417 if (RT_SUCCESS(rc)) 418 { 419 logStringF(hModule, "InstallPythonAPI: Validating VBox API ...\n"); 420 421 RTPROCSTATUS ProcSts; 422 RT_ZERO(ProcSts); 423 424 RTPROCESS Process; 425 RT_ZERO(Process); 426 const char *papszArgs[4] = { szPythonPath, "-c", "from vboxapi import VirtualBoxManager", NULL}; 427 rc = RTProcCreate(szPythonPath, papszArgs, RTENV_DEFAULT, fProcess, &Process); 428 if (RT_SUCCESS(rc)) 429 { 430 rc = procWait(Process, RT_MS_30SEC, &ProcSts); 431 if (RT_SUCCESS(rc)) 432 logStringF(hModule, "InstallPythonAPI: VBox API looks good.\n"); 433 } 434 435 if (RT_FAILURE(rc)) 436 logStringF(hModule, "InstallPythonAPI: Validating VBox API failed with %Rrc (process status: %d, exit reason: %d)\n", 437 rc, ProcSts.iStatus, ProcSts.enmReason); 438 } 439 440 RTStrFree(pszPythonPath); 441 442 VBoxSetMsiProp(hModule, L"VBOX_API_INSTALLED", RT_SUCCESS(rc) ? L"1" : L"0"); 443 444 if (RT_FAILURE(rc)) 445 logStringF(hModule, "InstallPythonAPI: Installation failed with %Rrc\n", rc); 446 298 447 return ERROR_SUCCESS; /* Do not fail here. */ 299 448 } … … 327 476 (DWORD)wcslen(wszValue)); 328 477 if (rc != ERROR_SUCCESS) 329 logString W(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc);478 logStringF(hModule, "InstallBranding: Could not write value %s! Error %ld", pwszValue, rc); 330 479 RegCloseKey (hkBranding); 331 480 } … … 355 504 FOF_NOERRORUI; 356 505 357 logString W(hModule, L"CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);506 logStringF(hModule, "CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource); 358 507 int r = SHFileOperationW(&s); 359 508 if (r != 0) 360 509 { 361 logString W(hModule, L"CopyDir: Copy operation returned status 0x%x", r);510 logStringF(hModule, "CopyDir: Copy operation returned status 0x%x", r); 362 511 rc = ERROR_GEN_FAILURE; 363 512 } … … 383 532 | FOF_NOERRORUI; 384 533 385 logString W(hModule, L"RemoveDir: DestDir=%s", wszDest);534 logStringF(hModule, "RemoveDir: DestDir=%s", wszDest); 386 535 int r = SHFileOperationW(&s); 387 536 if (r != 0) 388 537 { 389 logString W(hModule, L"RemoveDir: Remove operation returned status 0x%x", r);538 logStringF(hModule, "RemoveDir: Remove operation returned status 0x%x", r); 390 539 rc = ERROR_GEN_FAILURE; 391 540 } … … 414 563 | FOF_NOERRORUI; 415 564 416 logString W(hModule, L"RenameDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);565 logStringF(hModule, "RenameDir: DestDir=%s, SourceDir=%s", wszDest, wszSource); 417 566 int r = SHFileOperationW(&s); 418 567 if (r != 0) 419 568 { 420 logString W(hModule, L"RenameDir: Rename operation returned status 0x%x", r);569 logStringF(hModule, "RenameDir: Rename operation returned status 0x%x", r); 421 570 rc = ERROR_GEN_FAILURE; 422 571 } … … 429 578 { 430 579 UINT rc; 431 logString W(hModule, L"UninstallBranding: Handling branding file ...");580 logStringF(hModule, "UninstallBranding: Handling branding file ..."); 432 581 433 582 WCHAR wszPathTargetDir[_MAX_PATH]; 434 583 WCHAR wszPathDest[_MAX_PATH]; 435 584 436 rc = VBoxGet Property(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));585 rc = VBoxGetMsiProp(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir)); 437 586 if (rc == ERROR_SUCCESS) 438 587 { … … 454 603 } 455 604 456 logString W(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);605 logStringF(hModule, "UninstallBranding: Handling done. (rc=%u (ignored))", rc); 457 606 return ERROR_SUCCESS; /* Do not fail here. */ 458 607 } … … 461 610 { 462 611 UINT rc; 463 logString W(hModule, L"InstallBranding: Handling branding file ...");612 logStringF(hModule, "InstallBranding: Handling branding file ..."); 464 613 465 614 WCHAR wszPathMSI[_MAX_PATH]; 466 rc = VBoxGet Property(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI));615 rc = VBoxGetMsiProp(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI)); 467 616 if (rc == ERROR_SUCCESS) 468 617 { 469 618 WCHAR wszPathTargetDir[_MAX_PATH]; 470 rc = VBoxGet Property(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));619 rc = VBoxGetMsiProp(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir)); 471 620 if (rc == ERROR_SUCCESS) 472 621 { … … 487 636 } 488 637 489 logString W(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);638 logStringF(hModule, "InstallBranding: Handling done. (rc=%u (ignored))", rc); 490 639 return ERROR_SUCCESS; /* Do not fail here. */ 491 640 } … … 518 667 case VBOXDRVCFG_LOG_SEVERITY_REL: 519 668 if (g_hCurrentModule) 520 logString (g_hCurrentModule, pszMsg);669 logStringF(g_hCurrentModule, pszMsg); 521 670 break; 522 671 default: … … 528 677 { 529 678 if (g_hCurrentModule) 530 logString (g_hCurrentModule, pszString);679 logStringF(g_hCurrentModule, pszString); 531 680 } 532 681 … … 565 714 case NETCFG_S_REBOOT: 566 715 { 567 logString W(hModule, L"Reboot required, setting REBOOT property to \"force\"");716 logStringF(hModule, "Reboot required, setting REBOOT property to \"force\""); 568 717 HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force"); 569 718 if (hr2 != ERROR_SUCCESS) 570 logString W(hModule, L"Failed to set REBOOT property, error = 0x%x", hr2);719 logStringF(hModule, "Failed to set REBOOT property, error = 0x%x", hr2); 571 720 uRet = ERROR_SUCCESS; /* Never fail here. */ 572 721 break; … … 574 723 575 724 default: 576 logString W(hModule, L"Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE", hr);725 logStringF(hModule, "Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE", hr); 577 726 uRet = ERROR_GEN_FAILURE; 578 727 } … … 588 737 if (uErr != ERROR_SUCCESS) 589 738 { 590 logString W(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr);739 logStringF(hModule, "createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr); 591 740 MsiCloseHandle(hRecord); 592 741 hRecord = NULL; … … 594 743 } 595 744 else 596 logString W(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record");745 logStringF(hModule, "createNetCfgLockedMsgRecord: Failed to create a record"); 597 746 598 747 return hRecord; … … 613 762 { 614 763 if (FAILED(hr)) 615 logString W(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x", hr);764 logStringF(hModule, "doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x", hr); 616 765 uErr = errorConvertFromHResult(hModule, hr); 617 766 break; … … 622 771 if (!lpszLockedBy) 623 772 { 624 logString W(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking");773 logStringF(hModule, "doNetCfgInit: lpszLockedBy == NULL, breaking"); 625 774 break; 626 775 } … … 636 785 { 637 786 cRetries++; 638 logString W(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);787 logStringF(hModule, "doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES); 639 788 MsgResult = IDRETRY; 640 789 } … … 646 795 if (!hMsg) 647 796 { 648 logString W(hModule, L"doNetCfgInit: Failed to create a message record, breaking");797 logStringF(hModule, "doNetCfgInit: Failed to create a message record, breaking"); 649 798 CoTaskMemFree(lpszLockedBy); 650 799 break; … … 656 805 if (rTmp != ERROR_SUCCESS) 657 806 { 658 logString W(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x", rTmp);807 logStringF(hModule, "doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x", rTmp); 659 808 CoTaskMemFree(lpszLockedBy); 660 809 break; … … 663 812 MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg); 664 813 NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL); 665 logString W(hModule, L"doNetCfgInit: MsiProcessMessage returned (0x%x)", MsgResult);814 logStringF(hModule, "doNetCfgInit: MsiProcessMessage returned (0x%x)", MsgResult); 666 815 } 667 816 CoTaskMemFree(lpszLockedBy); … … 684 833 685 834 wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH)); 686 logString W(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf);835 logStringF(hModule, "vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf); 687 836 688 837 wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH)); 689 logString W(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf);838 logStringF(hModule, "vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf); 690 839 } 691 840 else if (uErr != ERROR_SUCCESS) 692 logString W(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr);841 logStringF(hModule, "vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr); 693 842 else 694 843 { 695 logString W(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");844 logStringF(hModule, "vboxNetFltQueryInfArray: Empty installation directory"); 696 845 uErr = ERROR_GEN_FAILURE; 697 846 } … … 714 863 __try 715 864 { 716 logString W(hModule, L"Uninstalling NetFlt");865 logStringF(hModule, "Uninstalling NetFlt"); 717 866 718 867 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 721 870 HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg); 722 871 if (hr != S_OK) 723 logString W(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);872 logStringF(hModule, "UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr); 724 873 725 874 uErr = errorConvertFromHResult(hModule, hr); … … 727 876 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 728 877 729 logString W(hModule, L"Uninstalling NetFlt done, error = 0x%x", uErr);878 logStringF(hModule, "Uninstalling NetFlt done, error = 0x%x", uErr); 730 879 } 731 880 else 732 logString W(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);881 logStringF(hModule, "UninstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr); 733 882 } 734 883 __finally … … 766 915 { 767 916 768 logString W(hModule, L"InstallNetFlt: Installing NetFlt");917 logStringF(hModule, "InstallNetFlt: Installing NetFlt"); 769 918 770 919 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 779 928 HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs)); 780 929 if (FAILED(hr)) 781 logString W(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr);930 logStringF(hModule, "InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr); 782 931 783 932 uErr = errorConvertFromHResult(hModule, hr); 784 933 } 785 934 else 786 logString W(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x", uErr);935 logStringF(hModule, "InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x", uErr); 787 936 788 937 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 789 938 790 logString W(hModule, L"InstallNetFlt: Done");939 logStringF(hModule, "InstallNetFlt: Done"); 791 940 } 792 941 else 793 logString W(hModule, L"InstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);942 logStringF(hModule, "InstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr); 794 943 } 795 944 __finally … … 827 976 __try 828 977 { 829 logString W(hModule, L"Uninstalling NetLwf");978 logStringF(hModule, "Uninstalling NetLwf"); 830 979 831 980 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 834 983 HRESULT hr = VBoxNetCfgWinNetLwfUninstall(pNetCfg); 835 984 if (hr != S_OK) 836 logString W(hModule, L"UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);985 logStringF(hModule, "UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr); 837 986 838 987 uErr = errorConvertFromHResult(hModule, hr); … … 840 989 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 841 990 842 logString W(hModule, L"Uninstalling NetLwf done, error = 0x%x", uErr);991 logStringF(hModule, "Uninstalling NetLwf done, error = 0x%x", uErr); 843 992 } 844 993 else 845 logString W(hModule, L"UninstallNetLwf: doNetCfgInit failed, error = 0x%x", uErr);994 logStringF(hModule, "UninstallNetLwf: doNetCfgInit failed, error = 0x%x", uErr); 846 995 } 847 996 __finally … … 879 1028 { 880 1029 881 logString W(hModule, L"InstallNetLwf: Installing NetLwf");1030 logStringF(hModule, "InstallNetLwf: Installing NetLwf"); 882 1031 883 1032 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 901 1050 HRESULT hr = VBoxNetCfgWinNetLwfInstall(pNetCfg, wszInf); 902 1051 if (FAILED(hr)) 903 logString W(hModule, L"InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = 0x%x", hr);1052 logStringF(hModule, "InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = 0x%x", hr); 904 1053 905 1054 uErr = errorConvertFromHResult(hModule, hr); … … 907 1056 else 908 1057 { 909 logString W(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");1058 logStringF(hModule, "vboxNetFltQueryInfArray: Empty installation directory"); 910 1059 uErr = ERROR_GEN_FAILURE; 911 1060 } 912 1061 } 913 1062 else 914 logString W(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr);1063 logStringF(hModule, "vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr); 915 1064 916 1065 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 917 1066 918 logString W(hModule, L"InstallNetLwf: Done");1067 logStringF(hModule, "InstallNetLwf: Done"); 919 1068 } 920 1069 else 921 logString W(hModule, L"InstallNetLwf: doNetCfgInit failed, error = 0x%x", uErr);1070 logStringF(hModule, "InstallNetLwf: doNetCfgInit failed, error = 0x%x", uErr); 922 1071 } 923 1072 __finally … … 1008 1157 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); 1009 1158 1010 logString W(hModule, L"CreateHostOnlyInterface: Creating host-only interface");1159 logStringF(hModule, "CreateHostOnlyInterface: Creating host-only interface"); 1011 1160 1012 1161 HRESULT hr = E_FAIL; … … 1021 1170 if (cchMpInf) 1022 1171 { 1023 logString W(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf);1172 logStringF(hModule, "CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf); 1024 1173 if (wszMpInf[cchMpInf - 1] != L'\\') 1025 1174 { … … 1032 1181 fIsFile = true; 1033 1182 1034 logString W(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath);1183 logStringF(hModule, "CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath); 1035 1184 } 1036 1185 else 1037 logString W(hModule, L"CreateHostOnlyInterface: VBox installation path is empty");1186 logStringF(hModule, "CreateHostOnlyInterface: VBox installation path is empty"); 1038 1187 } 1039 1188 else 1040 logString W(hModule, L"CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = 0x%x", uErr);1189 logStringF(hModule, "CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = 0x%x", uErr); 1041 1190 1042 1191 /* Make sure the inf file is installed. */ 1043 1192 if (pwszInfPath != NULL && fIsFile) 1044 1193 { 1045 logString W(hModule, L"CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath);1194 logStringF(hModule, "CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath); 1046 1195 hr = VBoxDrvCfgInfInstall(pwszInfPath); 1047 logString W(hModule, L"CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns 0x%x", hr);1196 logStringF(hModule, "CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns 0x%x", hr); 1048 1197 if (FAILED(hr)) 1049 logString W(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = 0x%x", hr);1198 logStringF(hModule, "CreateHostOnlyInterface: Failed to install INF file, error = 0x%x", hr); 1050 1199 } 1051 1200 … … 1059 1208 if (fRebootRequired) 1060 1209 { 1061 logString W(hModule, L"CreateHostOnlyInterface: Reboot required for update, setting REBOOT property to force");1210 logStringF(hModule, "CreateHostOnlyInterface: Reboot required for update, setting REBOOT property to force"); 1062 1211 HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force"); 1063 1212 if (hr2 != ERROR_SUCCESS) 1064 logString W(hModule, L"CreateHostOnlyInterface: Failed to set REBOOT property for update, error = 0x%x", hr2);1213 logStringF(hModule, "CreateHostOnlyInterface: Failed to set REBOOT property for update, error = 0x%x", hr2); 1065 1214 } 1066 1215 } … … 1068 1217 { 1069 1218 //in fail case call CreateHostOnlyInterface 1070 logString W(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr);1071 logString W(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");1219 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr); 1220 logStringF(hModule, "CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface"); 1072 1221 #ifdef VBOXNETCFG_DELAYEDRENAME 1073 1222 BSTR devId; … … 1076 1225 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, NULL, NULL); 1077 1226 #endif /* !VBOXNETCFG_DELAYEDRENAME */ 1078 logString W(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr);1227 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr); 1079 1228 if (SUCCEEDED(hr)) 1080 1229 { 1081 1230 ULONG ip = inet_addr("192.168.56.1"); 1082 1231 ULONG mask = inet_addr("255.255.255.0"); 1083 logString W(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");1232 logStringF(hModule, "CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig"); 1084 1233 hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask); 1085 logString W(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns 0x%x", hr);1234 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns 0x%x", hr); 1086 1235 if (FAILED(hr)) 1087 logString W(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr);1236 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr); 1088 1237 #ifdef VBOXNETCFG_DELAYEDRENAME 1089 1238 hr = VBoxNetCfgWinRenameHostOnlyConnection(&guid, devId, NULL); 1090 1239 if (FAILED(hr)) 1091 logString W(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRenameHostOnlyConnection failed, error = 0x%x", hr);1240 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinRenameHostOnlyConnection failed, error = 0x%x", hr); 1092 1241 SysFreeString(devId); 1093 1242 #endif /* VBOXNETCFG_DELAYEDRENAME */ 1094 1243 } 1095 1244 else 1096 logString W(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr);1245 logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr); 1097 1246 } 1098 1247 } 1099 1248 1100 1249 if (SUCCEEDED(hr)) 1101 logString W(hModule, L"CreateHostOnlyInterface: Creating host-only interface done");1250 logStringF(hModule, "CreateHostOnlyInterface: Creating host-only interface done"); 1102 1251 1103 1252 /* Restore original setup mode. */ 1104 logString W(hModule, L"CreateHostOnlyInterface: Almost done...");1253 logStringF(hModule, "CreateHostOnlyInterface: Almost done..."); 1105 1254 if (fSetupModeInteractive) 1106 1255 SetupSetNonInteractiveMode(fSetupModeInteractive); … … 1110 1259 #endif /* VBOX_WITH_NETFLT */ 1111 1260 1112 logString W(hModule, L"CreateHostOnlyInterface: Returns success (ignoring all failures)");1261 logStringF(hModule, "CreateHostOnlyInterface: Returns success (ignoring all failures)"); 1113 1262 /* Never fail the install even if we did not succeed. */ 1114 1263 return ERROR_SUCCESS; … … 1130 1279 netCfgLoggerEnable(hModule); 1131 1280 1132 logString W(hModule, L"RemoveHostOnlyInterfaces: Removing all host-only interfaces");1281 logStringF(hModule, "RemoveHostOnlyInterfaces: Removing all host-only interfaces"); 1133 1282 1134 1283 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); … … 1140 1289 if (FAILED(hr)) 1141 1290 { 1142 logString W(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files");1291 logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files"); 1143 1292 } 1144 1293 else 1145 logString W(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully");1294 logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstalled successfully"); 1146 1295 1147 1296 } 1148 1297 else 1149 logString W(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x", hr);1298 logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x", hr); 1150 1299 1151 1300 /* Restore original setup mode. */ … … 1170 1319 netCfgLoggerEnable(hModule); 1171 1320 1172 logString W(hModule, L"StopHostOnlyInterfaces: Stopping all host-only interfaces");1321 logStringF(hModule, "StopHostOnlyInterfaces: Stopping all host-only interfaces"); 1173 1322 1174 1323 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); … … 1177 1326 if (SUCCEEDED(hr)) 1178 1327 { 1179 logString W(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = 0x%x", hr);1328 logStringF(hModule, "StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = 0x%x", hr); 1180 1329 } 1181 1330 else 1182 logString W(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces failed, hr = 0x%x", hr);1331 logStringF(hModule, "StopHostOnlyInterfaces: Disabling host interfaces failed, hr = 0x%x", hr); 1183 1332 1184 1333 /* Restore original setup mode. */ … … 1203 1352 netCfgLoggerEnable(hModule); 1204 1353 1205 logString W(hModule, L"UpdateHostOnlyInterfaces: Updating all host-only interfaces");1354 logStringF(hModule, "UpdateHostOnlyInterfaces: Updating all host-only interfaces"); 1206 1355 1207 1356 BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); … … 1216 1365 if (cchMpInf) 1217 1366 { 1218 logString W(hModule, L"UpdateHostOnlyInterfaces: NetAdpDir property = %s", wszMpInf);1367 logStringF(hModule, "UpdateHostOnlyInterfaces: NetAdpDir property = %s", wszMpInf); 1219 1368 if (wszMpInf[cchMpInf - 1] != L'\\') 1220 1369 { … … 1227 1376 fIsFile = true; 1228 1377 1229 logString W(hModule, L"UpdateHostOnlyInterfaces: Resulting INF path = %s", pwszInfPath);1378 logStringF(hModule, "UpdateHostOnlyInterfaces: Resulting INF path = %s", pwszInfPath); 1230 1379 1231 1380 DWORD attrFile = GetFileAttributesW(pwszInfPath); … … 1233 1382 { 1234 1383 DWORD dwErr = GetLastError(); 1235 logString W(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" not found, dwErr=%ld",1384 logStringF(hModule, "UpdateHostOnlyInterfaces: File \"%s\" not found, dwErr=%ld", 1236 1385 pwszInfPath, dwErr); 1237 1386 } 1238 1387 else 1239 1388 { 1240 logString W(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" exists",1389 logStringF(hModule, "UpdateHostOnlyInterfaces: File \"%s\" exists", 1241 1390 pwszInfPath); 1242 1391 … … 1247 1396 if (fRebootRequired) 1248 1397 { 1249 logString W(hModule, L"UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");1398 logStringF(hModule, "UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force"); 1250 1399 HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force"); 1251 1400 if (hr2 != ERROR_SUCCESS) 1252 logString W(hModule, L"UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = 0x%x", hr2);1401 logStringF(hModule, "UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = 0x%x", hr2); 1253 1402 } 1254 1403 } 1255 1404 else 1256 logString W(hModule, L"UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr);1405 logStringF(hModule, "UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr); 1257 1406 } 1258 1407 } 1259 1408 else 1260 logString W(hModule, L"UpdateHostOnlyInterfaces: VBox installation path is empty");1409 logStringF(hModule, "UpdateHostOnlyInterfaces: VBox installation path is empty"); 1261 1410 } 1262 1411 else 1263 logString W(hModule, L"UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = 0x%x", uErr);1412 logStringF(hModule, "UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = 0x%x", uErr); 1264 1413 1265 1414 /* Restore original setup mode. */ … … 1296 1445 __try 1297 1446 { 1298 logString W(hModule, L"Uninstalling NetAdp");1447 logStringF(hModule, "Uninstalling NetAdp"); 1299 1448 1300 1449 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 1303 1452 HRESULT hr = VBoxNetCfgWinNetAdpUninstall(pNetCfg, pwszId); 1304 1453 if (hr != S_OK) 1305 logString W(hModule, L"UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);1454 logStringF(hModule, "UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr); 1306 1455 1307 1456 uErr = errorConvertFromHResult(hModule, hr); … … 1309 1458 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 1310 1459 1311 logString W(hModule, L"Uninstalling NetAdp done, error = 0x%x", uErr);1460 logStringF(hModule, "Uninstalling NetAdp done, error = 0x%x", uErr); 1312 1461 } 1313 1462 else 1314 logString W(hModule, L"UninstallNetAdp: doNetCfgInit failed, error = 0x%x", uErr);1463 logStringF(hModule, "UninstallNetAdp: doNetCfgInit failed, error = 0x%x", uErr); 1315 1464 } 1316 1465 __finally … … 1398 1547 } 1399 1548 1549 /** @todo r=andy BUGBUG WTF! Why do we a) set the rc to 0 (success), and b) need this macro at all!? */ 1400 1550 #define SetErrBreak(args) \ 1401 1551 if (1) { \ 1402 1552 rc = 0; \ 1403 logString Wargs; \1553 logStringF args; \ 1404 1554 break; \ 1405 1555 } else do {} while (0) … … 1425 1575 LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork); 1426 1576 if ((lStatus != ERROR_SUCCESS) || !hkeyNetwork) 1427 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]",1577 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", 1428 1578 wszRegLocation)); 1429 1579 1430 1580 lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection); 1431 1581 if ((lStatus != ERROR_SUCCESS) || !hkeyConnection) 1432 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]",1582 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", 1433 1583 wszRegLocation)); 1434 1584 … … 1438 1588 &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len); 1439 1589 if ((lStatus != ERROR_SUCCESS) || (dwKeyType != REG_SZ)) 1440 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]",1590 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", 1441 1591 wszRegLocation)); 1442 1592 } … … 1473 1623 if (hDeviceInfo == INVALID_HANDLE_VALUE) 1474 1624 { 1475 logString W(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());1476 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));1625 logStringF(hModule, "VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError()); 1626 SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!")); 1477 1627 } 1478 1628 … … 1576 1726 if (!fResult) 1577 1727 { 1578 logString W(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());1579 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));1728 logStringF(hModule, "VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError()); 1729 SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!")); 1580 1730 } 1581 1731 … … 1583 1733 if (!fResult) 1584 1734 { 1585 logString W(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());1586 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));1735 logStringF(hModule, "VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError()); 1736 SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!")); 1587 1737 } 1588 1738 } 1589 1739 else 1590 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network device not found!"));1740 SetErrBreak((hModule, "VBox HostInterfaces: Host interface network device not found!")); 1591 1741 } while (0); 1592 1742 … … 1606 1756 if (lStatus == ERROR_SUCCESS) 1607 1757 { 1608 logString W(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");1758 logStringF(hModule, "VBox HostInterfaces: Enumerating interfaces ..."); 1609 1759 for (int i = 0; ; ++i) 1610 1760 { … … 1617 1767 { 1618 1768 case ERROR_NO_MORE_ITEMS: 1619 logString W(hModule, L"VBox HostInterfaces: No interfaces found.");1769 logStringF(hModule, "VBox HostInterfaces: No interfaces found."); 1620 1770 break; 1621 1771 default: 1622 logString W(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);1772 logStringF(hModule, "VBox HostInterfaces: Enumeration failed: %ld", lStatus); 1623 1773 break; 1624 1774 } … … 1628 1778 if (isTAPDevice(wszNetworkGUID)) 1629 1779 { 1630 logString W(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);1780 logStringF(hModule, "VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID); 1631 1781 removeNetworkInterface(hModule, wszNetworkGUID); 1632 1782 lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID); … … 1634 1784 } 1635 1785 RegCloseKey(hCtrlNet); 1636 logString W(hModule, L"VBox HostInterfaces: Removing interfaces done.");1786 logStringF(hModule, "VBox HostInterfaces: Removing interfaces done."); 1637 1787 } 1638 1788 return ERROR_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.