Changeset 38791 in vbox
- Timestamp:
- Sep 19, 2011 1:21:31 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 74086
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r38732 r38791 274 274 } 275 275 276 /** @todo r=bird: This function is not in the header file, why is it 277 * exported? */ 276 278 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallInfAndComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass, 277 IN LPCWSTR *apInfPaths, IN UINT cInfPaths,279 IN LPCWSTR const *apInfPaths, IN UINT cInfPaths, 278 280 OUT INetCfgComponent **ppComponent) 279 281 { … … 1858 1860 1859 1861 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltInstall(IN INetCfg *pNc, 1860 IN LPCWSTR *apInfFullPaths, IN UINT cInfFullPaths)1862 IN LPCWSTR const *apInfFullPaths, IN UINT cInfFullPaths) 1861 1863 { 1862 1864 HRESULT hr = vboxNetCfgWinNetFltUninstall(pNc, SUOI_FORCEDELETE); … … 2056 2058 2057 2059 /* Build the display name in the form "::{GUID}". */ 2058 if (wcslen 2060 if (wcslen(wGuid) >= MAX_PATH) 2059 2061 return E_INVALIDARG; 2060 2062 WCHAR szAdapterGuid[MAX_PATH + 2] = {0}; 2061 swprintf 2063 swprintf(szAdapterGuid, L"::%ls", wGuid); 2062 2064 2063 2065 /* Create an instance of the network connections folder. */ 2064 hr = CoCreateInstance 2065 2066 reinterpret_cast <LPVOID *>(&pShellFolder));2066 hr = CoCreateInstance(CLSID_NetworkConnections, NULL, 2067 CLSCTX_INPROC_SERVER, IID_IShellFolder, 2068 reinterpret_cast<LPVOID *>(&pShellFolder)); 2067 2069 /* Parse the display name. */ 2068 2070 if (SUCCEEDED (hr)) … … 2709 2711 if (lppszName) 2710 2712 { 2711 *lppszName = ::SysAllocString((const OLECHAR *) DevName);2713 *lppszName = SysAllocString((const OLECHAR *) DevName); 2712 2714 if (!*lppszName) 2713 2715 { -
trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp
r37289 r38791 5 5 6 6 /* 7 * Copyright (C) 2008-201 0Oracle Corporation7 * Copyright (C) 2008-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 19 /******************************************************************************* 20 * Header Files * 21 *******************************************************************************/ 18 22 #include <windows.h> 19 23 #include <tchar.h> … … 24 28 25 29 26 #if (_MSC_VER < 1400) /* Provide _stprintf_s to VC < 8.0. */27 int _stprintf_s(TCHAR *buffer, size_t cbBuffer, const TCHAR *format, ...)30 #if (_MSC_VER < 1400) /* Provide swprintf_s to VC < 8.0. */ 31 int swprintf_s(WCHAR *buffer, size_t cbBuffer, const WCHAR *format, ...) 28 32 { 29 33 int ret; 30 va_list args;31 va_start( args, format);32 ret = _vsn tprintf(buffer, cbBuffer, format, args);33 va_end( args);34 va_list va; 35 va_start(va, format); 36 ret = _vsnwprintf(buffer, cbBuffer, format, va); 37 va_end(va); 34 38 return ret; 35 39 } 36 40 #endif 37 41 38 UINT VBoxGetProperty(MSIHANDLE a_hModule, TCHAR* a_pszName, TCHAR* a_pValue, DWORD a_dwSize)42 UINT VBoxGetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue, DWORD a_dwSize) 39 43 { 40 UINT uiRet = ERROR_SUCCESS;41 44 DWORD dwBuffer = 0; 42 43 uiRet = MsiGetProperty(a_hModule, a_pszName, TEXT(""), &dwBuffer); 44 if (ERROR_MORE_DATA == uiRet) 45 UINT uiRet = MsiGetPropertyW(a_hModule, a_pwszName, L"", &dwBuffer); 46 if (uiRet == ERROR_MORE_DATA) 45 47 { 46 48 ++dwBuffer; /* On output does not include terminating null, so add 1. */ … … 49 51 return ERROR_MORE_DATA; 50 52 51 ZeroMemory(a_p Value, a_dwSize);52 uiRet = MsiGetProperty (a_hModule, a_pszName, a_pValue, &dwBuffer);53 ZeroMemory(a_pwszValue, a_dwSize); 54 uiRet = MsiGetPropertyW(a_hModule, a_pwszName, a_pwszValue, &dwBuffer); 53 55 } 54 56 return uiRet; 55 57 } 56 58 57 UINT VBoxSetProperty(MSIHANDLE a_hModule, TCHAR* a_pszName, TCHAR* a_pValue)59 UINT VBoxSetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue) 58 60 { 59 return MsiSetProperty (a_hModule, a_pszName, a_pValue);61 return MsiSetPropertyW(a_hModule, a_pwszName, a_pwszValue); 60 62 } 61 63 -
trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.h
r32112 r38791 5 5 6 6 /* 7 * Copyright (C) 2008-201 0Oracle Corporation7 * Copyright (C) 2008-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 21 21 #if (_MSC_VER < 1400) /* Provide _stprintf_s to VC < 8.0. */ 22 int _stprintf_s(TCHAR *buffer, size_t cbBuffer, const TCHAR *format, ...);22 int swprintf_s(WCHAR *buffer, size_t cbBuffer, const WCHAR *format, ...); 23 23 #endif 24 24 25 UINT VBoxGetProperty(MSIHANDLE a_hModule, TCHAR *a_pszName, TCHAR *a_pValue, DWORD a_dwSize);26 UINT VBoxSetProperty(MSIHANDLE a_hModule, TCHAR *a_pszName, TCHAR *a_pValue);25 UINT VBoxGetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue, DWORD a_dwSize); 26 UINT VBoxSetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue); 27 27 28 28 #endif /* !___VBoxInstallHelper_Common_h */ -
trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp
r38740 r38791 16 16 */ 17 17 18 19 /******************************************************************************* 20 * Header Files * 21 *******************************************************************************/ 18 22 #ifdef VBOX_WITH_NETFLT 19 23 # include "VBox/VBoxNetCfg-win.h" … … 24 28 25 29 #include <windows.h> 26 #include < tchar.h>30 #include <wchar.h> 27 31 #include <stdio.h> 28 32 … … 48 52 #endif 49 53 54 55 /******************************************************************************* 56 * Header Files * 57 *******************************************************************************/ 50 58 #ifdef DEBUG 51 59 # define NonStandardAssert(_expr) assert(_expr) … … 54 62 #endif 55 63 64 #define MY_WTEXT_HLP(a_str) L##a_str 65 #define MY_WTEXT(a_str) MY_WTEXT_HLP(a_str) 66 67 56 68 BOOL APIENTRY DllMain(HANDLE hModule, 57 69 DWORD ul_reason_for_call, … … 61 73 } 62 74 63 static void LogString(MSIHANDLE hInstall, LPCSTR szString, ...)75 static void logString(MSIHANDLE hInstall, LPCSTR szString, ...) 64 76 { 65 77 PMSIHANDLE newHandle = MsiCreateRecord(2); 66 78 67 char szBuffer[1024] = {0};68 va_list pArgList;69 va_start( pArgList, szString);70 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(char), szString, pArgList);71 va_end( pArgList);79 char szBuffer[1024]; 80 va_list va; 81 va_start(va, szString); 82 _vsnprintf(szBuffer, sizeof(szBuffer), szString, va); 83 va_end(va); 72 84 73 85 MsiRecordSetStringA(newHandle, 0, szBuffer); … … 75 87 MsiCloseHandle(newHandle); 76 88 77 #if def DEBUG89 #if 0/*def DEBUG - wrong? What does '%s' expect, wchar or char? */ 78 90 _tprintf(_T("Debug: %s\n"), szBuffer); 79 91 #endif 80 92 } 81 93 82 static void LogStringW(MSIHANDLE hInstall, LPCWSTRszString, ...)94 static void logStringW(MSIHANDLE hInstall, LPCWSTR pwszString, ...) 83 95 { 84 96 PMSIHANDLE newHandle = MsiCreateRecord(2); 85 97 86 TCHAR szBuffer[1024] = {0};87 va_list pArgList;88 va_start( pArgList,szString);89 _vsnwprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szString, pArgList);90 va_end( pArgList);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); 91 103 92 104 MsiRecordSetStringW(newHandle, 0, szBuffer); … … 112 124 113 125 DWORD Exec(MSIHANDLE hModule, 114 const TCHAR *pszAppName, TCHAR *pszCmdLine, const TCHAR *pszWorkDir,126 const WCHAR *pwszAppName, WCHAR *pwszCmdLine, const WCHAR *pwszWorkDir, 115 127 DWORD *pdwExitCode) 116 128 { … … 128 140 ZeroMemory(&pi, sizeof(pi)); 129 141 130 LogStringW(hModule, TEXT("Executing command line: %s %s (Working Dir: %s)"),131 p szAppName, pszCmdLine, pszWorkDir == NULL ? L"Current" : pszWorkDir);142 logStringW(hModule, L"Executing command line: %s %s (Working Dir: %s)", 143 pwszAppName, pwszCmdLine, pwszWorkDir == NULL ? L"Current" : pwszWorkDir); 132 144 133 145 SetLastError(0); 134 if (!CreateProcess(p szAppName,/* Module name. */135 p szCmdLine,/* Command line. */146 if (!CreateProcess(pwszAppName, /* Module name. */ 147 pwszCmdLine, /* Command line. */ 136 148 NULL, /* Process handle not inheritable. */ 137 149 NULL, /* Thread handle not inheritable. */ … … 139 151 0, /* No creation flags. */ 140 152 NULL, /* Use parent's environment block. */ 141 p szWorkDir,/* Use parent's starting directory. */153 pwszWorkDir, /* Use parent's starting directory. */ 142 154 &si, /* Pointer to STARTUPINFO structure. */ 143 155 &pi)) /* Pointer to PROCESS_INFORMATION structure. */ 144 156 { 145 157 rc = GetLastError(); 146 LogStringW(hModule, TEXT("Executing command line: CreateProcess() failed! Error: %ld"), rc);158 logStringW(hModule, L"Executing command line: CreateProcess() failed! Error: %ld", rc); 147 159 return rc; 148 160 } … … 152 164 { 153 165 rc = GetLastError(); 154 LogStringW(hModule, TEXT("Executing command line: WaitForSingleObject() failed! Error: %ld"), rc);166 logStringW(hModule, L"Executing command line: WaitForSingleObject() failed! Error: %u", rc); 155 167 } 156 168 else … … 159 171 { 160 172 rc = GetLastError(); 161 LogStringW(hModule, TEXT("Executing command line: GetExitCodeProcess() failed! Error: %ld"), rc);173 logStringW(hModule, L"Executing command line: GetExitCodeProcess() failed! Error: %u", rc); 162 174 } 163 175 } … … 167 179 CloseHandle(pi.hThread); 168 180 169 LogStringW(hModule, TEXT("Executing command returned: %ld (exit code %ld)"), rc, *pdwExitCode);181 logStringW(hModule, L"Executing command returned: %u (exit code %u)", rc, *pdwExitCode); 170 182 return rc; 171 183 } … … 173 185 UINT __stdcall InstallPythonAPI(MSIHANDLE hModule) 174 186 { 175 LogStringW(hModule, TEXT("InstallPythonAPI: Checking for installed Python environment ..."));187 logStringW(hModule, L"InstallPythonAPI: Checking for installed Python environment ..."); 176 188 177 189 HKEY hkPythonCore = NULL; … … 180 192 if (rc != ERROR_SUCCESS) 181 193 { 182 LogStringW(hModule, TEXT("InstallPythonAPI: Python seems not to be installed."));194 logStringW(hModule, L"InstallPythonAPI: Python seems not to be installed."); 183 195 return ERROR_SUCCESS; 184 196 } 185 197 186 TCHARszPath[MAX_PATH] = { 0 };187 TCHARszVal[MAX_PATH] = { 0 };198 WCHAR wszPath[MAX_PATH] = { 0 }; 199 WCHAR wszVal[MAX_PATH] = { 0 }; 188 200 189 201 for (int i = 0;; ++i) 190 202 { 191 TCHARszRoot[MAX_PATH] = { 0 };192 DWORD dwLen = sizeof (szPath);203 WCHAR wszRoot[MAX_PATH] = { 0 }; 204 DWORD dwLen = sizeof(wszPath); 193 205 DWORD dwKeyType = REG_SZ; 194 206 195 rc = RegEnumKeyEx(hkPythonCore, i, szRoot, &dwLen, NULL, NULL, NULL, NULL);207 rc = RegEnumKeyEx(hkPythonCore, i, wszRoot, &dwLen, NULL, NULL, NULL, NULL); 196 208 if (rc != ERROR_SUCCESS || dwLen <= 0) 197 209 break; 198 210 199 _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\InstallPath",szRoot);200 dwLen = sizeof( szVal);211 swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\InstallPath", wszRoot); 212 dwLen = sizeof(wszVal); 201 213 202 214 HKEY hkPythonInstPath = NULL; 203 rc = RegOpenKeyEx(hkPythonCore, szPath, 0, KEY_READ, &hkPythonInstPath);215 rc = RegOpenKeyEx(hkPythonCore, wszPath, 0, KEY_READ, &hkPythonInstPath); 204 216 if (rc != ERROR_SUCCESS) 205 217 continue; 206 218 207 rc = RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE) szVal, &dwLen);219 rc = RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)wszVal, &dwLen); 208 220 if (rc == ERROR_SUCCESS) 209 LogStringW(hModule, TEXT("InstallPythonAPI: Path \"%s\" detected."),szVal);221 logStringW(hModule, L"InstallPythonAPI: Path \"%s\" detected.", wszVal); 210 222 211 223 RegCloseKey(hkPythonInstPath); … … 214 226 215 227 /* Python path found? */ 216 TCHARszExec[MAX_PATH] = { 0 };217 TCHARszCmdLine[MAX_PATH] = { 0 };228 WCHAR wszExec[MAX_PATH] = { 0 }; 229 WCHAR wszCmdLine[MAX_PATH] = { 0 }; 218 230 DWORD dwExitCode = 0; 219 if ( _tcslen(szVal) > 0)231 if (wcslen(wszVal) > 0) 220 232 { 221 233 /* Cool, check for installed Win32 extensions. */ 222 LogStringW(hModule, TEXT("InstallPythonAPI: Python installed. Checking for Win32 extensions ..."));223 _stprintf_s(szExec, sizeof(szExec) / sizeof(TCHAR), L"%s\\python.exe",szVal);224 _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe -c \"import win32api\"",szVal);225 226 DWORD dwRetExec = Exec(hModule, szExec,szCmdLine, NULL, &dwExitCode);234 logStringW(hModule, L"InstallPythonAPI: Python installed. Checking for Win32 extensions ..."); 235 swprintf_s(wszExec, RT_ELEMENTS(wszExec), L"%s\\python.exe", wszVal); 236 swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe -c \"import win32api\"", wszVal); 237 238 DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, NULL, &dwExitCode); 227 239 if ( (ERROR_SUCCESS == dwRetExec) 228 240 && ( 0 == dwExitCode)) 229 241 { 230 242 /* Did we get the correct error level (=0)? */ 231 LogStringW(hModule, TEXT("InstallPythonAPI: Win32 extensions installed."));243 logStringW(hModule, L"InstallPythonAPI: Win32 extensions installed."); 232 244 bFound = TRUE; 233 245 } 234 246 else 235 LogStringW(hModule, TEXT("InstallPythonAPI: Win32 extensions not found."));247 logStringW(hModule, L"InstallPythonAPI: Win32 extensions not found."); 236 248 } 237 249 … … 240 252 { 241 253 /* Get the VBoxAPI setup string. */ 242 TCHARszPathTargetDir[MAX_PATH] = {0};243 VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));244 if ( _tcslen(szPathTargetDir))254 WCHAR wszPathTargetDir[MAX_PATH] = {0}; 255 VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir)); 256 if (wcslen(wszPathTargetDir)) 245 257 { 246 258 247 259 /* Set final path. */ 248 _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\sdk\\install",szPathTargetDir);260 swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\sdk\\install", wszPathTargetDir); 249 261 250 262 /* Install our API module. */ 251 _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe vboxapisetup.py install",szVal);263 swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe vboxapisetup.py install", wszVal); 252 264 253 265 /* Set required environment variables. */ 254 if (!SetEnvironmentVariable(L"VBOX_INSTALL_PATH", szPathTargetDir)) 255 { 256 LogStringW(hModule, TEXT("InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!")); 257 } 266 if (!SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszPathTargetDir)) 267 logStringW(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!"); 258 268 else 259 269 { 260 DWORD dwRetExec = Exec(hModule, szExec, szCmdLine,szPath, &dwExitCode);270 DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, wszPath, &dwExitCode); 261 271 if ( (ERROR_SUCCESS == dwRetExec) 262 272 && ( 0 == dwExitCode)) 263 273 { 264 274 /* All done! */ 265 LogStringW(hModule, TEXT("InstallPythonAPI: VBoxAPI for Python successfully installed."));275 logStringW(hModule, L"InstallPythonAPI: VBoxAPI for Python successfully installed."); 266 276 bInstalled = TRUE; 267 277 } … … 269 279 { 270 280 if (dwRetExec) 271 LogStringW(hModule, TEXT("InstallPythonAPI: Error while executing installation of VBox API: %ld"), dwRetExec);281 logStringW(hModule, L"InstallPythonAPI: Error while executing installation of VBox API: %ld", dwRetExec); 272 282 else 273 LogStringW(hModule, TEXT("InstallPythonAPI: Python reported an error while installing VBox API: %ld"), dwExitCode);283 logStringW(hModule, L"InstallPythonAPI: Python reported an error while installing VBox API: %ld", dwExitCode); 274 284 } 275 285 } 276 286 } 277 287 else 278 LogStringW(hModule, TEXT("InstallPythonAPI: Unable to retrieve VBox installation path!"));288 logStringW(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation path!"); 279 289 } 280 290 … … 282 292 283 293 if (!bInstalled) 284 LogStringW(hModule, TEXT("InstallPythonAPI: VBox API not installed."));294 logStringW(hModule, L"InstallPythonAPI: VBox API not installed."); 285 295 return ERROR_SUCCESS; /* Do not fail here. */ 286 296 } 287 297 288 static LONG InstallBrandingValue(MSIHANDLE hModule,289 const TCHAR* pszFileName,290 const TCHAR* pszSection,291 const TCHAR* pszValue)298 static LONG installBrandingValue(MSIHANDLE hModule, 299 const WCHAR *pwszFileName, 300 const WCHAR *pwszSection, 301 const WCHAR *pwszValue) 292 302 { 293 303 LONG rc; 294 TCHARszValue[_MAX_PATH];295 if (GetPrivateProfileString(p szSection, pszValue, NULL,296 szValue, sizeof(szValue), pszFileName) > 0)304 WCHAR wszValue[_MAX_PATH]; 305 if (GetPrivateProfileString(pwszSection, pwszValue, NULL, 306 wszValue, sizeof(wszValue), pwszFileName) > 0) 297 307 { 298 308 HKEY hkBranding; 299 TCHARszKey[_MAX_PATH];300 301 if (wcsicmp(L"General", p szSection) != 0)302 _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pszSection);309 WCHAR wszKey[_MAX_PATH]; 310 311 if (wcsicmp(L"General", pwszSection) != 0) 312 swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pwszSection); 303 313 else 304 _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT); 305 306 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 307 0, KEY_WRITE, &hkBranding); 314 swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT); 315 316 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wszKey, 0, KEY_WRITE, &hkBranding); 308 317 if (rc == ERROR_SUCCESS) 309 318 { 310 rc = RegSetValueEx (hkBranding,311 pszValue,312 NULL,313 REG_SZ,314 (BYTE*)szValue,315 (DWORD)wcslen(szValue));319 rc = RegSetValueExW(hkBranding, 320 pwszValue, 321 NULL, 322 REG_SZ, 323 (BYTE *)wszValue, 324 (DWORD)wcslen(wszValue)); 316 325 if (rc != ERROR_SUCCESS) 317 LogStringW(hModule, TEXT("InstallBranding: Could not write value %s! Error %ld"), pszValue, rc);326 logStringW(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc); 318 327 RegCloseKey (hkBranding); 319 328 } … … 324 333 } 325 334 326 UINT CopyDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)335 UINT CopyDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir) 327 336 { 328 337 UINT rc; 329 TCHARszDest[_MAX_PATH + 1];330 TCHARszSource[_MAX_PATH + 1];331 332 _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');333 _stprintf_s(szSource, sizeof(szSource) / sizeof(TCHAR), L"%s%c", pszSourceDir, '\0');338 WCHAR wszDest[_MAX_PATH + 1]; 339 WCHAR wszSource[_MAX_PATH + 1]; 340 341 swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0'); 342 swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, '\0'); 334 343 335 344 SHFILEOPSTRUCT s = {0}; 336 345 s.hwnd = NULL; 337 346 s.wFunc = FO_COPY; 338 s.pTo = szDest;339 s.pFrom = szSource;347 s.pTo = wszDest; 348 s.pFrom = wszSource; 340 349 s.fFlags = FOF_SILENT | 341 350 FOF_NOCONFIRMATION | … … 343 352 FOF_NOERRORUI; 344 353 345 LogStringW(hModule, TEXT("CopyDir: DestDir=%s, SourceDir=%s"), 346 szDest, szSource); 354 logStringW(hModule, L"CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource); 347 355 int r = SHFileOperation(&s); 348 356 if (r != 0) 349 357 { 350 LogStringW(hModule, TEXT("CopyDir: Copy operation returned status 0x%x"), r);358 logStringW(hModule, L"CopyDir: Copy operation returned status 0x%x", r); 351 359 rc = ERROR_GEN_FAILURE; 352 360 } … … 356 364 } 357 365 358 UINT RemoveDir(MSIHANDLE hModule, const TCHAR *pszDestDir)366 UINT RemoveDir(MSIHANDLE hModule, const WCHAR *pwszDestDir) 359 367 { 360 368 UINT rc; 361 TCHARszDest[_MAX_PATH + 1];362 363 _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');364 365 SHFILEOPSTRUCT s = {0};369 WCHAR wszDest[_MAX_PATH + 1]; 370 371 swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0'); 372 373 SHFILEOPSTRUCTW s = {0}; 366 374 s.hwnd = NULL; 367 375 s.wFunc = FO_DELETE; 368 s.pFrom = szDest;369 s.fFlags = FOF_SILENT |370 FOF_NOCONFIRMATION |371 FOF_NOCONFIRMMKDIR |372 373 374 LogStringW(hModule, TEXT("RemoveDir: DestDir=%s"),szDest);375 int r = SHFileOperation (&s);376 s.pFrom = wszDest; 377 s.fFlags = FOF_SILENT 378 | FOF_NOCONFIRMATION 379 | FOF_NOCONFIRMMKDIR 380 | FOF_NOERRORUI; 381 382 logStringW(hModule, L"RemoveDir: DestDir=%s", wszDest); 383 int r = SHFileOperationW(&s); 376 384 if (r != 0) 377 385 { 378 LogStringW(hModule, TEXT("RemoveDir: Remove operation returned status 0x%x"), r);386 logStringW(hModule, L"RemoveDir: Remove operation returned status 0x%x", r); 379 387 rc = ERROR_GEN_FAILURE; 380 388 } … … 384 392 } 385 393 386 UINT RenameDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)394 UINT RenameDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir) 387 395 { 388 396 UINT rc; 389 TCHARszDest[_MAX_PATH + 1];390 TCHARszSource[_MAX_PATH + 1];391 392 _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');393 _stprintf_s(szSource, sizeof(szSource) / sizeof(TCHAR), L"%s%c", pszSourceDir, '\0');394 395 SHFILEOPSTRUCT s = {0};397 WCHAR wszDest[_MAX_PATH + 1]; 398 WCHAR wszSource[_MAX_PATH + 1]; 399 400 swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0'); 401 swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, '\0'); 402 403 SHFILEOPSTRUCTW s = {0}; 396 404 s.hwnd = NULL; 397 405 s.wFunc = FO_RENAME; 398 s.pTo = szDest; 399 s.pFrom = szSource; 400 s.fFlags = FOF_SILENT | 401 FOF_NOCONFIRMATION | 402 FOF_NOCONFIRMMKDIR | 403 FOF_NOERRORUI; 404 405 LogStringW(hModule, TEXT("RenameDir: DestDir=%s, SourceDir=%s"), 406 szDest, szSource); 407 int r = SHFileOperation(&s); 406 s.pTo = wszDest; 407 s.pFrom = wszSource; 408 s.fFlags = FOF_SILENT 409 | FOF_NOCONFIRMATION 410 | FOF_NOCONFIRMMKDIR 411 | FOF_NOERRORUI; 412 413 logStringW(hModule, L"RenameDir: DestDir=%s, SourceDir=%s", wszDest, wszSource); 414 int r = SHFileOperationW(&s); 408 415 if (r != 0) 409 416 { 410 LogStringW(hModule, TEXT("RenameDir: Rename operation returned status 0x%x"), r);417 logStringW(hModule, L"RenameDir: Rename operation returned status 0x%x", r); 411 418 rc = ERROR_GEN_FAILURE; 412 419 } … … 419 426 { 420 427 UINT rc; 421 LogStringW(hModule, TEXT("UninstallBranding: Handling branding file ..."));422 423 TCHARszPathTargetDir[_MAX_PATH];424 TCHARszPathDest[_MAX_PATH];425 426 rc = VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));428 logStringW(hModule, L"UninstallBranding: Handling branding file ..."); 429 430 WCHAR wszPathTargetDir[_MAX_PATH]; 431 WCHAR wszPathDest[_MAX_PATH]; 432 433 rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir)); 427 434 if (rc == ERROR_SUCCESS) 428 435 { 429 436 /** @todo Check trailing slash after %s. */ 430 _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir); 431 rc = RemoveDir(hModule, szPathDest); 437 /** @todo r=bird: using swprintf_s for formatting paths without checking for 438 * overflow not good. You're dodging the buffer overflow issue only to end up 439 * with incorrect behavior! (Truncated file/dir names) 440 * 441 * This applies almost to all swprintf_s calls in this file!! 442 */ 443 swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir); 444 rc = RemoveDir(hModule, wszPathDest); 432 445 if (rc != ERROR_SUCCESS) 433 446 { 434 447 /* Check for hidden .custom directory and remove it. */ 435 _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s.custom",szPathTargetDir);436 rc = RemoveDir(hModule, szPathDest);437 } 438 } 439 440 LogStringW(hModule, TEXT("UninstallBranding: Handling done."));448 swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s.custom", wszPathTargetDir); 449 rc = RemoveDir(hModule, wszPathDest); 450 } 451 } 452 453 logStringW(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc); 441 454 return ERROR_SUCCESS; /* Do not fail here. */ 442 455 } … … 445 458 { 446 459 UINT rc; 447 LogStringW(hModule, TEXT("InstallBranding: Handling branding file ...")); 448 449 TCHAR szPathMSI[_MAX_PATH]; 450 TCHAR szPathTargetDir[_MAX_PATH]; 451 452 TCHAR szPathSource[_MAX_PATH]; 453 TCHAR szPathDest[_MAX_PATH]; 454 455 rc = VBoxGetProperty(hModule, L"SOURCEDIR", szPathMSI, sizeof(szPathMSI)); 460 logStringW(hModule, L"InstallBranding: Handling branding file ..."); 461 462 WCHAR wszPathMSI[_MAX_PATH]; 463 rc = VBoxGetProperty(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI)); 456 464 if (rc == ERROR_SUCCESS) 457 465 { 458 rc = VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir)); 466 WCHAR wszPathTargetDir[_MAX_PATH]; 467 rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir)); 459 468 if (rc == ERROR_SUCCESS) 460 469 { 461 470 /** @todo Check for trailing slash after %s. */ 462 _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s", szPathTargetDir); 463 _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom", szPathMSI); 464 rc = CopyDir(hModule, szPathDest, szPathSource); 471 WCHAR wszPathDest[_MAX_PATH]; 472 swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s", wszPathTargetDir); 473 474 WCHAR wszPathSource[_MAX_PATH]; 475 swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathMSI); 476 rc = CopyDir(hModule, wszPathDest, wszPathSource); 465 477 if (rc == ERROR_SUCCESS) 466 478 { 467 _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom",szPathTargetDir);468 _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom",szPathTargetDir);469 rc = RenameDir(hModule, szPathDest,szPathSource);479 swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir); 480 swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathTargetDir); 481 rc = RenameDir(hModule, wszPathDest, wszPathSource); 470 482 } 471 483 } 472 484 } 473 485 474 LogStringW(hModule, TEXT("InstallBranding: Handling done."));486 logStringW(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc); 475 487 return ERROR_SUCCESS; /* Do not fail here. */ 476 488 } … … 491 503 { 492 504 if (g_hCurrentModule) 493 LogString(g_hCurrentModule, szString);505 logString(g_hCurrentModule, szString); 494 506 } 495 507 … … 515 527 } 516 528 517 static UINT ErrorConvertFromHResult(MSIHANDLE hModule, HRESULT hr)529 static UINT errorConvertFromHResult(MSIHANDLE hModule, HRESULT hr) 518 530 { 519 531 UINT uRet; … … 526 538 case NETCFG_S_REBOOT: 527 539 { 528 LogStringW(hModule, TEXT("Reboot required, setting REBOOT property to Force"));529 HRESULT hr2 = MsiSetProperty(hModule, TEXT("REBOOT"), TEXT("Force"));540 logStringW(hModule, L"Reboot required, setting REBOOT property to Force"); 541 HRESULT hr2 = MsiSetProperty(hModule, L"REBOOT", L"Force"); 530 542 if (hr2 != ERROR_SUCCESS) 531 LogStringW(hModule, TEXT("Failed to set REBOOT property, error = 0x%x"), hr2);543 logStringW(hModule, L"Failed to set REBOOT property, error = 0x%x", hr2); 532 544 uRet = ERROR_SUCCESS; /* Never fail here. */ 533 545 break; … … 535 547 536 548 default: 537 LogStringW(hModule, TEXT("Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE"), hr);549 logStringW(hModule, L"Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE", hr); 538 550 uRet = ERROR_GEN_FAILURE; 539 551 } … … 549 561 if (uErr != ERROR_SUCCESS) 550 562 { 551 LogStringW(hModule, TEXT("createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x"), uErr);563 logStringW(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr); 552 564 MsiCloseHandle(hRecord); 553 565 hRecord = NULL; … … 555 567 } 556 568 else 557 LogStringW(hModule, TEXT("createNetCfgLockedMsgRecord: Failed to create a record"));569 logStringW(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record"); 558 570 559 571 return hRecord; … … 574 586 { 575 587 if (FAILED(hr)) 576 LogStringW(hModule, TEXT("doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x"), hr);577 uErr = ErrorConvertFromHResult(hModule, hr);588 logStringW(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x", hr); 589 uErr = errorConvertFromHResult(hModule, hr); 578 590 break; 579 591 } … … 583 595 if (!lpszLockedBy) 584 596 { 585 LogStringW(hModule, TEXT("doNetCfgInit: lpszLockedBy == NULL, breaking"));597 logStringW(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking"); 586 598 break; 587 599 } … … 597 609 { 598 610 cRetries++; 599 LogStringW(hModule, TEXT("doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d"), cRetries, VBOX_NETCFG_MAX_RETRIES);611 logStringW(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES); 600 612 MsgResult = IDRETRY; 601 613 } … … 607 619 if (!hMsg) 608 620 { 609 LogStringW(hModule, TEXT("doNetCfgInit: Failed to create a message record, breaking"));621 logStringW(hModule, L"doNetCfgInit: Failed to create a message record, breaking"); 610 622 CoTaskMemFree(lpszLockedBy); 611 623 break; … … 617 629 if (rTmp != ERROR_SUCCESS) 618 630 { 619 LogStringW(hModule, TEXT("doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x"), rTmp);631 logStringW(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x", rTmp); 620 632 CoTaskMemFree(lpszLockedBy); 621 633 break; … … 624 636 MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg); 625 637 NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL); 626 LogStringW(hModule, TEXT("doNetCfgInit: MsiProcessMessage returned (0x%x)"), MsgResult);638 logStringW(hModule, L"doNetCfgInit: MsiProcessMessage returned (0x%x)", MsgResult); 627 639 } 628 640 CoTaskMemFree(lpszLockedBy); … … 635 647 } 636 648 637 static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR *apInfFullPaths, PUINT pcInfs, DWORD dwSize) 638 { 639 UINT uErr; 640 if (*pcInfs >= 2) 641 { 642 *pcInfs = 2; 643 644 DWORD dwBuf = dwSize; 645 uErr = MsiGetPropertyW(hModule, L"CustomActionData", apInfFullPaths[0], &dwBuf); 646 if ( uErr == ERROR_SUCCESS 647 && dwBuf) 648 { 649 /** @todo r=andy Avoid wcscpy and wcsncat, can cause buffer overruns! */ 650 wcscpy(apInfFullPaths[1], apInfFullPaths[0]); 651 652 wcsncat(apInfFullPaths[0], NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH)); 653 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: INF 1: %s"), apInfFullPaths[0]); 654 655 wcsncat(apInfFullPaths[1], NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH)); 656 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: INF 2: %s"), apInfFullPaths[1]); 657 } 658 else 659 { 660 if (uErr != ERROR_SUCCESS) 661 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x"), uErr); 662 else 663 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: Empty installation directory")); 664 } 665 } 649 static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize) 650 { 651 DWORD dwBuf = dwSize - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH)); 652 UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &dwBuf); 653 if ( uErr == ERROR_SUCCESS 654 && dwBuf) 655 { 656 wcscpy(pwszMpInf, pwszPtInf); 657 658 wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH)); 659 logStringW(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf); 660 661 wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH)); 662 logStringW(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf); 663 } 664 else if (uErr != ERROR_SUCCESS) 665 logStringW(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr); 666 666 else 667 667 { 668 uErr = ERROR_BUFFER_OVERFLOW;669 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: Buffer array size is < 2 (%u)"), *pcInfs);668 logStringW(hModule, L"vboxNetFltQueryInfArray: Empty installation directory"); 669 uErr = ERROR_GEN_FAILURE; 670 670 } 671 671 … … 687 687 __try 688 688 { 689 LogStringW(hModule, TEXT("Uninstalling NetFlt"));689 logStringW(hModule, L"Uninstalling NetFlt"); 690 690 691 691 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); … … 694 694 HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg); 695 695 if (hr != S_OK) 696 LogStringW(hModule, TEXT("UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x"), hr);697 698 uErr = ErrorConvertFromHResult(hModule, hr);696 logStringW(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr); 697 698 uErr = errorConvertFromHResult(hModule, hr); 699 699 700 700 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 701 701 702 LogStringW(hModule, TEXT("Uninstalling NetFlt done, error = 0x%x"), uErr);702 logStringW(hModule, L"Uninstalling NetFlt done, error = 0x%x", uErr); 703 703 704 704 /* Never fail on uninstall. */ … … 706 706 } 707 707 else 708 LogStringW(hModule, TEXT("UninstallNetFlt: doNetCfgInit failed, error = 0x%x"), uErr);708 logStringW(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr); 709 709 } 710 710 __finally … … 736 736 { 737 737 738 LogStringW(hModule, TEXT("Installing NetFlt"));738 logStringW(hModule, L"Installing NetFlt"); 739 739 740 740 uErr = doNetCfgInit(hModule, &pNetCfg, TRUE); 741 741 if (uErr == ERROR_SUCCESS) 742 742 { 743 WCHAR PtInf[MAX_PATH]; 744 WCHAR MpInf[MAX_PATH]; 745 DWORD sz = sizeof(PtInf); 746 LPWSTR aInfs[] = {PtInf, MpInf}; 747 UINT cInfs = 2; 748 uErr = vboxNetFltQueryInfArray(hModule, aInfs, &cInfs, sz); 743 WCHAR wszPtInf[MAX_PATH]; 744 WCHAR wszMpInf[MAX_PATH]; 745 uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, wszMpInf, sizeof(wszMpInf)); 749 746 if (uErr == ERROR_SUCCESS) 750 747 { 751 HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, (LPCWSTR*)aInfs, cInfs); 748 LPCWSTR const apwszInfs[] = { wszPtInf, wszMpInf }; 749 HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs)); 752 750 if (FAILED(hr)) 753 LogStringW(hModule, TEXT("InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x"), hr);754 755 uErr = ErrorConvertFromHResult(hModule, hr);751 logStringW(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr); 752 753 uErr = errorConvertFromHResult(hModule, hr); 756 754 } 757 755 else 758 LogStringW(hModule, TEXT("InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x"), uErr);756 logStringW(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x", uErr); 759 757 760 758 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 761 759 762 LogStringW(hModule, TEXT("Installing NetFlt done"));760 logStringW(hModule, L"Installing NetFlt done"); 763 761 } 764 762 else 765 LogStringW(hModule, TEXT("InstallNetFlt: doNetCfgInit failed, error = 0x%x"), uErr);763 logStringW(hModule, L"InstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr); 766 764 } 767 765 __finally … … 822 820 if (SUCCEEDED(hr)) 823 821 { 824 hr = VBoxNetCfgWinRenameConnection 822 hr = VBoxNetCfgWinRenameConnection(guid, ConnectoinName); 825 823 NonStandardAssert(hr == S_OK); 826 824 } … … 846 844 bool bSetStaticIp = true; 847 845 848 LogStringW(hModule, TEXT("Creating host-only interface"));846 logStringW(hModule, L"Creating host-only interface"); 849 847 850 848 HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID); 851 849 if (FAILED(hr)) 852 850 { 853 LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, error = 0x%x"), hr);851 logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, error = 0x%x", hr); 854 852 bSetStaticIp = false; 855 853 } … … 865 863 if (cSize) 866 864 { 867 LogStringW(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property = %s"), MpInf);865 logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", MpInf); 868 866 if (MpInf[cSize-1] != L'\\') 869 867 { … … 878 876 bIsFile = true; 879 877 880 LogStringW(hModule, TEXT("CreateHostOnlyInterface: Resulting INF path = %s"), pInfPath);878 logStringW(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pInfPath); 881 879 } 882 880 else 883 LogStringW(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property value is empty"));881 logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property value is empty"); 884 882 } 885 883 else 886 LogStringW(hModule, TEXT("CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x"), uErr);884 logStringW(hModule, L"CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x", uErr); 887 885 888 886 /* Make sure the inf file is installed. */ … … 891 889 hr = VBoxDrvCfgInfInstall(pInfPath); 892 890 if (FAILED(hr)) 893 LogStringW(hModule, TEXT("CreateHostOnlyInterface: Failed to install INF file, error = 0x%x"), hr);891 logStringW(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = 0x%x", hr); 894 892 } 895 893 … … 903 901 hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask); 904 902 if (FAILED(hr)) 905 LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x"), hr);903 logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr); 906 904 } 907 905 else 908 LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x"), hr);906 logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr); 909 907 } 910 908 911 909 if (SUCCEEDED(hr)) 912 LogStringW(hModule, TEXT("Creating host-only interface done"));910 logStringW(hModule, L"Creating host-only interface done"); 913 911 914 912 /* Restore original setup mode. */ … … 929 927 netCfgLoggerEnable(hModule); 930 928 931 LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: Removing All Host-Only Interface"));929 logStringW(hModule, L"RemoveHostOnlyInterfaces: Removing All Host-Only Interface"); 932 930 933 931 BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE); … … 939 937 if (FAILED(hr)) 940 938 { 941 LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n"));939 logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n"); 942 940 } 943 941 } 944 942 else 945 LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x\n"), hr);943 logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x\n", hr); 946 944 947 945 /* Restore original setup mode. */ … … 956 954 } 957 955 958 static bool IsTAPDevice(const TCHAR *pcGUID)956 static bool isTAPDevice(const WCHAR *pwszGUID) 959 957 { 960 958 HKEY hNetcard; 961 959 bool bIsTapDevice = false; 962 LONG lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,963 TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"),964 0, KEY_READ, &hNetcard);960 LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 961 L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 962 0, KEY_READ, &hNetcard); 965 963 if (lStatus != ERROR_SUCCESS) 966 964 return false; 967 965 968 966 int i = 0; 969 while (true)970 { 971 TCHARszEnumName[256];972 TCHARszNetCfgInstanceId[256];967 for (;;) 968 { 969 WCHAR wszEnumName[256]; 970 WCHAR wszNetCfgInstanceId[256]; 973 971 DWORD dwKeyType; 974 972 HKEY hNetCardGUID; 975 973 976 DWORD dwLen = sizeof( szEnumName);977 lStatus = RegEnumKeyEx(hNetcard, i, szEnumName, &dwLen, NULL, NULL, NULL, NULL);974 DWORD dwLen = sizeof(wszEnumName); 975 lStatus = RegEnumKeyEx(hNetcard, i, wszEnumName, &dwLen, NULL, NULL, NULL, NULL); 978 976 if (lStatus != ERROR_SUCCESS) 979 977 break; 980 978 981 lStatus = RegOpenKeyEx(hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);979 lStatus = RegOpenKeyEx(hNetcard, wszEnumName, 0, KEY_READ, &hNetCardGUID); 982 980 if (lStatus == ERROR_SUCCESS) 983 981 { 984 dwLen = sizeof( szNetCfgInstanceId);985 lStatus = RegQueryValueEx (hNetCardGUID, TEXT("NetCfgInstanceId"), NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &dwLen);982 dwLen = sizeof(wszNetCfgInstanceId); 983 lStatus = RegQueryValueExW(hNetCardGUID, L"NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)wszNetCfgInstanceId, &dwLen); 986 984 if ( lStatus == ERROR_SUCCESS 987 985 && dwKeyType == REG_SZ) 988 986 { 989 TCHARszNetProductName[256];990 TCHARszNetProviderName[256];991 992 szNetProductName[0] = 0;993 dwLen = sizeof( szNetProductName);994 lStatus = RegQueryValueEx (hNetCardGUID, TEXT("ProductName"), NULL, &dwKeyType, (LPBYTE)szNetProductName, &dwLen);995 996 szNetProviderName[0] = 0;997 dwLen = sizeof( szNetProviderName);998 lStatus = RegQueryValueEx (hNetCardGUID, TEXT("ProviderName"), NULL, &dwKeyType, (LPBYTE)szNetProviderName, &dwLen);999 1000 if ( !wcscmp( szNetCfgInstanceId, pcGUID)1001 && !wcscmp( szNetProductName, TEXT("VirtualBox TAP Adapter"))1002 && ( (!wcscmp( szNetProviderName, TEXT("innotek GmbH"))) /* Legacy stuff. */1003 || (!wcscmp( szNetProviderName, TEXT("Sun Microsystems, Inc."))) /* Legacy stuff. */1004 || (!wcscmp( szNetProviderName,TEXT(VBOX_VENDOR))) /* Reflects current vendor string. */987 WCHAR wszNetProductName[256]; 988 WCHAR wszNetProviderName[256]; 989 990 wszNetProductName[0] = 0; 991 dwLen = sizeof(wszNetProductName); 992 lStatus = RegQueryValueExW(hNetCardGUID, L"ProductName", NULL, &dwKeyType, (LPBYTE)wszNetProductName, &dwLen); 993 994 wszNetProviderName[0] = 0; 995 dwLen = sizeof(wszNetProviderName); 996 lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen); 997 998 if ( !wcscmp(wszNetCfgInstanceId, pwszGUID) 999 && !wcscmp(wszNetProductName, L"VirtualBox TAP Adapter") 1000 && ( (!wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */ 1001 || (!wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */ 1002 || (!wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */ 1005 1003 ) 1006 1004 ) … … 1016 1014 } 1017 1015 1018 RegCloseKey 1016 RegCloseKey(hNetcard); 1019 1017 return bIsTapDevice; 1020 1018 } 1021 1022 #define VBOX_TAP_HWID _T("vboxtap")1023 1019 1024 1020 #define SetErrBreak(strAndArgs) \ 1025 1021 if (1) { \ 1026 1022 rc = 0; \ 1027 LogStringW(hModule, strAndArgs); \1023 logStringW(hModule, strAndArgs); \ 1028 1024 break; \ 1029 1025 } else do {} while (0) 1030 1026 1031 int removeNetworkInterface(MSIHANDLE hModule, const TCHAR* pcGUID)1027 int removeNetworkInterface(MSIHANDLE hModule, const WCHAR *pwszGUID) 1032 1028 { 1033 1029 int rc = 1; 1034 1030 do 1035 1031 { 1036 TCHAR lszPnPInstanceId[512] = {0};1032 WCHAR wszPnPInstanceId[512] = {0}; 1037 1033 1038 1034 /* We have to find the device instance ID through a registry search */ … … 1041 1037 HKEY hkeyConnection = 0; 1042 1038 1043 do 1044 { 1045 TCHAR strRegLocation [256]; 1046 swprintf (strRegLocation, 1047 TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\") 1048 TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s"), 1049 pcGUID); 1050 LONG lStatus; 1051 lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegLocation, 0, 1052 KEY_READ, &hkeyNetwork); 1039 do /* break-loop */ 1040 { 1041 WCHAR wszRegLocation[256]; 1042 swprintf(wszRegLocation, 1043 L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", 1044 pwszGUID); 1045 LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork); 1053 1046 if ((lStatus != ERROR_SUCCESS) || !hkeyNetwork) 1054 SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]"), strRegLocation)); 1055 1056 lStatus = RegOpenKeyExA(hkeyNetwork, "Connection", 0, 1057 KEY_READ, &hkeyConnection); 1047 SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", wszRegLocation)); 1048 1049 lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection); 1058 1050 if ((lStatus != ERROR_SUCCESS) || !hkeyConnection) 1059 SetErrBreak(( TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]"), strRegLocation));1060 1061 DWORD len = sizeof (lszPnPInstanceId);1051 SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", wszRegLocation)); 1052 1053 DWORD len = sizeof(wszPnPInstanceId); 1062 1054 DWORD dwKeyType; 1063 1055 lStatus = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, 1064 &dwKeyType, (LPBYTE) lszPnPInstanceId, &len);1056 &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len); 1065 1057 if ((lStatus != ERROR_SUCCESS) || (dwKeyType != REG_SZ)) 1066 SetErrBreak(( TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]"), strRegLocation));1058 SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", wszRegLocation)); 1067 1059 } 1068 1060 while (0); … … 1099 1091 if (hDeviceInfo == INVALID_HANDLE_VALUE) 1100 1092 { 1101 LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!"), GetLastError());1102 SetErrBreak( TEXT("VBox HostInterfaces: Uninstallation failed!"));1093 logStringW(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError()); 1094 SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!"); 1103 1095 } 1104 1096 … … 1108 1100 while (TRUE) 1109 1101 { 1110 TCHAR *pszDeviceHwid;1102 WCHAR *pwszDeviceHwid; 1111 1103 1112 1104 fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData); … … 1138 1130 } 1139 1131 1140 p szDeviceHwid = (TCHAR *)malloc(size);1141 if (p szDeviceHwid)1132 pwszDeviceHwid = (WCHAR *)malloc(size); 1133 if (pwszDeviceHwid) 1142 1134 { 1143 1135 fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo, … … 1145 1137 SPDRP_HARDWAREID, 1146 1138 NULL, 1147 (PBYTE)p szDeviceHwid,1139 (PBYTE)pwszDeviceHwid, 1148 1140 size, 1149 1141 NULL); 1150 1142 if (!fResult) 1151 1143 { 1152 free(p szDeviceHwid);1153 p szDeviceHwid = NULL;1144 free(pwszDeviceHwid); 1145 pwszDeviceHwid = NULL; 1154 1146 index++; 1155 1147 continue; … … 1164 1156 } 1165 1157 1166 for ( TCHAR *t = pszDeviceHwid;1167 t && *t && t < &p szDeviceHwid[size / sizeof(TCHAR)];1168 t += _tcslen(t) + 1)1158 for (WCHAR *t = pwszDeviceHwid; 1159 t && *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)]; 1160 t += wcslen(t) + 1) 1169 1161 { 1170 if (!_ tcsicmp(VBOX_TAP_HWID, t))1162 if (!_wcsicmp(L"vboxtap", t)) 1171 1163 { 1172 1164 /* get the device instance ID */ 1173 TCHAR devID[MAX_DEVICE_ID_LEN];1165 WCHAR wszDevID[MAX_DEVICE_ID_LEN]; 1174 1166 if (CM_Get_Device_ID(DeviceInfoData.DevInst, 1175 devID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)1167 wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS) 1176 1168 { 1177 1169 /* compare to what we determined before */ 1178 if (!wcscmp( devID, lszPnPInstanceId))1170 if (!wcscmp(wszDevID, wszPnPInstanceId)) 1179 1171 { 1180 1172 fFoundDevice = TRUE; … … 1185 1177 } 1186 1178 1187 if (p szDeviceHwid)1179 if (pwszDeviceHwid) 1188 1180 { 1189 free(p szDeviceHwid);1190 p szDeviceHwid = NULL;1181 free(pwszDeviceHwid); 1182 pwszDeviceHwid = NULL; 1191 1183 } 1192 1184 … … 1202 1194 if (!fResult) 1203 1195 { 1204 LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!"), GetLastError());1205 SetErrBreak( TEXT("VBox HostInterfaces: Uninstallation failed!"));1196 logStringW(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError()); 1197 SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!"); 1206 1198 } 1207 1199 … … 1209 1201 if (!fResult) 1210 1202 { 1211 LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!"), GetLastError());1212 SetErrBreak( TEXT("VBox HostInterfaces: Uninstallation failed!"));1203 logStringW(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError()); 1204 SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!"); 1213 1205 } 1214 1206 } 1215 1207 else 1216 SetErrBreak( TEXT("VBox HostInterfaces: Host interface network device not found!"));1208 SetErrBreak(L"VBox HostInterfaces: Host interface network device not found!"); 1217 1209 } 1218 1210 while (0); … … 1228 1220 UINT __stdcall UninstallTAPInstances(MSIHANDLE hModule) 1229 1221 { 1230 static const TCHAR *NetworkKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\") 1231 TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}"); 1222 static const WCHAR *s_wszNetworkKey = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; 1232 1223 HKEY hCtrlNet; 1233 1224 1234 LONG lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,NetworkKey, 0, KEY_READ, &hCtrlNet);1225 LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet); 1235 1226 if (lStatus == ERROR_SUCCESS) 1236 1227 { 1237 LogStringW(hModule, TEXT("VBox HostInterfaces: Enumerating interfaces ...")); 1238 for (int i = 0;; ++ i) 1239 { 1240 TCHAR szNetworkGUID [256] = { 0 }; 1241 TCHAR szNetworkConnection [256] = { 0 }; 1242 1243 DWORD dwLen = (DWORD)sizeof(szNetworkGUID); 1244 lStatus = RegEnumKeyEx(hCtrlNet, i, szNetworkGUID, &dwLen, NULL, NULL, NULL, NULL); 1228 logStringW(hModule, L"VBox HostInterfaces: Enumerating interfaces ..."); 1229 for (int i = 0; ; ++i) 1230 { 1231 WCHAR wszNetworkGUID[256] = { 0 }; 1232 DWORD dwLen = (DWORD)sizeof(wszNetworkGUID); 1233 lStatus = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL); 1245 1234 if (lStatus != ERROR_SUCCESS) 1246 1235 { 1247 1236 switch (lStatus) 1248 1237 { 1249 case ERROR_NO_MORE_ITEMS:1250 LogStringW(hModule, TEXT("VBox HostInterfaces: No interfaces found."));1251 break;1252 default:1253 LogStringW(hModule, TEXT("VBox HostInterfaces: Enumeration failed: %ld"), lStatus);1254 break;1255 } ;1238 case ERROR_NO_MORE_ITEMS: 1239 logStringW(hModule, L"VBox HostInterfaces: No interfaces found."); 1240 break; 1241 default: 1242 logStringW(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus); 1243 break; 1244 } 1256 1245 break; 1257 1246 } 1258 1247 1259 if ( IsTAPDevice(szNetworkGUID))1248 if (isTAPDevice(wszNetworkGUID)) 1260 1249 { 1261 LogStringW(hModule, TEXT("VBox HostInterfaces: Removing interface \"%s\" ..."),szNetworkGUID);1262 removeNetworkInterface (hModule,szNetworkGUID);1263 lStatus = RegDeleteKey (hCtrlNet,szNetworkGUID);1250 logStringW(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID); 1251 removeNetworkInterface(hModule, wszNetworkGUID); 1252 lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID); 1264 1253 } 1265 1254 } 1266 RegCloseKey 1267 LogStringW(hModule, TEXT("VBox HostInterfaces: Removing interfaces done."));1255 RegCloseKey(hCtrlNet); 1256 logStringW(hModule, L"VBox HostInterfaces: Removing interfaces done."); 1268 1257 } 1269 1258 return ERROR_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.