~ubuntu-branches/ubuntu/precise/virtualbox/precise-updates

« back to all changes in this revision

Viewing changes to src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-10-17 23:23:09 UTC
  • mfrom: (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20111017232309-kzm6841lzk61ranj
Tags: 4.1.4-dfsg-1
* New upstream release.
  - Fixes missing icons when using pt_BR locale. (Closes: #507188)
  - Fixes guest additions download url. (Closes: #637349; LP: #840668)
* Refresh patches.
* Drop the vboxmouse x11 driver. The mouse integration is now completely
  handled by the kernel module.
* Restrict dh_pycentral to the virtualbox binary package.
* Merge changes from the Ubuntu package but use them only when built
  on Ubuntu:
  - Add an Apport hook.
  - Add vboxguest modalias to the package control field.
* Pass KBUILD_VERBOSE=2 to kmk.
* Add 36-fix-text-mode.patch to fix text mode when using the vboxvideo driver.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: VBoxInstallHelper.cpp 37765 2011-07-04 13:54:00Z vboxsync $ */
 
1
/* $Id: VBoxInstallHelper.cpp $ */
2
2
/** @file
3
3
 * VBoxInstallHelper - Various helper routines for Windows host installer.
4
4
 */
15
15
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16
16
 */
17
17
 
 
18
 
 
19
/*******************************************************************************
 
20
*   Header Files                                                               *
 
21
*******************************************************************************/
18
22
#ifdef VBOX_WITH_NETFLT
19
23
# include "VBox/VBoxNetCfg-win.h"
20
24
# include "VBox/VBoxDrvCfg-win.h"
23
27
#include <VBox/version.h>
24
28
 
25
29
#include <windows.h>
26
 
#include <tchar.h>
 
30
#include <wchar.h>
27
31
#include <stdio.h>
28
32
 
29
33
#include <msi.h>
47
51
# include "internal/VBoxSerial.h"
48
52
#endif
49
53
 
 
54
 
 
55
/*******************************************************************************
 
56
*   Header Files                                                               *
 
57
*******************************************************************************/
50
58
#ifdef DEBUG
51
59
# define Assert(_expr) assert(_expr)
52
60
#else
53
61
# define Assert(_expr) do{ }while(0)
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,
58
70
                      LPVOID lpReserved)
60
72
    return TRUE;
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);
74
86
    MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
75
87
    MsiCloseHandle(newHandle);
76
88
 
77
 
#ifdef DEBUG
 
89
#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, LPCWSTR szString, ...)
 
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);
93
105
    MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
111
123
}
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
{
117
 
    STARTUPINFO si;
 
129
    STARTUPINFOW si;
118
130
    PROCESS_INFORMATION pi;
119
131
    DWORD rc = ERROR_SUCCESS;
120
132
 
127
139
    si.cb = sizeof(si);
128
140
    ZeroMemory(&pi, sizeof(pi));
129
141
 
130
 
    LogStringW(hModule, TEXT("Executing command line: %s %s (Working Dir: %s)"),
131
 
               pszAppName, 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(pszAppName,    /* Module name. */
135
 
                       pszCmdLine,    /* Command line. */
136
 
                       NULL,         /* Process handle not inheritable. */
137
 
                       NULL,         /* Thread handle not inheritable. */
138
 
                       FALSE,        /* Set handle inheritance to FALSE .*/
139
 
                       0,            /* No creation flags. */
140
 
                       NULL,         /* Use parent's environment block. */
141
 
                       pszWorkDir,    /* Use parent's starting directory. */
142
 
                       &si,          /* Pointer to STARTUPINFO structure. */
143
 
                       &pi))         /* Pointer to PROCESS_INFORMATION structure. */
 
146
    if (!CreateProcessW(pwszAppName,  /* Module name. */
 
147
                        pwszCmdLine,  /* Command line. */
 
148
                        NULL,         /* Process handle not inheritable. */
 
149
                        NULL,         /* Thread handle not inheritable. */
 
150
                        FALSE,        /* Set handle inheritance to FALSE .*/
 
151
                        0,            /* No creation flags. */
 
152
                        NULL,         /* Use parent's environment block. */
 
153
                        pwszWorkDir,  /* Use parent's starting directory. */
 
154
                        &si,          /* Pointer to STARTUPINFO structure. */
 
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
    }
149
161
 
151
163
    if (WAIT_FAILED == WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
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
157
169
    {
158
170
        if (!GetExitCodeProcess(pi.hProcess, pdwExitCode))
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
    }
164
176
 
166
178
    CloseHandle(pi.hProcess);
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
}
172
184
 
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;
178
190
    BOOL bFound = FALSE;
179
 
    LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
 
191
    LONG rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
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
 
    TCHAR szPath[MAX_PATH] = { 0 };
187
 
    TCHAR szVal[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
 
        TCHAR szRoot[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 = RegEnumKeyExW(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 = RegOpenKeyExW(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 = RegQueryValueExW(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);
212
224
    }
213
225
    RegCloseKey(hkPythonCore);
214
226
 
215
227
    /* Python path found? */
216
 
    TCHAR szExec[MAX_PATH] = { 0 };
217
 
    TCHAR szCmdLine[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);
 
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);
225
237
 
226
 
        DWORD dwRetExec = Exec(hModule, szExec, szCmdLine, NULL, &dwExitCode);
 
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
 
238
250
    BOOL bInstalled = FALSE;
239
251
    if (bFound) /* Is Python and all required stuff installed? */
240
252
    {
241
253
        /* Get the VBoxAPI setup string. */
242
 
        TCHAR szPathTargetDir[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
                }
268
278
                else
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
 
281
291
    VBoxSetProperty(hModule, L"PYTHON_INSTALLED", bInstalled ? L"1" : L"0");
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
 
    TCHAR szValue[_MAX_PATH];
295
 
    if (GetPrivateProfileString(pszSection, pszValue, NULL,
296
 
                                szValue, sizeof(szValue), pszFileName) > 0)
 
304
    WCHAR wszValue[_MAX_PATH];
 
305
    if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL,
 
306
                                 wszValue, sizeof(wszValue), pwszFileName) > 0)
297
307
    {
298
308
        HKEY hkBranding;
299
 
        TCHAR szKey[_MAX_PATH];
 
309
        WCHAR wszKey[_MAX_PATH];
300
310
 
301
 
        if (wcsicmp(L"General", pszSection) != 0)
302
 
            _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pszSection);
 
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);
 
314
            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
305
315
 
306
 
        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey,
307
 
                          0, KEY_WRITE, &hkBranding);
 
316
        rc = RegOpenKeyExW(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
        }
320
329
    }
323
332
    return rc;
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
 
    TCHAR szDest[_MAX_PATH + 1];
