diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-04-03 10:21:30 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-04-03 10:21:30 +0200 |
commit | 77761e819506075b28c1b4eaf3fb295cc544c838 (patch) | |
tree | 694123b8a8bf2c70d94b09b44f1dcb576f0127e4 /dep/CascLib/src/common/FileStream.cpp | |
parent | e320ce27c578b21b8611ecfb01084a205790e2e6 (diff) |
Dep/CascLib: Update to ladislav-zezula/CascLib@d477d30f7c2b3a306fd07c92929950639335fb3f
Diffstat (limited to 'dep/CascLib/src/common/FileStream.cpp')
-rw-r--r-- | dep/CascLib/src/common/FileStream.cpp | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/dep/CascLib/src/common/FileStream.cpp b/dep/CascLib/src/common/FileStream.cpp index ef9cc55d7ea..ccd3a65318d 100644 --- a/dep/CascLib/src/common/FileStream.cpp +++ b/dep/CascLib/src/common/FileStream.cpp @@ -70,14 +70,14 @@ static bool BaseFile_Create(TFileStream * pStream) #if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) { intptr_t handle; - + handle = open(pStream->szFileName, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(handle == -1) { SetLastError(errno); return false; } - + pStream->Base.File.hFile = (HANDLE)handle; } #endif @@ -205,7 +205,7 @@ static bool BaseFile_Read( SetLastError(errno); return false; } - + dwBytesRead = (DWORD)(size_t)bytes_read; } } @@ -274,7 +274,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const SetLastError(errno); return false; } - + dwBytesWritten = (DWORD)(size_t)bytes_written; } #endif @@ -321,7 +321,7 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize) return bResult; } #endif - + #if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) { if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1) @@ -329,7 +329,7 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize) SetLastError(errno); return false; } - + pStream->Base.File.FileSize = NewFileSize; return true; } @@ -373,7 +373,7 @@ static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream) SetLastError(errno); return false; } - + return true; #endif } @@ -713,7 +713,7 @@ static bool BaseHttp_Read( // Add range request to the HTTP headers // http://www.clevercomponents.com/articles/article015/resuming.asp _stprintf(szRangeRequest, _T("Range: bytes=%u-%u"), (unsigned int)dwStartOffset, (unsigned int)dwEndOffset); - HttpAddRequestHeaders(hRequest, szRangeRequest, 0xFFFFFFFF, HTTP_ADDREQ_FLAG_ADD_IF_NEW); + HttpAddRequestHeaders(hRequest, szRangeRequest, 0xFFFFFFFF, HTTP_ADDREQ_FLAG_ADD_IF_NEW); // Send the request to the server if(HttpSendRequest(hRequest, NULL, 0, NULL, 0)) @@ -966,7 +966,7 @@ static void BlockStream_Close(TBlockStream * pStream) static STREAM_INIT StreamBaseInit[4] = { BaseFile_Init, - BaseMap_Init, + BaseMap_Init, BaseHttp_Init, BaseNone_Init }; @@ -1005,7 +1005,7 @@ static TFileStream * AllocateFileStream( SetLastError(ERROR_INVALID_PARAMETER); return NULL; } - + // Open the master file pMaster = FileStream_OpenFile(szNextFile + 1, STREAM_FLAG_READ_ONLY); } @@ -1063,7 +1063,7 @@ static DWORD FlatStream_CheckFile(TBlockStream * pStream) static bool FlatStream_LoadBitmap(TBlockStream * pStream) { FILE_BITMAP_FOOTER Footer; - ULONGLONG ByteOffset; + ULONGLONG ByteOffset; LPBYTE FileBitmap; DWORD BlockCount; DWORD BitmapSize; @@ -1171,7 +1171,7 @@ static bool FlatStream_BlockCheck( // Sanity checks assert((BlockOffset & (pStream->BlockSize - 1)) == 0); assert(FileBitmap != NULL); - + // Calculate the index of the block BlockIndex = (DWORD)(BlockOffset / pStream->BlockSize); BitMask = (BYTE)(1 << (BlockIndex & 0x07)); @@ -1232,7 +1232,7 @@ static void FlatStream_Close(TBlockStream * pStream) { // Write the file bitmap pStream->BaseWrite(pStream, &pStream->StreamSize, pStream->FileBitmap, pStream->BitmapSize); - + // Prepare and write the file footer Footer.Signature = ID_FILE_BITMAP_FOOTER; Footer.Version = 3; @@ -1327,7 +1327,7 @@ static bool FlatStream_CreateMirror(TBlockStream * pStream) static TFileStream * FlatStream_Open(const TCHAR * szFileName, DWORD dwStreamFlags) { - TBlockStream * pStream; + TBlockStream * pStream; ULONGLONG ByteOffset = 0; // Create new empty stream @@ -1551,7 +1551,7 @@ static bool PartStream_BlockCheck( // Sanity checks assert((BlockOffset & (pStream->BlockSize - 1)) == 0); assert(pStream->FileBitmap != NULL); - + // Calculate the block map entry FileBitmap = (PPART_FILE_MAP_ENTRY)pStream->FileBitmap + (BlockOffset / pStream->BlockSize); @@ -1647,7 +1647,7 @@ static void PartStream_Close(TBlockStream * pStream) PartHeader.FileSizeHi = (DWORD)(pStream->StreamSize >> 0x20); PartHeader.FileSizeLo = (DWORD)(pStream->StreamSize & 0xFFFFFFFF); PartHeader.BlockSize = pStream->BlockSize; - + // Make sure that the header is properly BSWAPed BSWAP_ARRAY32_UNSIGNED(&PartHeader, sizeof(PART_FILE_HEADER)); sprintf(PartHeader.GameBuildNumber, "%u", (unsigned int)pStream->BuildNumber); @@ -1812,7 +1812,7 @@ static const char * AuthCodeArray[] = "S48B6CDTN5XEQAKQDJNDLJBJ73FDFM3U", // SC2 Heart of the Swarm-all : "expand 32-byte kQAKQ0000FM3UN5XE000073FD6CDT0000LJBJS48B0000DJND" // Diablo III: Agent.exe (1.0.0.954) - // Address of decryption routine: 00502b00 + // Address of decryption routine: 00502b00 // Pointer to decryptor object: ECX // Pointer to key: ECX+0x5C // Authentication code URL: http://dist.blizzard.com/mediakey/d3-authenticationcode-enGB.txt @@ -1918,7 +1918,7 @@ static void DecryptFileChunk( KeyShuffled[0x04] = KeyMirror[0x0D]; KeyShuffled[0x01] = KeyMirror[0x0E]; KeyShuffled[0x00] = KeyMirror[0x0F]; - + // Shuffle the key - part 2 for(DWORD i = 0; i < RoundCount; i += 2) { @@ -2009,7 +2009,7 @@ static bool EncrStream_DetectFileKey(TEncryptedStream * pStream) // Prepare they decryption key from game serial number CreateKeyFromAuthCode(pStream->Key, AuthCodeArray[i]); - // Try to decrypt with the given key + // Try to decrypt with the given key memcpy(FileHeader, EncryptedHeader, ENCRYPTED_CHUNK_SIZE); DecryptFileChunk((PDWORD)FileHeader, pStream->Key, ByteOffset, ENCRYPTED_CHUNK_SIZE); @@ -2264,8 +2264,8 @@ static TFileStream * Block4Stream_Open(const TCHAR * szFileName, DWORD dwStreamF assert(FileSize <= BLOCK4_MAX_FSIZE); RemainderBlock = FileSize % (BLOCK4_BLOCK_SIZE + BLOCK4_HASH_SIZE); BlockCount = FileSize / (BLOCK4_BLOCK_SIZE + BLOCK4_HASH_SIZE); - - // Increment the stream size and number of blocks + + // Increment the stream size and number of blocks pStream->StreamSize += (BlockCount * BLOCK4_BLOCK_SIZE); pStream->BlockCount += (DWORD)BlockCount; @@ -2482,7 +2482,7 @@ size_t FileStream_Prefix(const TCHAR * szFileName, DWORD * pdwProvider) dwProvider |= BASE_PROVIDER_MAP; nPrefixLength2 = 4; } - + else if(!_tcsnicmp(szFileName+nPrefixLength1, _T("http:"), 5)) { dwProvider |= BASE_PROVIDER_HTTP; @@ -2605,7 +2605,7 @@ bool FileStream_GetSize(TFileStream * pStream, ULONGLONG * pFileSize) * \a NewFileSize File size to set */ bool FileStream_SetSize(TFileStream * pStream, ULONGLONG NewFileSize) -{ +{ if(pStream->dwFlags & STREAM_FLAG_READ_ONLY) { SetLastError(ERROR_ACCESS_DENIED); @@ -2717,7 +2717,7 @@ void FileStream_Close(TFileStream * pStream) // Close the stream provider. if(pStream->StreamClose != NULL) pStream->StreamClose(pStream); - + // Also close base stream, if any else if(pStream->BaseClose != NULL) pStream->BaseClose(pStream); |