Changeset 537


Ignore:
Timestamp:
11/13/08 10:54:09 (6 years ago)
Author:
lowjoel
Message:

-Fixed Yield
-Fixed the TempDir? destructor
-Added exception handlers to Main, since it can't throw
-Few warning fixes

Location:
branches/eraser6/Installer/Bootstrapper
Files:
2 edited

Legend:

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

    r536 r537  
    8282            s->FileRead += readSize; 
    8383 
    84             SetProgress((double)s->FileRead / s->FileSize); 
     84            SetProgress((float)((double)s->FileRead / s->FileSize)); 
    8585        } 
    8686 
     
    104104void ExtractTempFiles(std::wstring pathToExtract) 
    105105{ 
    106     if (std::wstring(L"\\/").find(pathToExtract[pathToExtract.length() - 1])) 
     106    if (std::wstring(L"\\/").find(pathToExtract[pathToExtract.length() - 1]) == std::wstring::npos) 
    107107        pathToExtract += L"\\"; 
    108108 
     
    159159 
    160160        //Create the output file 
     161        size_t convertedChars = 0; 
    161162        wchar_t fileName[MAX_PATH]; 
    162         mbstowcs(fileName, f->Name, sizeof(fileName) / sizeof(fileName[0])); 
     163        mbstowcs_s(&convertedChars, fileName, f->Name, sizeof(fileName) / sizeof(fileName[0])); 
    163164        HANDLE destFile = CreateFileW((pathToExtract + fileName).c_str(), GENERIC_WRITE, 0, 
    164165            NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
     
    231232    //Get a mutable version of the command line 
    232233    wchar_t* cmdLine = new wchar_t[commandLine.length() + 1]; 
    233     wcscpy(cmdLine, commandLine.c_str()); 
     234    wcscpy_s(cmdLine, commandLine.length() + 1, commandLine.c_str()); 
    234235 
    235236    //Launch the process 
    236237    STARTUPINFOW startupInfo; 
    237     PROCESS_INFORMATIONW pInfo; 
     238    PROCESS_INFORMATION pInfo; 
    238239    ::ZeroMemory(&startupInfo, sizeof(startupInfo)); 
    239240    ::ZeroMemory(&pInfo, sizeof(pInfo)); 
     
    273274 
    274275    //Get the path to the installer 
    275     if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1])) 
     276    if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 
    276277        tempDir += L"\\"; 
    277     std::wstring commandLine('"' + tempDir); 
     278    std::wstring commandLine(L'"' + tempDir); 
    278279    commandLine += L"dotnetfx.exe\""; 
    279280 
     
    290291    SYSTEM_INFO sysInfo; 
    291292    ZeroMemory(&sysInfo, sizeof(sysInfo)); 
    292     sysInfo.cbSize = sizeof(sysInfo); 
    293293    GetSystemInfo(&sysInfo); 
    294294 
    295     if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1])) 
     295    if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 
    296296        tempDir += L"\\"; 
    297297    switch (sysInfo.wProcessorArchitecture) 
     
    307307 
    308308    std::wstring commandLine(L"msiexec.exe /i "); 
    309     commandLine += '"' + tempDir + '"'; 
     309    commandLine += L'"' + tempDir + L'"'; 
    310310     
    311311    //And the return code is true if the process exited with 0. 
  • branches/eraser6/Installer/Bootstrapper/Main.cpp

    r536 r537  
    5757            : DirName(dirName) 
    5858        { 
     59            if (std::wstring(L"\\/").find(dirName[dirName.length() - 1]) == std::wstring::npos) 
     60                dirName += L"\\"; 
     61 
    5962            if (!CreateDirectoryW(dirName.c_str(), NULL)) 
    6063                throw GetErrorMessage(GetLastError()); 
     
    6467        { 
    6568            //Clean up the files in the directory. 
    66  
    67  
     69            WIN32_FIND_DATAW findData; 
     70            ZeroMemory(&findData, sizeof(findData)); 
     71            HANDLE findHandle = FindFirstFileW((DirName + L"*").c_str(), &findData); 
     72            if (findHandle == INVALID_HANDLE_VALUE) 
     73                throw GetErrorMessage(GetLastError()); 
     74 
     75            //Delete! 
     76            do 
     77                DeleteFileW((DirName + findData.cFileName).c_str()); 
     78            while (FindNextFileW(findHandle, &findData)); 
     79 
     80            //Clean up. 
     81            FindClose(findHandle); 
    6882            RemoveDirectoryW(DirName.c_str()); 
    6983        } 
     
    155169        } 
    156170 
    157         case WM_PAINT: 
    158         { 
    159             PAINTSTRUCT ps; 
    160             HDC hdc = BeginPaint(hWnd, &ps); 
    161  
    162             // TODO: Add any drawing code here... 
    163             EndPaint(hWnd, &ps); 
    164             break; 
    165         } 
    166  
    167171        case WM_DESTROY: 
    168172            PostQuitMessage(0); 
     
    207211    UpdateWindow(hWndParent); 
    208212 
    209     //OK, now we do the hard work. Create a folder to place our payload into 
    210     wchar_t tempPath[MAX_PATH]; 
    211     DWORD result = GetTempPathW(sizeof(tempPath) / sizeof(tempPath[0]), tempPath); 
    212     if (!result) 
    213         throw GetErrorMessage(GetLastError()); 
    214  
    215     std::wstring tempDir(tempPath, result); 
    216     if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 
    217         tempDir += L"\\"; 
    218     tempDir += L"eraserInstallBootstrapper\\"; 
    219     TempDir dir(tempDir); 
    220     ExtractTempFiles(tempDir); 
    221  
    222     //Install the .NET framework 
    223     if (!HasNetFramework()) 
    224         InstallNetFramework(tempDir); 
    225  
    226     //Then install Eraser! 
    227     InstallEraser(); 
    228  
    229     //Main message loop 
    230     MSG msg; 
    231     while (GetMessage(&msg, NULL, 0, 0)) 
    232     { 
    233         TranslateMessage(&msg); 
    234         DispatchMessage(&msg); 
    235     } 
    236  
    237     return (int) msg.wParam; 
     213    try 
     214    { 
     215        //OK, now we do the hard work. Create a folder to place our payload into 
     216        wchar_t tempPath[MAX_PATH]; 
     217        DWORD result = GetTempPathW(sizeof(tempPath) / sizeof(tempPath[0]), tempPath); 
     218        if (!result) 
     219            throw GetErrorMessage(GetLastError()); 
     220 
     221        std::wstring tempDir(tempPath, result); 
     222        if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 
     223            tempDir += L"\\"; 
     224        tempDir += L"eraserInstallBootstrapper\\"; 
     225        TempDir dir(tempDir); 
     226        ExtractTempFiles(tempDir); 
     227 
     228        //Install the .NET framework 
     229        if (!HasNetFramework()) 
     230            InstallNetFramework(tempDir); 
     231 
     232        //Then install Eraser! 
     233        InstallEraser(tempDir); 
     234    } 
     235    catch (const std::wstring& e) 
     236    { 
     237        MessageBoxW(GetTopWindow(), e.c_str(), L"Eraser Setup", MB_OK | MB_ICONERROR); 
     238    } 
     239 
     240    return 0; 
    238241} 
    239242 
     
    265268    MSG msg; 
    266269    while (PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && msg.message != WM_QUIT) 
    267     { 
     270    { 
     271        if (GetMessageW(&msg, NULL, 0, 0) == 0) 
     272            return; 
     273 
    268274        TranslateMessage(&msg); 
    269275        DispatchMessage(&msg); 
    270     } 
     276    } 
    271277} 
    272278 
Note: See TracChangeset for help on using the changeset viewer.