330
 
    TCHAR szSource[_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');
334
 
 
335
 
    SHFILEOPSTRUCT s = {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');
 
343
 
 
344
    SHFILEOPSTRUCTW 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 |
342
351
               FOF_NOCONFIRMMKDIR |
343
352
               FOF_NOERRORUI;
344
353
 
345
 
    LogStringW(hModule, TEXT("CopyDir: DestDir=%s, SourceDir=%s"),
346
 
              szDest, szSource);
347
 
    int r = SHFileOperation(&s);
 
354
    logStringW(hModule, L"CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
 
355
    int r = SHFileOperationW(&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
    }
353
361
    else
355
363
    return rc;
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
 
    TCHAR szDest[_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
 
               FOF_NOERRORUI;
 
376
    s.pFrom = wszDest;
 
377
    s.fFlags = FOF_SILENT
 
378
             | FOF_NOCONFIRMATION
 
379
             | FOF_NOCONFIRMMKDIR
 
380
             | FOF_NOERRORUI;
373
381
 
374
 
    LogStringW(hModule, TEXT("RemoveDir: DestDir=%s"), szDest);
375
 
    int r = SHFileOperation(&s);
 
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
    }
381
389
    else
383
391
    return rc;
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
 
    TCHAR szDest[_MAX_PATH + 1];
390
 
    TCHAR szSource[_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;
 
406
    s.pTo = wszDest;
 
407
    s.pFrom = wszSource;
 
408
    s.fFlags = FOF_SILENT
 
409
             | FOF_NOCONFIRMATION
 
410
             | FOF_NOCONFIRMMKDIR
 
411
             | FOF_NOERRORUI;
404
412
 
405
 
    LogStringW(hModule, TEXT("RenameDir: DestDir=%s, SourceDir=%s"),
406
 
              szDest, szSource);
407
 
    int r = SHFileOperation(&s);
 
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
    }
413
420
    else
418
425
UINT __stdcall UninstallBranding(MSIHANDLE hModule)
419
426
{
420
427
    UINT rc;
421
 
    LogStringW(hModule, TEXT("UninstallBranding: Handling branding file ..."));
422
 
 
423
 
    TCHAR szPathTargetDir[_MAX_PATH];
424
 
    TCHAR szPathDest[_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);
 
448
            swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s.custom", wszPathTargetDir);
 
449
            rc = RemoveDir(hModule, wszPathDest);
437
450
        }
438
451
    }
439
452
 
440
 
    LogStringW(hModule, TEXT("UninstallBranding: Handling done."));
 
453
    logStringW(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);
441
454
    return ERROR_SUCCESS; /* Do not fail here. */
442
455
}
443
456
 
444
457
UINT __stdcall InstallBranding(MSIHANDLE hModule)
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
}
477
489
 
490
502
static VOID netCfgLoggerCallback(LPCSTR szString)
491
503
{
492
504
    if (g_hCurrentModule)
493
 
        LogString(g_hCurrentModule, szString);
 
505
        logString(g_hCurrentModule, szString);
494
506
}
495
507
 
496
508
static VOID netCfgLoggerDisable()
514
526
    VBoxNetCfgWinSetLogging((LOG_ROUTINE)netCfgLoggerCallback);
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;
520
532
    switch (hr)
525
537
 
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 = MsiSetPropertyW(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;
534
546
        }
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
    }
540
552
    return uRet;
548
560
        UINT uErr = MsiRecordSetInteger(hRecord, 1, 25001);
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;
554
566
        }
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;
560
572
}
573
585
        if (hr != NETCFG_E_NO_WRITE_LOCK)
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
        }
580
592
 
582
594
 
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
        }
588
600
 
596
608
            && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
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
        }
602
614
        else
606
618
                hMsg = createNetCfgLockedMsgRecord(hModule);
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;
612
624
                }
616
628
            Assert(rTmp == ERROR_SUCCESS);
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;
622
634
            }
623
635
 
624
636
            MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
625
637
            Assert(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);
629
641
    } while(MsgResult == IDRETRY);
634
646
    return uErr;
635
647
}
636
648
 
637
 
static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR *apInfFullPaths, PUINT pcInfs, DWORD dwSize)
 
649
static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize)
638
650
{
639
 
    UINT uErr;
640
 
    if (*pcInfs >= 2)
 
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)
641
655
    {
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
 
        }
 
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);
665
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
 
672
672
    return uErr;
686
686
 
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);
692
692
        if (uErr == ERROR_SUCCESS)
693
693
        {
694
694
            HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg);
695
695
            if (hr != S_OK)
696
 
                LogStringW(hModule, TEXT("UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x"), hr);
 
696
                logStringW(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);
697
697
 
698
 
            uErr = ErrorConvertFromHResult(hModule, hr);
 
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. */
705
705
            uErr = ERROR_SUCCESS;
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
711
711
    {
735
735
    __try
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);
 
751
                    logStringW(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr);
754
752
 
