VirtualBox

Changeset 37765 in vbox for trunk/src


Ignore:
Timestamp:
Jul 4, 2011 1:54:00 PM (13 years ago)
Author:
vboxsync
Message:

Windows host installer: Fixed automated VBox Python API installation.

Location:
trunk/src/VBox/Installer/win
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp

    r37289 r37765  
    6363static void LogString(MSIHANDLE hInstall, LPCSTR szString, ...)
    6464{
    65     PMSIHANDLE newHandle = ::MsiCreateRecord(2);
     65    PMSIHANDLE newHandle = MsiCreateRecord(2);
    6666
    6767    char szBuffer[1024] = {0};
     
    8282static void LogStringW(MSIHANDLE hInstall, LPCWSTR szString, ...)
    8383{
    84     PMSIHANDLE newHandle = ::MsiCreateRecord(2);
     84    PMSIHANDLE newHandle = MsiCreateRecord(2);
    8585
    8686    TCHAR szBuffer[1024] = {0};
     
    111111}
    112112
    113 DWORD Exec(MSIHANDLE hModule, TCHAR* szAppName, TCHAR* szCmdLine, TCHAR* szWorkDir, DWORD* dwExitCode)
     113DWORD Exec(MSIHANDLE hModule,
     114           const TCHAR *pszAppName, TCHAR *pszCmdLine, const TCHAR *pszWorkDir,
     115           DWORD *pdwExitCode)
    114116{
    115117    STARTUPINFO si;
     
    117119    DWORD rc = ERROR_SUCCESS;
    118120
    119     ::ZeroMemory(&si, sizeof(si));
     121    ZeroMemory(&si, sizeof(si));
    120122    si.dwFlags = STARTF_USESHOWWINDOW;
    121123#ifdef UNICODE
     
    124126    si.wShowWindow = SW_HIDE; /* For debugging: SW_SHOW; */
    125127    si.cb = sizeof(si);
    126     ::ZeroMemory(&pi, sizeof(pi));
     128    ZeroMemory(&pi, sizeof(pi));
    127129
    128130    LogStringW(hModule, TEXT("Executing command line: %s %s (Working Dir: %s)"),
    129                szAppName, szCmdLine, szWorkDir == NULL ? L"Current" : szWorkDir);
    130 
    131     ::SetLastError(0);
    132     if (!::CreateProcess(szAppName,    /* Module name. */
    133                          szCmdLine,    /* Command line. */
    134                          NULL,         /* Process handle not inheritable. */
    135                          NULL,         /* Thread handle not inheritable. */
    136                          FALSE,        /* Set handle inheritance to FALSE .*/
    137                          0,            /* No creation flags. */
    138                          NULL,         /* Use parent's environment block. */
    139                          szWorkDir,    /* Use parent's starting directory. */
    140                          &si,          /* Pointer to STARTUPINFO structure. */
    141                          &pi))         /* Pointer to PROCESS_INFORMATION structure. */
    142     {
    143         rc = ::GetLastError();
     131               pszAppName, pszCmdLine, pszWorkDir == NULL ? L"Current" : pszWorkDir);
     132
     133    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. */
     144    {
     145        rc = GetLastError();
    144146        LogStringW(hModule, TEXT("Executing command line: CreateProcess() failed! Error: %ld"), rc);
    145147        return rc;
     
    147149
    148150    /* Wait until child process exits. */
    149     if (WAIT_FAILED == ::WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
    150     {
    151         rc = ::GetLastError();
     151    if (WAIT_FAILED == WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
     152    {
     153        rc = GetLastError();
    152154        LogStringW(hModule, TEXT("Executing command line: WaitForSingleObject() failed! Error: %ld"), rc);
    153155    }
    154156    else
    155157    {
    156         if (0 == ::GetExitCodeProcess(pi.hProcess, dwExitCode))
    157         {
    158             rc = ::GetLastError();
     158        if (!GetExitCodeProcess(pi.hProcess, pdwExitCode))
     159        {
     160            rc = GetLastError();
    159161            LogStringW(hModule, TEXT("Executing command line: GetExitCodeProcess() failed! Error: %ld"), rc);
    160162        }
     
    162164
    163165    /* Close process and thread handles. */
    164     ::CloseHandle(pi.hProcess);
    165     ::CloseHandle(pi.hThread);
    166 
    167     LogStringW(hModule, TEXT("Executing command returned: %ld (exit code %ld)"), rc, *dwExitCode);
     166    CloseHandle(pi.hProcess);
     167    CloseHandle(pi.hThread);
     168
     169    LogStringW(hModule, TEXT("Executing command returned: %ld (exit code %ld)"), rc, *pdwExitCode);
    168170    return rc;
    169171}
     
    175177    HKEY hkPythonCore = NULL;
    176178    BOOL bFound = FALSE;
    177     LONG rc = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
     179    LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
    178180    if (rc != ERROR_SUCCESS)
    179181    {
     
    191193        DWORD dwKeyType = REG_SZ;
    192194
    193         rc = ::RegEnumKeyEx(hkPythonCore, i, szRoot, &dwLen, NULL, NULL, NULL, NULL);
     195        rc = RegEnumKeyEx(hkPythonCore, i, szRoot, &dwLen, NULL, NULL, NULL, NULL);
    194196        if (rc != ERROR_SUCCESS || dwLen <= 0)
    195197            break;
     
    199201
    200202        HKEY hkPythonInstPath = NULL;
    201         rc = ::RegOpenKeyEx(hkPythonCore, szPath, 0, KEY_READ,  &hkPythonInstPath);
     203        rc = RegOpenKeyEx(hkPythonCore, szPath, 0, KEY_READ,  &hkPythonInstPath);
    202204        if (rc != ERROR_SUCCESS)
    203205            continue;
    204206
    205         rc = ::RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)szVal, &dwLen);
     207        rc = RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)szVal, &dwLen);
    206208        if (rc == ERROR_SUCCESS)
    207209            LogStringW(hModule, TEXT("InstallPythonAPI: Path \"%s\" detected."), szVal);
    208210
    209         ::RegCloseKey(hkPythonInstPath);
    210     }
    211     ::RegCloseKey(hkPythonCore);
     211        RegCloseKey(hkPythonInstPath);
     212    }
     213    RegCloseKey(hkPythonCore);
    212214
    213215    /* Python path found? */
     
    215217    TCHAR szCmdLine[MAX_PATH] = { 0 };
    216218    DWORD dwExitCode = 0;
    217     if (::_tcslen(szVal) > 0)
     219    if (_tcslen(szVal) > 0)
    218220    {
    219221        /* Cool, check for installed Win32 extensions. */
     
    222224        _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe -c \"import win32api\"", szVal);
    223225
    224         if (   (0 == Exec(hModule, szExec, szCmdLine, NULL, &dwExitCode))
    225             && (0 == dwExitCode))
     226        DWORD dwRetExec = Exec(hModule, szExec, szCmdLine, NULL, &dwExitCode);
     227        if (   (ERROR_SUCCESS == dwRetExec)
     228            && (            0 == dwExitCode))
    226229        {
    227230            /* Did we get the correct error level (=0)? */
     
    229232            bFound = TRUE;
    230233        }
    231         else LogStringW(hModule, TEXT("InstallPythonAPI: Win32 extensions not found."));
     234        else
     235            LogStringW(hModule, TEXT("InstallPythonAPI: Win32 extensions not found."));
    232236    }
    233237
     
    236240    {
    237241        /* Get the VBoxAPI setup string. */
    238         TCHAR szVBoxAPISetupPath[MAX_PATH] = {0};
    239         VBoxGetProperty(hModule, L"INSTALLDIR", szVBoxAPISetupPath, sizeof(szVBoxAPISetupPath));
    240 
    241         /* Set final path. */
    242         _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\sdk\\install", szVBoxAPISetupPath);
    243 
    244         /* Install our API module. */
    245         _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe vboxapisetup.py install", szVal);
    246 
    247         /* Set required environment variables. */
    248         if (!SetEnvironmentVariable(L"VBOX_INSTALL_PATH", szVBoxAPISetupPath))
    249         {
    250             LogStringW(hModule, TEXT("InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!"));
     242        TCHAR szPathTargetDir[MAX_PATH] = {0};
     243        VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));
     244        if (_tcslen(szPathTargetDir))
     245        {
     246
     247            /* Set final path. */
     248            _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\sdk\\install", szPathTargetDir);
     249
     250            /* Install our API module. */
     251            _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe vboxapisetup.py install", szVal);
     252
     253            /* 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            }
     258            else
     259            {
     260                DWORD dwRetExec = Exec(hModule, szExec, szCmdLine, szPath, &dwExitCode);
     261                if (   (ERROR_SUCCESS == dwRetExec)
     262                    && (            0 == dwExitCode))
     263                {
     264                    /* All done! */
     265                    LogStringW(hModule, TEXT("InstallPythonAPI: VBoxAPI for Python successfully installed."));
     266                    bInstalled = TRUE;
     267                }
     268                else
     269                {
     270                    if (dwRetExec)
     271                        LogStringW(hModule, TEXT("InstallPythonAPI: Error while executing installation of VBox API: %ld"), dwRetExec);
     272                    else
     273                        LogStringW(hModule, TEXT("InstallPythonAPI: Python reported an error while installing VBox API: %ld"), dwExitCode);
     274                }
     275            }
    251276        }
    252277        else
    253         {
    254             if (   (0 == Exec(hModule, szExec, szCmdLine, szPath, &dwExitCode))
    255                 && (0 == dwExitCode))
    256             {
    257                 /* All done! */
    258                 LogStringW(hModule, TEXT("InstallPythonAPI: VBoxAPI for Python successfully installed."));
    259                 bInstalled = TRUE;
    260             }
    261             else
    262                 LogStringW(hModule, TEXT("InstallPythonAPI: Error while installing VBox API: %ld"), dwExitCode);
    263         }
     278            LogStringW(hModule, TEXT("InstallPythonAPI: Unable to retrieve VBox installation path!"));
    264279    }
    265280
     
    409424    TCHAR szPathDest[_MAX_PATH];
    410425
    411     rc = VBoxGetProperty(hModule, L"INSTALLDIR", szPathTargetDir, sizeof(szPathTargetDir));
     426    rc = VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));
    412427    if (rc == ERROR_SUCCESS)
    413428    {
     
    441456    if (rc == ERROR_SUCCESS)
    442457    {
    443         rc = VBoxGetProperty(hModule, L"INSTALLDIR", szPathTargetDir, sizeof(szPathTargetDir));
     458        rc = VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));
    444459        if (rc == ERROR_SUCCESS)
    445460        {
  • trunk/src/VBox/Installer/win/VirtualBox.wxs

    r37549 r37765  
    162162        <Binary Id="VBoxInstallHelper" SourceFile="$(env.PATH_OUT)\bin\VBoxInstallHelper.dll" />
    163163        <CustomAction Id="ca_CheckSerial" BinaryKey="VBoxInstallHelper" DllEntry="CheckSerial" Impersonate="no"/>
    164         <CustomAction Id="ca_InstallPythonAPI" BinaryKey="VBoxInstallHelper" DllEntry="InstallPythonAPI" Execute="deferred" Impersonate="no"/>
    165         <CustomAction Id="ca_InstallBranding" BinaryKey="VBoxInstallHelper" DllEntry="InstallBranding" Execute="deferred" Impersonate="no"/>
    166         <CustomAction Id="ca_UninstallBranding" BinaryKey="VBoxInstallHelper" DllEntry="UninstallBranding" Execute="deferred" Impersonate="no"/>
     164
     165        <CustomAction Id="ca_InstallPythonAPI" BinaryKey="VBoxInstallHelper" DllEntry="InstallPythonAPI" Execute="deferred" Return="check" Impersonate="no"/>
     166        <CustomAction Id="ca_InstallPythonAPIArgs" Property="ca_InstallPythonAPI" Value="[INSTALLDIR]" Execute="immediate"/>
     167
     168        <CustomAction Id="ca_InstallBranding" BinaryKey="VBoxInstallHelper" DllEntry="InstallBranding" Execute="deferred" Return="check" Impersonate="no"/>
     169        <CustomAction Id="ca_InstallBrandingArgs" Property="ca_InstallBranding" Value="[INSTALLDIR]" Execute="immediate"/>
     170
     171        <CustomAction Id="ca_UninstallBranding" BinaryKey="VBoxInstallHelper" DllEntry="UninstallBranding" Execute="deferred" Return="check" Impersonate="no"/>
     172        <CustomAction Id="ca_UninstallBrandingArgs" Property="ca_UninstallBranding" Value="[INSTALLDIR]" Execute="immediate"/>
    167173
    168174        <CustomAction Id="ca_UninstallTAPInstances" BinaryKey="VBoxInstallHelper"
     
    170176
    171177<?if $(env.VBOX_WITH_NETFLT) = "yes" ?>
     178        <CustomAction Id="ca_CreateHostOnlyInterface"  BinaryKey="VBoxInstallHelper"  DllEntry="CreateHostOnlyInterface" Execute="deferred" Return="check" Impersonate="no"/>
    172179        <CustomAction Id="ca_CreateHostOnlyInterfaceArgs" Property="ca_CreateHostOnlyInterface" Value="[INSTALLDIR]" Execute="immediate"/>
    173         <CustomAction Id="ca_CreateHostOnlyInterface"  BinaryKey="VBoxInstallHelper"  DllEntry="CreateHostOnlyInterface" Execute="deferred" Return="check" Impersonate="no"/>
    174180
    175181        <CustomAction Id="ca_RemoveHostOnlyInterfaces" BinaryKey="VBoxInstallHelper"  DllEntry="RemoveHostOnlyInterfaces" Execute="deferred" Return="check" Impersonate="no"/>
     
    724730
    725731<?if $(env.VBOX_WITH_PYTHON) = "yes" ?>
    726             <Feature Id="ft_VBoxPython" Title="VirtualBox Python Support" Level="1"
     732            <Feature Id="ft_VBoxPython" Title="VirtualBox Python 2.x Support" Level="1"
    727733                    Description="!(loc.VB_Python)"
    728734                    ConfigurableDirectory="INSTALLDIR" TypicalDefault="install" Display="expand" >
     
    762768            <Custom Action="ca_UninstallNetFlt" After="InstallInitialize" ><![CDATA[&ft_VBoxNetworkFlt=2]]></Custom>
    763769<?endif?>
     770            <Custom Action="ca_InstallPythonAPIArgs" Before="ca_InstallPythonAPI" ><![CDATA[&ft_VBoxPython=3]]></Custom>
    764771            <Custom Action="ca_InstallPythonAPI" Before="InstallFinalize" ><![CDATA[&ft_VBoxPython=3]]></Custom>
     772
     773            <Custom Action="ca_InstallBrandingArgs" Before="ca_InstallBranding" ><![CDATA[NOT REMOVE]]></Custom>
    765774            <Custom Action="ca_InstallBranding" Before="InstallFinalize" ><![CDATA[NOT REMOVE]]></Custom>
     775
     776            <Custom Action="ca_UninstallBrandingArgs" Before="ca_UninstallBranding" ><![CDATA[REMOVE]]></Custom>
    766777            <Custom Action="ca_UninstallBranding" Before="InstallFinalize" ><![CDATA[REMOVE]]></Custom>
    767778
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette