Ignore:
Timestamp:
11/13/2008 2:19:55 PM (4 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)

File:
1 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; 
Note: See TracChangeset for help on using the changeset viewer.