755
 
                uErr = ErrorConvertFromHResult(hModule, hr);
 
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
768
766
    {
821
819
                Assert(hr == S_OK);
822
820
                if (SUCCEEDED(hr))
823
821
                {
824
 
                    hr = VBoxNetCfgWinRenameConnection (guid, ConnectoinName);
 
822
                    hr = VBoxNetCfgWinRenameConnection(guid, ConnectoinName);
825
823
                    Assert(hr == S_OK);
826
824
                }
827
825
            }
845
843
    BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
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
    }
856
854
 
857
855
    GUID guid;
858
 
    WCHAR MpInf[MAX_PATH];
859
 
    DWORD cSize = sizeof(MpInf)/sizeof(MpInf[0]);
860
 
    LPCWSTR pInfPath = NULL;
 
856
    WCHAR wszMpInf[MAX_PATH];
 
857
    DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - sizeof("drivers\\network\\netadp\\VBoxNetAdp.inf") - 1;
 
858
    LPCWSTR pwszInfPath = NULL;
861
859
    bool bIsFile = false;
862
 
    UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", MpInf, &cSize);
 
860
    UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
863
861
    if (uErr == ERROR_SUCCESS)
864
862
    {
865
 
        if (cSize)
 
863
        if (cchMpInf)
866
864
        {
867
 
            LogStringW(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property = %s"), MpInf);
868
 
            if (MpInf[cSize-1] != L'\\')
 
865
            logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf);
 
866
            if (wszMpInf[cchMpInf - 1] != L'\\')
869
867
            {
870
 
                MpInf[cSize] = L'\\';
871
 
                ++cSize;
872
 
                MpInf[cSize] = L'\0';
 
868
                wszMpInf[cchMpInf++] = L'\\';
 
869
                wszMpInf[cchMpInf]   = L'\0';
873
870
            }
874
871
 
875
 
            /** @todo r=andy Avoid wcscat, can cause buffer overruns! */
876
 
            wcscat(MpInf, L"drivers\\network\\netadp\\VBoxNetAdp.inf");
877
 
            pInfPath = MpInf;
 
872
            wcscat(wszMpInf, L"drivers\\network\\netadp\\VBoxNetAdp.inf");
 
873
            pwszInfPath = wszMpInf;
878
874
            bIsFile = true;
879
875
 
880
 
            LogStringW(hModule, TEXT("CreateHostOnlyInterface: Resulting INF path = %s"), pInfPath);
 
876
            logStringW(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath);
881
877
        }
882
878
        else
883
 
            LogStringW(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property value is empty"));
 
879
            logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property value is empty");
884
880
    }
885
881
    else
886
 
        LogStringW(hModule, TEXT("CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x"), uErr);
 
882
        logStringW(hModule, L"CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x", uErr);
887
883
 
888
884
    /* Make sure the inf file is installed. */
889
 
    if (!!pInfPath && bIsFile)
 
885
    if (pwszInfPath != NULL && bIsFile)
890
886
    {
891
 
        hr = VBoxDrvCfgInfInstall(pInfPath);
 
887
logStringW(hModule, L"CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath);
 
888
        hr = VBoxDrvCfgInfInstall(pwszInfPath);
 
889
logStringW(hModule, L"CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns 0x%x", hr);
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
 
896
894
    if (SUCCEEDED(hr))
897
895
    {
898
 
        hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsFile, &guid, NULL, NULL);
 
896
logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");
 
897
        hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, bIsFile, &guid, NULL, NULL);
 
898
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr);
899
899
        if (SUCCEEDED(hr))
900
900
        {
901
901
            ULONG ip = inet_addr("192.168.56.1");
902
902
            ULONG mask = inet_addr("255.255.255.0");
 
903
logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");
903
904
            hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
 
905
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns 0x%x", hr);
904
906
            if (FAILED(hr))
905
 
                LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x"), hr);
 
907
                logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr);
906
908
        }
907
909
        else
908
 
            LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x"), hr);
 
910
            logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr);
909
911
    }
910
912
 
911
913
    if (SUCCEEDED(hr))
912
 
        LogStringW(hModule, TEXT("Creating host-only interface done"));
 
914
        logStringW(hModule, L"Creating host-only interface done");
913
915
 
914
916
    /* Restore original setup mode. */
 
917
logStringW(hModule, L"CreateHostOnlyInterface: almost done...");
915
918
    if (bSetupModeInteractive)
916
919
        SetupSetNonInteractiveMode(bSetupModeInteractive);
917
920
 
919
922
 
920
923
#endif /* VBOX_WITH_NETFLT */
921
924
 
 
925
logStringW(hModule, L"CreateHostOnlyInterface: returns success (ignoring all failures)");
922
926
    /* Never fail the install even if we did not succeed. */
923
927
    return ERROR_SUCCESS;
924
928
}
928
932
#ifdef VBOX_WITH_NETFLT
929
933
    netCfgLoggerEnable(hModule);
930
934
 
931
 
    LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: Removing All Host-Only Interface"));
 
935
    logStringW(hModule, L"RemoveHostOnlyInterfaces: Removing All Host-Only Interface");
932
936
 
933
937
    BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
934
938
 
938
942
        hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, NETADP_ID, L"Net", 0/* could be SUOI_FORCEDELETE */);
939
943
        if (FAILED(hr))
940
944
        {
941
 
            LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n"));
 
945
            logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n");
942
946
        }
943
947
    }
944
948
    else
945
 
        LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x\n"), hr);
 
949
        logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x\n", hr);
946
950
 
947
951
    /* Restore original setup mode. */
948
952
    if (bSetupModeInteractive)
955
959
    return ERROR_SUCCESS;
956
960
}
957
961
 
958
 
static bool IsTAPDevice(const TCHAR *pcGUID)
 
962
static bool isTAPDevice(const WCHAR *pwszGUID)
959
963
{
960
964
    HKEY hNetcard;
961
965
    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);
 
966
    LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
 
967
                                 L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",
 
968
                                 0, KEY_READ, &hNetcard);
965
969
    if (lStatus != ERROR_SUCCESS)
966
970
        return false;
967
971
 
968
972
    int i = 0;
969
 
    while (true)
 
973
    for (;;)
