Changeset 544 for branches/eraser6/Installer/Bootstrapper/Bootstrapper.cpp
- Timestamp:
- 11/13/2008 2:19:55 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Installer/Bootstrapper/Bootstrapper.cpp
r543 r544 45 45 }; 46 46 47 int 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 47 96 /// ISzInStream interface for extracting the archives. 48 97 struct LZFileStream … … 58 107 FileHandle = fileHandle; 59 108 60 FileRead = FileRead =0;109 FileRead = 0; 61 110 LARGE_INTEGER largeInt; 62 111 largeInt.QuadPart = 0; 63 112 if (!SetFilePointerEx(FileHandle, largeInt, &largeInt, FILE_CURRENT)) 64 113 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)) 69 117 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; 75 119 } 76 120 … … 84 128 private: 85 129 HANDLE FileHandle; 130 long long DataOffset; 86 131 long long FileRead; 87 132 long long FileSize; … … 95 140 //of memory and stop. 96 141 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]; 98 146 99 147 DWORD readSize = 0; … … 116 164 117 165 LARGE_INTEGER value; 118 value.LowPart = (DWORD)pos; 119 value.HighPart = (LONG)((UInt64)pos >> 32); 166 value.QuadPart = pos + s->DataOffset; 120 167 if (!SetFilePointerEx(s->FileHandle, value, NULL, FILE_BEGIN) && 121 168 GetLastError() != NO_ERROR) … … 132 179 //Open the file 133 180 #if _DEBUG 134 H andle 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); 136 183 if (srcFile == INVALID_HANDLE_VALUE) 137 184 throw GetErrorMessage(GetLastError()); 138 185 #else 139 H andle 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); 141 188 if (srcFile == INVALID_HANDLE_VALUE) 142 189 throw GetErrorMessage(GetLastError()); 143 190 144 //Seek to the 1 28th kb.191 //Seek to the 196th kb. 145 192 LARGE_INTEGER fPos; 146 193 fPos.QuadPart = DataOffset;
Note: See TracChangeset
for help on using the changeset viewer.
