Changeset 544


Ignore:
Timestamp:
11/13/2008 2:19:55 PM (6 years ago)
Author:
lowjoel
Message:

Implemented the final bit of the installer where the data is appended to the bootstrapper. Use --integrate (source 7z) and --out (installer)

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

Legend:

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

    r543 r544  
    4545}; 
    4646 
     47int Integrate(const std::wstring& destItem, const std::wstring& package) 
     48{ 
     49    //Open a handle to ourselves 
     50    Handle srcFile(CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
     51        FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
     52    if (srcFile == INVALID_HANDLE_VALUE) 
     53        throw GetErrorMessage(GetLastError()); 
     54 
     55    //Copy ourselves, in essence. 
     56    Handle destFile(CreateFileW(destItem.c_str(), GENERIC_WRITE, 0, NULL, 
     57        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
     58    if (destFile == INVALID_HANDLE_VALUE) 
     59        throw GetErrorMessage(GetLastError()); 
     60 
     61    DWORD lastOperation = 0; 
     62    //char buffer[262144]; 
     63    char* buffer = new char[2621440]; 
     64    unsigned bufsize = 2621440; 
     65    while (ReadFile(srcFile, buffer, bufsize, &lastOperation, NULL) && lastOperation) 
     66        WriteFile(destFile, buffer, lastOperation, &lastOperation, NULL); 
     67 
     68    //Fill to the predetermined file position 
     69    int amountToWrite = DataOffset - GetFileSize(srcFile, NULL); 
     70    if (amountToWrite < 0) 
     71        throw std::wstring(L"The file size of the binary is larger than the data " 
     72            L"offset position; recompile the package, increasing DataOffset."); 
     73    ZeroMemory(buffer, bufsize); 
     74    while (amountToWrite > 0) 
     75    { 
     76        WriteFile(destFile, buffer, std::min<unsigned>(amountToWrite, bufsize), 
     77            &lastOperation, NULL); 
     78        amountToWrite -= lastOperation; 
     79    } 
     80 
     81    //Then copy the package 
     82    Handle packageFile(CreateFileW(package.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, 
     83        OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
     84    if (packageFile == INVALID_HANDLE_VALUE) 
     85        throw GetErrorMessage(GetLastError()); 
     86    int error; 
     87    SetLastError(0); 
     88    while (ReadFile(packageFile, buffer, bufsize, &lastOperation, NULL) && lastOperation) 
     89    { 
     90        WriteFile(destFile, buffer, lastOperation, &lastOperation, NULL); 
     91        error = GetLastError(); 
     92    } 
     93    return 0; 
     94} 
     95 
    4796/// ISzInStream interface for extracting the archives. 
    4897struct LZFileStream 
     
    58107        FileHandle = fileHandle; 
    59108 
    60         FileRead = FileRead = 0; 
     109        FileRead = 0; 
    61110        LARGE_INTEGER largeInt; 
    62111        largeInt.QuadPart = 0; 
    63112        if (!SetFilePointerEx(FileHandle, largeInt, &largeInt, FILE_CURRENT)) 
    64113            throw GetErrorMessage(GetLastError()); 
    65  
    66         long long currPos = largeInt.QuadPart; 
    67         largeInt.QuadPart = 0; 
    68         if (!SetFilePointerEx(FileHandle, largeInt, &largeInt, FILE_END)) 
     114        DataOffset = largeInt.QuadPart; 
     115 
     116        if (!GetFileSizeEx(fileHandle, &largeInt)) 
    69117            throw GetErrorMessage(GetLastError()); 
    70         FileSize = largeInt.QuadPart - currPos; 
    71  
    72         largeInt.QuadPart = currPos; 
    73         if (!SetFilePointerEx(FileHandle, largeInt, NULL, FILE_BEGIN)) 
    74             throw GetErrorMessage(GetLastError()); 
     118        FileSize = largeInt.QuadPart - DataOffset; 
    75119    } 
    76120 
     
    84128private: 
    85129    HANDLE FileHandle; 
     130    long long DataOffset; 
    86131    long long FileRead; 
    87132    long long FileSize; 
     
    95140        //of memory and stop. 
    96141        size = std::min(1048576u * 4, size); 
    97         char* buffer = new char[size]; 
     142        static char* buffer = NULL; 
     143        if (buffer) 
     144            delete[] buffer; 
     145        buffer = new char[size]; 
    98146 
    99147        DWORD readSize = 0; 
     
    116164 
    117165        LARGE_INTEGER value; 
    118         value.LowPart = (DWORD)pos; 
    119         value.HighPart = (LONG)((UInt64)pos >> 32); 
     166        value.QuadPart = pos + s->DataOffset; 
    120167        if (!SetFilePointerEx(s->FileHandle, value, NULL, FILE_BEGIN) && 
    121168            GetLastError() != NO_ERROR) 
     
    132179    //Open the file 
    133180#if _DEBUG 
    134     Handle srcFile(CreateFileW((Application::Get().GetPath() + L".7z").c_str(), 
    135         GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
     181    HANDLE srcFile = CreateFileW((Application::Get().GetPath() + L".7z").c_str(), 
     182        GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
    136183    if (srcFile == INVALID_HANDLE_VALUE) 
    137184        throw GetErrorMessage(GetLastError()); 
    138185#else 
    139     Handle srcFile(CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
    140         FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
     186    HANDLE srcFile = CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
     187        FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
    141188    if (srcFile == INVALID_HANDLE_VALUE) 
    142189        throw GetErrorMessage(GetLastError()); 
    143190 
    144     //Seek to the 128th kb. 
     191    //Seek to the 196th kb. 
    145192    LARGE_INTEGER fPos; 
    146193    fPos.QuadPart = DataOffset; 
  • branches/eraser6/Installer/Bootstrapper/Bootstrapper.h

    r543 r544  
    138138std::wstring GetErrorMessage(DWORD lastError); 
    139139 
     140/// Integrates the distribution package to the installer. 
     141int Integrate(const std::wstring& destItem, const std::wstring& package); 
     142 
    140143/// Extracts the setup files to the users' temporary folder. 
    141144///  
  • branches/eraser6/Installer/Bootstrapper/Main.cpp

    r543 r544  
    9898 
    9999int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, 
    100                        LPTSTR /*lpCmdLine*/, int /*nCmdShow*/) 
    101 { 
    102     //Create the parent window and the child controls 
    103     ::hInstance = hInstance; 
    104     Application::Get(); 
    105  
     100                       LPTSTR lpCmdLine, int /*nCmdShow*/) 
     101{ 
    106102    try 
    107103    { 
     104        //Parse the command line. 
     105        int argc = 0; 
     106        LPWSTR* argv = CommandLineToArgvW(lpCmdLine, & argc); 
     107        if (argv == NULL) 
     108            throw GetErrorMessage(GetLastError()); 
     109 
     110        for (int i = 0; i != argc; ++i) 
     111        { 
     112            if (wcscmp(argv[i], L"--integrate") == 0) 
     113            { 
     114                //OK, integrate ourselves. 
     115                std::wstring destItem, package; 
     116                if (++i != argc) 
     117                    package = argv[i]; 
     118 
     119                for (++i; i < argc; ++i) 
     120                { 
     121                    std::wstring arg(argv[i]); 
     122                    if (arg.substr(0, 9) == L"--out") 
     123                    { 
     124                        if (++i != argc) 
     125                            destItem = argv[i]; 
     126                    } 
     127                } 
     128 
     129                if (!destItem.empty() && !package.empty()) 
     130                    return Integrate(destItem, package); 
     131            } 
     132        } 
     133 
     134        //Create the parent window and the child controls 
     135        ::hInstance = hInstance; 
     136        Application::Get(); 
     137 
    108138        //OK, now we do the hard work. Create a folder to place our payload into 
    109139        wchar_t tempPath[MAX_PATH]; 
  • branches/eraser6/Installer/Bootstrapper/stdafx.h

    r542 r544  
    3131#include <windows.h> 
    3232#include <commctrl.h> 
     33#include <Shellapi.h> 
    3334 
    3435#include <tchar.h> 
Note: See TracChangeset for help on using the changeset viewer.