970
974
    {
971
 
        TCHAR szEnumName[256];
972
 
        TCHAR szNetCfgInstanceId[256];
 
975
        WCHAR wszEnumName[256];
 
976
        WCHAR wszNetCfgInstanceId[256];
973
977
        DWORD dwKeyType;
974
978
        HKEY  hNetCardGUID;
975
979
 
976
 
        DWORD dwLen = sizeof(szEnumName);
977
 
        lStatus = RegEnumKeyEx(hNetcard, i, szEnumName, &dwLen, NULL, NULL, NULL, NULL);
 
980
        DWORD dwLen = sizeof(wszEnumName);
 
981
        lStatus = RegEnumKeyExW(hNetcard, i, wszEnumName, &dwLen, NULL, NULL, NULL, NULL);
978
982
        if (lStatus != ERROR_SUCCESS)
979
983
            break;
980
984
 
981
 
        lStatus = RegOpenKeyEx(hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);
 
985
        lStatus = RegOpenKeyExW(hNetcard, wszEnumName, 0, KEY_READ, &hNetCardGUID);
982
986
        if (lStatus == ERROR_SUCCESS)
983
987
        {
984
 
            dwLen = sizeof(szNetCfgInstanceId);
985
 
            lStatus = RegQueryValueEx(hNetCardGUID, TEXT("NetCfgInstanceId"), NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &dwLen);
 
988
            dwLen = sizeof(wszNetCfgInstanceId);
 
989
            lStatus = RegQueryValueExW(hNetCardGUID, L"NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)wszNetCfgInstanceId, &dwLen);
986
990
            if (   lStatus == ERROR_SUCCESS
987
991
                && dwKeyType == REG_SZ)
988
992
            {
989
 
                TCHAR szNetProductName[256];
990
 
                TCHAR szNetProviderName[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. */
 
993
                WCHAR wszNetProductName[256];
 
994
                WCHAR wszNetProviderName[256];
 
995
 
 
996
                wszNetProductName[0] = 0;
 
997
                dwLen = sizeof(wszNetProductName);
 
998
                lStatus = RegQueryValueExW(hNetCardGUID, L"ProductName", NULL, &dwKeyType, (LPBYTE)wszNetProductName, &dwLen);
 
999
 
 
1000
                wszNetProviderName[0] = 0;
 
1001
                dwLen = sizeof(wszNetProviderName);
 
1002
                lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen);
 
1003
 
 
1004
                if (   !wcscmp(wszNetCfgInstanceId, pwszGUID)
 
1005
                    && !wcscmp(wszNetProductName, L"VirtualBox TAP Adapter")
 
1006
                    && (   (!wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */
 
1007
                        || (!wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */
 
1008
                        || (!wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
1005
1009
                       )
1006
1010
                   )
1007
1011
                {
1015
1019
        ++i;
1016
1020
    }
1017
1021
 
1018
 
    RegCloseKey (hNetcard);
 
1022
    RegCloseKey(hNetcard);
1019
1023
    return bIsTapDevice;
1020
1024
}
1021
1025
 
1022
 
#define VBOX_TAP_HWID _T("vboxtap")
1023
 
 
1024
1026
#define SetErrBreak(strAndArgs) \
1025
1027
    if (1) { \
1026
1028
        rc = 0; \
1027
 
        LogStringW(hModule, strAndArgs); \
 
1029
        logStringW(hModule, strAndArgs); \
1028
1030
        break; \
1029
1031
    } else do {} while (0)
1030
1032
 
1031
 
int removeNetworkInterface(MSIHANDLE hModule, const TCHAR* pcGUID)
 
1033
int removeNetworkInterface(MSIHANDLE hModule, const WCHAR *pwszGUID)
1032
1034
{
1033
1035
    int rc = 1;
1034
1036
    do
1035
1037
    {
1036
 
        TCHAR lszPnPInstanceId [512] = {0};
 
1038
        WCHAR wszPnPInstanceId[512] = {0};
1037
1039
 
1038
1040
        /* We have to find the device instance ID through a registry search */
1039
1041
 
1040
1042
        HKEY hkeyNetwork = 0;
1041
1043
        HKEY hkeyConnection = 0;
1042
1044
 
1043
 
        do
 
1045
        do /* break-loop */
1044
1046
        {
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);
 
1047
            WCHAR wszRegLocation[256];
 
1048
            swprintf(wszRegLocation,
 
1049
                     L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
 
1050
                     pwszGUID);
 
1051
            LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);
1053
1052
            if ((lStatus != ERROR_SUCCESS) || !hkeyNetwork)
1054
 
                SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]"), strRegLocation));
 
1053
                SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", wszRegLocation));
1055
1054
 
1056
 
            lStatus = RegOpenKeyExA(hkeyNetwork, "Connection", 0,
1057
 
                                    KEY_READ, &hkeyConnection);
 
1055
            lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);
1058
1056
            if ((lStatus != ERROR_SUCCESS) || !hkeyConnection)
1059
 
                SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]"), strRegLocation));
 
1057
                SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", wszRegLocation));
1060
1058
 
1061
 
            DWORD len = sizeof (lszPnPInstanceId);
 
1059
            DWORD len = sizeof(wszPnPInstanceId);
1062
1060
            DWORD dwKeyType;
1063
1061
            lStatus = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL,
1064
 
                                       &dwKeyType, (LPBYTE) lszPnPInstanceId, &len);
 
1062
                                       &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);
1065
1063
            if ((lStatus != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
1066
 
                SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]"), strRegLocation));
 
1064
                SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", wszRegLocation));
1067
1065
        }
1068
1066
        while (0);
1069
1067
 
1098
1096
            hDeviceInfo = SetupDiGetClassDevs(&netGuid, NULL, NULL, DIGCF_PRESENT);
1099
1097
            if (hDeviceInfo == INVALID_HANDLE_VALUE)
1100
1098
            {
1101
 
                LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!"), GetLastError());
1102
 
                SetErrBreak(TEXT("VBox HostInterfaces: Uninstallation failed!"));
 
1099
                logStringW(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());
 
1100
                SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
1103
1101
            }
1104
1102
 
1105
1103
            BOOL fFoundDevice = FALSE;
1107
1105
            /* enumerate the driver info list */
1108
1106
            while (TRUE)
1109
1107
            {
1110
 
                TCHAR *pszDeviceHwid;
 
1108
                WCHAR *pwszDeviceHwid;
1111
1109
 
1112
1110
                fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData);
1113
1111
                if (!fResult)
1137
1135
                        continue;
1138
1136
                    }
1139
1137
 
1140
 
                    pszDeviceHwid = (TCHAR *)malloc(size);
1141
 
                    if (pszDeviceHwid)
 
1138
                    pwszDeviceHwid = (WCHAR *)malloc(size);
 
1139
                    if (pwszDeviceHwid)
1142
1140
                    {
1143
1141
                        fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
1144
1142
                                                                   &DeviceInfoData,
1145
1143
                                                                   SPDRP_HARDWAREID,
1146
1144
                                                                   NULL,
1147
 
                                                                   (PBYTE)pszDeviceHwid,
 
1145
                                                                   (PBYTE)pwszDeviceHwid,
1148
1146
                                                                   size,
1149
1147
                                                                   NULL);
1150
1148
                        if (!fResult)
1151
1149
                        {
1152
 
                            free(pszDeviceHwid);
1153
 
                            pszDeviceHwid = NULL;
 
1150
                            free(pwszDeviceHwid);
 
1151
                            pwszDeviceHwid = NULL;
1154
1152
                            index++;
1155
1153
                            continue;
1156
1154
                        }
1163
1161
                    continue;
1164
1162
                }
