Ignore:
Timestamp:
11/13/2008 10:27:23 AM (4 years ago)
Author:
lowjoel
Message:

Implemented .NET framework and Eraser installation steps.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Installer/Bootstrapper/Bootstrapper.cpp

    r535 r536  
    227227} 
    228228 
    229 void InstallNetFramework() 
    230 { 
    231 } 
     229int CreateProcessAndWait(const std::wstring& commandLine) 
     230{ 
     231    //Get a mutable version of the command line 
     232    wchar_t* cmdLine = new wchar_t[commandLine.length() + 1]; 
     233    wcscpy(cmdLine, commandLine.c_str()); 
     234 
     235    //Launch the process 
     236    STARTUPINFOW startupInfo; 
     237    PROCESS_INFORMATIONW pInfo; 
     238    ::ZeroMemory(&startupInfo, sizeof(startupInfo)); 
     239    ::ZeroMemory(&pInfo, sizeof(pInfo)); 
     240    if (!CreateProcessW(NULL, cmdLine, NULL, NULL, false, 0, NULL,  NULL, &startupInfo, 
     241        &pInfo)) 
     242    { 
     243        delete[] cmdLine; 
     244        throw GetErrorMessage(GetLastError()); 
     245    } 
     246    delete[] cmdLine; 
     247 
     248    //Ok the process was created, wait for it to terminate. 
     249    DWORD lastWait = 0; 
     250    while ((lastWait = WaitForSingleObject(pInfo.hProcess, 50)) == WAIT_TIMEOUT) 
     251        Yield(); 
     252    if (lastWait == WAIT_ABANDONED) 
     253        throw std::wstring(L"The condition waiting on the termination of the .NET installer was abandoned."); 
     254 
     255    //Get the exit code 
     256    DWORD exitCode = 0; 
     257    if (!GetExitCodeProcess(pInfo.hProcess, &exitCode)) 
     258        throw GetErrorMessage(GetLastError()); 
     259 
     260    //Clean up 
     261    CloseHandle(pInfo.hProcess); 
     262    CloseHandle(pInfo.hThread); 
     263 
     264    //Return the exit code. 
     265    return exitCode; 
     266} 
     267 
     268bool InstallNetFramework(std::wstring tempDir) 
     269{ 
     270    //Update the UI 
     271    SetProgressIndeterminate(); 
     272    SetMessage(L"Installing .NET Framework..."); 
     273 
     274    //Get the path to the installer 
     275    if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1])) 
     276        tempDir += L"\\"; 
     277    std::wstring commandLine('"' + tempDir); 
     278    commandLine += L"dotnetfx.exe\""; 
     279 
     280    //And the return code is true if the process exited with 0. 
     281    return CreateProcessAndWait(commandLine) == 0; 
     282} 
     283 
     284bool InstallEraser(std::wstring tempDir) 
     285{ 
     286    SetProgressIndeterminate(); 
     287    SetMessage(L"Installing Eraser..."); 
     288 
     289    //Determine the system architecture. 
     290    SYSTEM_INFO sysInfo; 
     291    ZeroMemory(&sysInfo, sizeof(sysInfo)); 
     292    sysInfo.cbSize = sizeof(sysInfo); 
     293    GetSystemInfo(&sysInfo); 
     294 
     295    if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1])) 
     296        tempDir += L"\\"; 
     297    switch (sysInfo.wProcessorArchitecture) 
     298    { 
     299    case PROCESSOR_ARCHITECTURE_AMD64: 
     300        tempDir += L"Eraser (x64).msi"; 
     301        break; 
     302 
     303    default: 
     304        tempDir += L"Eraser (x86).msi"; 
     305        break; 
     306    } 
     307 
     308    std::wstring commandLine(L"msiexec.exe /i "); 
     309    commandLine += '"' + tempDir + '"'; 
     310     
     311    //And the return code is true if the process exited with 0. 
     312    return CreateProcessAndWait(commandLine) == 0; 
     313} 
Note: See TracChangeset for help on using the changeset viewer.