1165
1163
 
1166
 
                for (TCHAR *t = pszDeviceHwid;
1167
 
                     t && *t && t < &pszDeviceHwid[size / sizeof(TCHAR)];
1168
 
                     t += _tcslen (t) + 1)
 
1164
                for (WCHAR *t = pwszDeviceHwid;
 
1165
                     t && *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];
 
1166
                     t += wcslen(t) + 1)
1169
1167
                {
1170
 
                    if (!_tcsicmp(VBOX_TAP_HWID, t))
 
1168
                    if (!_wcsicmp(L"vboxtap", t))
1171
1169
                    {
1172
1170
                          /* get the device instance ID */
1173
 
                          TCHAR devID [MAX_DEVICE_ID_LEN];
1174
 
                          if (CM_Get_Device_ID(DeviceInfoData.DevInst,
1175
 
                                               devID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
 
1171
                          WCHAR wszDevID[MAX_DEVICE_ID_LEN];
 
1172
                          if (CM_Get_Device_IDW(DeviceInfoData.DevInst,
 
1173
                                                wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
1176
1174
                          {
1177
1175
                              /* compare to what we determined before */
1178
 
                              if (!wcscmp(devID, lszPnPInstanceId))
 
1176
                              if (!wcscmp(wszDevID, wszPnPInstanceId))
1179
1177
                              {
1180
1178
                                  fFoundDevice = TRUE;
1181
1179
                                  break;
1184
1182
                    }
1185
1183
                }
1186
1184
 
1187
 
                if (pszDeviceHwid)
 
1185
                if (pwszDeviceHwid)
1188
1186
                {
1189
 
                    free(pszDeviceHwid);
1190
 
                    pszDeviceHwid = NULL;
 
1187
                    free(pwszDeviceHwid);
 
1188
                    pwszDeviceHwid = NULL;
1191
1189
                }
1192
1190
 
1193
1191
                if (fFoundDevice)
1201
1199
                fResult = SetupDiSetSelectedDevice(hDeviceInfo, &DeviceInfoData);
1202
1200
                if (!fResult)
1203
1201
                {
1204
 
                    LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!"), GetLastError());
1205
 
                    SetErrBreak(TEXT("VBox HostInterfaces: Uninstallation failed!"));
 
1202
                    logStringW(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
 
1203
                    SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
1206
1204
                }
1207
1205
 
1208
1206
                fResult = SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
1209
1207
                if (!fResult)
1210
1208
                {
1211
 
                    LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!"), GetLastError());
1212
 
                    SetErrBreak(TEXT("VBox HostInterfaces: Uninstallation failed!"));
 
1209
                    logStringW(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
 
1210
                    SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
1213
1211
                }
1214
1212
            }
1215
1213
            else
1216
 
                SetErrBreak(TEXT("VBox HostInterfaces: Host interface network device not found!"));
 
1214
                SetErrBreak(L"VBox HostInterfaces: Host interface network device not found!");
1217
1215
        }
1218
1216
        while (0);
1219
1217
 
1227
1225
 
1228
1226
UINT __stdcall UninstallTAPInstances(MSIHANDLE hModule)
1229
1227
{
1230
 
    static const TCHAR *NetworkKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
1231
 
                                     TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}");
 
1228
    static const WCHAR *s_wszNetworkKey = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
1232
1229
    HKEY hCtrlNet;
1233
1230
 
1234
 
    LONG lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet);
 
1231
    LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);
1235
1232
    if (lStatus == ERROR_SUCCESS)
1236
1233
    {
1237
 
        LogStringW(hModule, TEXT("VBox HostInterfaces: Enumerating interfaces ..."));
1238
 
        for (int i = 0;; ++ i)
 
1234
        logStringW(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");
 
1235
        for (int i = 0; ; ++i)
1239
1236
        {
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);
 
1237
            WCHAR wszNetworkGUID[256] = { 0 };
 
1238
            DWORD dwLen = (DWORD)sizeof(wszNetworkGUID);
 
1239
            lStatus = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
1245
1240
            if (lStatus != ERROR_SUCCESS)
1246
1241
            {
1247
1242
                switch (lStatus)
1248
1243
                {
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
 
                };
 
1244
                    case ERROR_NO_MORE_ITEMS:
 
1245
                        logStringW(hModule, L"VBox HostInterfaces: No interfaces found.");
 
1246
                        break;
 
1247
                    default:
 
1248
                        logStringW(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);
 
1249
                        break;
 
1250
                }
1256
1251
                break;
1257
1252
            }
1258
1253
 
1259
 
            if (IsTAPDevice(szNetworkGUID))
 
1254
            if (isTAPDevice(wszNetworkGUID))
1260
1255
            {
1261
 
                LogStringW(hModule, TEXT("VBox HostInterfaces: Removing interface \"%s\" ..."), szNetworkGUID);
1262
 
                removeNetworkInterface (hModule, szNetworkGUID);
1263
 
                lStatus = RegDeleteKey (hCtrlNet, szNetworkGUID);
 
1256
                logStringW(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);
 
1257
                removeNetworkInterface(hModule, wszNetworkGUID);
 
1258
                lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID);
1264
1259
            }
1265
1260
        }
1266
 
        RegCloseKey (hCtrlNet);
1267
 
        LogStringW(hModule, TEXT("VBox HostInterfaces: Removing interfaces done."));
 
1261
        RegCloseKey(hCtrlNet);
 
1262
        logStringW(hModule, L"VBox HostInterfaces: Removing interfaces done.");
1268
1263
    }
1269
1264
    return ERROR_SUCCESS;
1270
1265
}