aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'dep/CascLib/src/common')
-rw-r--r--dep/CascLib/src/common/Common.cpp50
-rw-r--r--dep/CascLib/src/common/Common.h39
-rw-r--r--dep/CascLib/src/common/Csv.cpp2
-rw-r--r--dep/CascLib/src/common/Csv.h2
-rw-r--r--dep/CascLib/src/common/Directory.cpp6
-rw-r--r--dep/CascLib/src/common/FileStream.cpp238
-rw-r--r--dep/CascLib/src/common/FileStream.h9
-rw-r--r--dep/CascLib/src/common/FileTree.cpp8
-rw-r--r--dep/CascLib/src/common/ListFile.cpp2
-rw-r--r--dep/CascLib/src/common/ListFile.h2
10 files changed, 207 insertions, 151 deletions
diff --git a/dep/CascLib/src/common/Common.cpp b/dep/CascLib/src/common/Common.cpp
index 1fc6cc977b4..c16323e0f5e 100644
--- a/dep/CascLib/src/common/Common.cpp
+++ b/dep/CascLib/src/common/Common.cpp
@@ -356,6 +356,44 @@ wchar_t * CascNewStr(const wchar_t * szString, size_t nCharsToReserve)
return szNewString;
}
+LPSTR CascNewStrT2A(LPCTSTR szString, size_t nCharsToReserve)
+{
+ LPSTR szNewString = NULL;
+ size_t nLength;
+
+ if(szString != NULL)
+ {
+ nLength = _tcslen(szString);
+ szNewString = CASC_ALLOC<char>(nLength + nCharsToReserve + 1);
+ if(szNewString != NULL)
+ {
+ CascStrCopy(szNewString, nLength + nCharsToReserve + 1, szString, nLength);
+// szNewString[nLength] = 0;
+ }
+ }
+
+ return szNewString;
+}
+
+LPTSTR CascNewStrA2T(LPCSTR szString, size_t nCharsToReserve)
+{
+ LPTSTR szNewString = NULL;
+ size_t nLength;
+
+ if(szString != NULL)
+ {
+ nLength = strlen(szString);
+ szNewString = CASC_ALLOC<TCHAR>(nLength + nCharsToReserve + 1);
+ if(szNewString != NULL)
+ {
+ CascStrCopy(szNewString, nLength + nCharsToReserve + 1, szString, nLength);
+// szNewString[nLength] = 0;
+ }
+ }
+
+ return szNewString;
+}
+
//-----------------------------------------------------------------------------
// String merging
@@ -387,7 +425,7 @@ LPTSTR GetLastPathPart(LPTSTR szWorkPath)
return NULL;
}
-bool CutLastPathPart(TCHAR * szWorkPath)
+bool CutLastPathPart(LPTSTR szWorkPath)
{
// Get the last part of the path
szWorkPath = GetLastPathPart(szWorkPath);
@@ -482,7 +520,7 @@ ULONGLONG CalcFileNameHash(const char * szFileName)
return CalcNormNameHash(szNormName, nLength);
}
-int ConvertDigitToInt32(const TCHAR * szString, PDWORD PtrValue)
+DWORD ConvertDigitToInt32(LPCTSTR szString, PDWORD PtrValue)
{
BYTE Digit;
@@ -494,7 +532,7 @@ int ConvertDigitToInt32(const TCHAR * szString, PDWORD PtrValue)
return (Digit > 0x0F) ? ERROR_BAD_FORMAT : ERROR_SUCCESS;
}
-int ConvertStringToInt08(const char * szString, PDWORD PtrValue)
+DWORD ConvertStringToInt08(LPCSTR szString, PDWORD PtrValue)
{
BYTE DigitOne = AsciiToUpperTable_BkSlash[szString[0]] - '0';
BYTE DigitTwo = AsciiToUpperTable_BkSlash[szString[1]] - '0';
@@ -510,7 +548,7 @@ int ConvertStringToInt08(const char * szString, PDWORD PtrValue)
return (DigitOne <= 0x0F && DigitTwo <= 0x0F) ? ERROR_SUCCESS : ERROR_BAD_FORMAT;
}
-int ConvertStringToInt32(const TCHAR * szString, size_t nMaxDigits, PDWORD PtrValue)
+DWORD ConvertStringToInt32(LPCTSTR szString, size_t nMaxDigits, PDWORD PtrValue)
{
// The number of digits must be even
assert((nMaxDigits & 0x01) == 0);
@@ -545,8 +583,8 @@ int ConvertStringToInt32(const TCHAR * szString, size_t nMaxDigits, PDWORD PtrVa
}
// Converts string blob to binary blob.
-int ConvertStringToBinary(
- const char * szString,
+DWORD ConvertStringToBinary(
+ LPCSTR szString,
size_t nMaxDigits,
LPBYTE pbBinary)
{
diff --git a/dep/CascLib/src/common/Common.h b/dep/CascLib/src/common/Common.h
index ddf8e136c9b..0037293f53d 100644
--- a/dep/CascLib/src/common/Common.h
+++ b/dep/CascLib/src/common/Common.h
@@ -166,6 +166,14 @@ void CASC_FREE(T *& ptr)
}
//-----------------------------------------------------------------------------
+// 32-bit ROL
+
+inline DWORD Rol32(DWORD dwValue, DWORD dwRolCount)
+{
+ return (dwValue << dwRolCount) | (dwValue >> (32 - dwRolCount));
+}
+
+//-----------------------------------------------------------------------------
// Big endian number manipulation
inline DWORD ConvertBytesToInteger_2(LPBYTE ValueAsBytes)
@@ -246,18 +254,18 @@ inline ULONGLONG ConvertBytesToInteger_5(LPBYTE ValueAsBytes)
inline void ConvertIntegerToBytes_4(DWORD Value, LPBYTE ValueAsBytes)
{
- ValueAsBytes[0] = (Value >> 0x18) & 0xFF;
- ValueAsBytes[1] = (Value >> 0x10) & 0xFF;
- ValueAsBytes[2] = (Value >> 0x08) & 0xFF;
- ValueAsBytes[3] = (Value >> 0x00) & 0xFF;
+ ValueAsBytes[0] = (BYTE)((Value >> 0x18) & 0xFF);
+ ValueAsBytes[1] = (BYTE)((Value >> 0x10) & 0xFF);
+ ValueAsBytes[2] = (BYTE)((Value >> 0x08) & 0xFF);
+ ValueAsBytes[3] = (BYTE)((Value >> 0x00) & 0xFF);
}
inline void ConvertIntegerToBytes_4_LE(DWORD Value, LPBYTE ValueAsBytes)
{
- ValueAsBytes[0] = (Value >> 0x00) & 0xFF;
- ValueAsBytes[1] = (Value >> 0x08) & 0xFF;
- ValueAsBytes[2] = (Value >> 0x10) & 0xFF;
- ValueAsBytes[3] = (Value >> 0x18) & 0xFF;
+ ValueAsBytes[0] = (BYTE)((Value >> 0x00) & 0xFF);
+ ValueAsBytes[1] = (BYTE)((Value >> 0x08) & 0xFF);
+ ValueAsBytes[2] = (BYTE)((Value >> 0x10) & 0xFF);
+ ValueAsBytes[3] = (BYTE)((Value >> 0x18) & 0xFF);
}
// Faster than memset(Buffer, 0, 0x10)
@@ -313,14 +321,17 @@ size_t CascStrPrintf(wchar_t * buffer, size_t nCount, const wchar_t * format, ..
//-----------------------------------------------------------------------------
// String allocation
-char * CascNewStr(const char * szString, size_t nCharsToReserve = 0);
+char * CascNewStr(const char * szString, size_t nCharsToReserve = 0);
wchar_t * CascNewStr(const wchar_t * szString, size_t nCharsToReserve = 0);
+LPSTR CascNewStrT2A(LPCTSTR szString, size_t nCharsToReserve = 0);
+LPTSTR CascNewStrA2T(LPCSTR szString, size_t nCharsToReserve = 0);
+
size_t CombinePath(LPTSTR szBuffer, size_t nMaxChars, char chSeparator, va_list argList);
size_t CombinePath(LPTSTR szBuffer, size_t nMaxChars, char chSeparator, ...);
LPTSTR CombinePath(LPCTSTR szPath, LPCTSTR szSubDir);
LPTSTR GetLastPathPart(LPTSTR szWorkPath);
-bool CutLastPathPart(TCHAR * szWorkPath);
+bool CutLastPathPart(LPTSTR szWorkPath);
size_t NormalizeFileName_UpperBkSlash(char * szNormName, const char * szFileName, size_t cchMaxChars);
size_t NormalizeFileName_LowerSlash(char * szNormName, const char * szFileName, size_t cchMaxChars);
@@ -328,10 +339,10 @@ size_t NormalizeFileName_LowerSlash(char * szNormName, const char * szFileName,
ULONGLONG CalcNormNameHash(const char * szNormName, size_t nLength);
ULONGLONG CalcFileNameHash(const char * szFileName);
-int ConvertDigitToInt32(const TCHAR * szString, PDWORD PtrValue);
-int ConvertStringToInt08(const char * szString, PDWORD PtrValue);
-int ConvertStringToInt32(const TCHAR * szString, size_t nMaxDigits, PDWORD PtrValue);
-int ConvertStringToBinary(const char * szString, size_t nMaxDigits, LPBYTE pbBinary);
+DWORD ConvertDigitToInt32(LPCTSTR szString, PDWORD PtrValue);
+DWORD ConvertStringToInt08(LPCSTR szString, PDWORD PtrValue);
+DWORD ConvertStringToInt32(LPCTSTR szString, size_t nMaxDigits, PDWORD PtrValue);
+DWORD ConvertStringToBinary(LPCSTR szString, size_t nMaxDigits, LPBYTE pbBinary);
//-----------------------------------------------------------------------------
// Conversion from binary array to string. The caller must ensure that
diff --git a/dep/CascLib/src/common/Csv.cpp b/dep/CascLib/src/common/Csv.cpp
index c665fc00c4c..818973e9603 100644
--- a/dep/CascLib/src/common/Csv.cpp
+++ b/dep/CascLib/src/common/Csv.cpp
@@ -185,7 +185,7 @@ CASC_CSV::~CASC_CSV()
m_szCsvFile = NULL;
}
-DWORD CASC_CSV::Load(const TCHAR * szFileName)
+DWORD CASC_CSV::Load(LPCTSTR szFileName)
{
DWORD cbFileData = 0;
DWORD dwErrCode = ERROR_SUCCESS;
diff --git a/dep/CascLib/src/common/Csv.h b/dep/CascLib/src/common/Csv.h
index 394eab1e2f0..2fcee847703 100644
--- a/dep/CascLib/src/common/Csv.h
+++ b/dep/CascLib/src/common/Csv.h
@@ -70,7 +70,7 @@ class CASC_CSV
~CASC_CSV();
DWORD Load(LPBYTE pbData, size_t cbData);
- DWORD Load(const TCHAR * szFileName);
+ DWORD Load(LPCTSTR szFileName);
bool LoadNextLine();
const CASC_CSV_COLUMN & operator[](const char * szColumnName) const;
diff --git a/dep/CascLib/src/common/Directory.cpp b/dep/CascLib/src/common/Directory.cpp
index 387ca3a8ea4..57c7d552733 100644
--- a/dep/CascLib/src/common/Directory.cpp
+++ b/dep/CascLib/src/common/Directory.cpp
@@ -15,7 +15,7 @@
//-----------------------------------------------------------------------------
// Public functions
-bool DirectoryExists(const TCHAR * szDirectory)
+bool DirectoryExists(LPCTSTR szDirectory)
{
#ifdef PLATFORM_WINDOWS
@@ -38,7 +38,7 @@ bool DirectoryExists(const TCHAR * szDirectory)
return false;
}
-bool MakeDirectory(const TCHAR * szDirectory)
+bool MakeDirectory(LPCTSTR szDirectory)
{
#ifdef PLATFORM_WINDOWS
@@ -60,7 +60,7 @@ int ScanIndexDirectory(
#ifdef PLATFORM_WINDOWS
WIN32_FIND_DATA wf;
- TCHAR * szSearchMask;
+ LPTSTR szSearchMask;
HANDLE hFind;
// Prepare the search mask
diff --git a/dep/CascLib/src/common/FileStream.cpp b/dep/CascLib/src/common/FileStream.cpp
index ab591a2e3f1..350b0540cf4 100644
--- a/dep/CascLib/src/common/FileStream.cpp
+++ b/dep/CascLib/src/common/FileStream.cpp
@@ -89,7 +89,7 @@ static bool BaseFile_Create(TFileStream * pStream)
return true;
}
-static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
+static bool BaseFile_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStreamFlags)
{
#ifdef PLATFORM_WINDOWS
{
@@ -160,66 +160,72 @@ static bool BaseFile_Read(
void * pvBuffer, // Pointer to data to be read
DWORD dwBytesToRead) // Number of bytes to read from the file
{
- ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.File.FilePos;
DWORD dwBytesRead = 0; // Must be set by platform-specific code
-#ifdef PLATFORM_WINDOWS
+ // Synchronize the access to the TFileStream structure
+ CascLock(pStream->Lock);
{
- // Note: We no longer support Windows 9x.
- // Thus, we can use the OVERLAPPED structure to specify
- // file offset to read from file. This allows us to skip
- // one system call to SetFilePointer
-
- // Update the byte offset
- pStream->Base.File.FilePos = ByteOffset;
+ ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.File.FilePos;
- // Read the data
- if(dwBytesToRead != 0)
+#ifdef PLATFORM_WINDOWS
{
- OVERLAPPED Overlapped;
+ // Note: We no longer support Windows 9x.
+ // Thus, we can use the OVERLAPPED structure to specify
+ // file offset to read from file. This allows us to skip
+ // one system call to SetFilePointer
- Overlapped.OffsetHigh = (DWORD)(ByteOffset >> 32);
- Overlapped.Offset = (DWORD)ByteOffset;
- Overlapped.hEvent = NULL;
- if(!ReadFile(pStream->Base.File.hFile, pvBuffer, dwBytesToRead, &dwBytesRead, &Overlapped))
- return false;
+ // Update the byte offset
+ pStream->Base.File.FilePos = ByteOffset;
+
+ // Read the data
+ if (dwBytesToRead != 0)
+ {
+ OVERLAPPED Overlapped;
+
+ Overlapped.OffsetHigh = (DWORD)(ByteOffset >> 32);
+ Overlapped.Offset = (DWORD)ByteOffset;
+ Overlapped.hEvent = NULL;
+ if (!ReadFile(pStream->Base.File.hFile, pvBuffer, dwBytesToRead, &dwBytesRead, &Overlapped))
+ return false;
+ }
}
- }
#endif
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
- {
- ssize_t bytes_read;
-
- // If the byte offset is different from the current file position,
- // we have to update the file position
- if(ByteOffset != pStream->Base.File.FilePos)
{
- if(lseek64((intptr_t)pStream->Base.File.hFile, (off64_t)(ByteOffset), SEEK_SET) == (off64_t)-1)
+ ssize_t bytes_read;
+
+ // If the byte offset is different from the current file position,
+ // we have to update the file position
+ if (ByteOffset != pStream->Base.File.FilePos)
{
- SetLastError(errno);
- return false;
+ if (lseek64((intptr_t)pStream->Base.File.hFile, (off64_t)(ByteOffset), SEEK_SET) == (off64_t)-1)
+ {
+ SetLastError(errno);
+ return false;
+ }
+ pStream->Base.File.FilePos = ByteOffset;
}
- pStream->Base.File.FilePos = ByteOffset;
- }
- // Perform the read operation
- if(dwBytesToRead != 0)
- {
- bytes_read = read((intptr_t)pStream->Base.File.hFile, pvBuffer, (size_t)dwBytesToRead);
- if(bytes_read == -1)
+ // Perform the read operation
+ if (dwBytesToRead != 0)
{
- SetLastError(errno);
- return false;
- }
+ bytes_read = read((intptr_t)pStream->Base.File.hFile, pvBuffer, (size_t)dwBytesToRead);
+ if (bytes_read == -1)
+ {
+ SetLastError(errno);
+ return false;
+ }
- dwBytesRead = (DWORD)(size_t)bytes_read;
+ dwBytesRead = (DWORD)(size_t)bytes_read;
+ }
}
- }
#endif
- // Increment the current file position by number of bytes read
- pStream->Base.File.FilePos = ByteOffset + dwBytesRead;
+ // Increment the current file position by number of bytes read
+ pStream->Base.File.FilePos = ByteOffset + dwBytesRead;
+ }
+ CascUnlock(pStream->Lock);
// If the number of bytes read doesn't match to required amount, return false
// However, Blizzard's CASC handlers read encoded data so that if less than expected
@@ -249,67 +255,73 @@ static bool BaseFile_Read(
static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const void * pvBuffer, DWORD dwBytesToWrite)
{
- ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.File.FilePos;
DWORD dwBytesWritten = 0; // Must be set by platform-specific code
-#ifdef PLATFORM_WINDOWS
+ // Synchronize the access to the TFileStream structure
+ CascLock(pStream->Lock);
{
- // Note: We no longer support Windows 9x.
- // Thus, we can use the OVERLAPPED structure to specify
- // file offset to read from file. This allows us to skip
- // one system call to SetFilePointer
-
- // Update the byte offset
- pStream->Base.File.FilePos = ByteOffset;
+ ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.File.FilePos;
- // Read the data
- if(dwBytesToWrite != 0)
+#ifdef PLATFORM_WINDOWS
{
- OVERLAPPED Overlapped;
+ // Note: We no longer support Windows 9x.
+ // Thus, we can use the OVERLAPPED structure to specify
+ // file offset to read from file. This allows us to skip
+ // one system call to SetFilePointer
- Overlapped.OffsetHigh = (DWORD)(ByteOffset >> 32);
- Overlapped.Offset = (DWORD)ByteOffset;
- Overlapped.hEvent = NULL;
- if(!WriteFile(pStream->Base.File.hFile, pvBuffer, dwBytesToWrite, &dwBytesWritten, &Overlapped))
- return false;
+ // Update the byte offset
+ pStream->Base.File.FilePos = ByteOffset;
+
+ // Read the data
+ if (dwBytesToWrite != 0)
+ {
+ OVERLAPPED Overlapped;
+
+ Overlapped.OffsetHigh = (DWORD)(ByteOffset >> 32);
+ Overlapped.Offset = (DWORD)ByteOffset;
+ Overlapped.hEvent = NULL;
+ if (!WriteFile(pStream->Base.File.hFile, pvBuffer, dwBytesToWrite, &dwBytesWritten, &Overlapped))
+ return false;
+ }
}
- }
#endif
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
- {
- ssize_t bytes_written;
-
- // If the byte offset is different from the current file position,
- // we have to update the file position
- if(ByteOffset != pStream->Base.File.FilePos)
{
- if(lseek64((intptr_t)pStream->Base.File.hFile, (off64_t)(ByteOffset), SEEK_SET) == (off64_t)-1)
+ ssize_t bytes_written;
+
+ // If the byte offset is different from the current file position,
+ // we have to update the file position
+ if (ByteOffset != pStream->Base.File.FilePos)
+ {
+ if (lseek64((intptr_t)pStream->Base.File.hFile, (off64_t)(ByteOffset), SEEK_SET) == (off64_t)-1)
+ {
+ SetLastError(errno);
+ return false;
+ }
+ pStream->Base.File.FilePos = ByteOffset;
+ }
+
+ // Perform the read operation
+ bytes_written = write((intptr_t)pStream->Base.File.hFile, pvBuffer, (size_t)dwBytesToWrite);
+ if (bytes_written == -1)
{
SetLastError(errno);
return false;
}
- pStream->Base.File.FilePos = ByteOffset;
- }
- // Perform the read operation
- bytes_written = write((intptr_t)pStream->Base.File.hFile, pvBuffer, (size_t)dwBytesToWrite);
- if(bytes_written == -1)
- {
- SetLastError(errno);
- return false;
+ dwBytesWritten = (DWORD)(size_t)bytes_written;
}
-
- dwBytesWritten = (DWORD)(size_t)bytes_written;
- }
#endif
- // Increment the current file position by number of bytes read
- pStream->Base.File.FilePos = ByteOffset + dwBytesWritten;
+ // Increment the current file position by number of bytes read
+ pStream->Base.File.FilePos = ByteOffset + dwBytesWritten;
- // Also modify the file size, if needed
- if(pStream->Base.File.FilePos > pStream->Base.File.FileSize)
- pStream->Base.File.FileSize = pStream->Base.File.FilePos;
+ // Also modify the file size, if needed
+ if(pStream->Base.File.FilePos > pStream->Base.File.FileSize)
+ pStream->Base.File.FileSize = pStream->Base.File.FilePos;
+ }
+ CascUnlock(pStream->Lock);
if(dwBytesWritten != dwBytesToWrite)
SetLastError(ERROR_DISK_FULL);
@@ -383,12 +395,8 @@ static bool BaseFile_GetPos(TFileStream * pStream, ULONGLONG * pByteOffset)
static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream)
{
#ifdef PLATFORM_WINDOWS
- // Delete the original stream file. Don't check the result value,
- // because if the file doesn't exist, it would fail
- DeleteFile(pStream->szFileName);
-
// Rename the new file to the old stream's file
- return (bool)MoveFile(pNewStream->szFileName, pStream->szFileName);
+ return (bool)MoveFileEx(pNewStream->szFileName, pStream->szFileName, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
#endif
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
@@ -405,19 +413,24 @@ static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream)
static void BaseFile_Close(TFileStream * pStream)
{
- if(pStream->Base.File.hFile != INVALID_HANDLE_VALUE)
+ // Synchronize the access to multiple threads
+ CascLock(pStream->Lock);
{
+ if(pStream->Base.File.hFile != INVALID_HANDLE_VALUE)
+ {
#ifdef PLATFORM_WINDOWS
- CloseHandle(pStream->Base.File.hFile);
+ CloseHandle(pStream->Base.File.hFile);
#endif
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
- close((intptr_t)pStream->Base.File.hFile);
+ close((intptr_t)pStream->Base.File.hFile);
#endif
- }
+ }
- // Also invalidate the handle
- pStream->Base.File.hFile = INVALID_HANDLE_VALUE;
+ // Also invalidate the handle
+ pStream->Base.File.hFile = INVALID_HANDLE_VALUE;
+ }
+ CascUnlock(pStream->Lock);
}
// Initializes base functions for the disk file
@@ -436,7 +449,7 @@ static void BaseFile_Init(TFileStream * pStream)
//-----------------------------------------------------------------------------
// Local functions - base memory-mapped file support
-static bool BaseMap_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
+static bool BaseMap_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStreamFlags)
{
#ifdef PLATFORM_WINDOWS
@@ -584,7 +597,7 @@ static void BaseMap_Init(TFileStream * pStream)
//-----------------------------------------------------------------------------
// Local functions - base HTTP file support
-static const TCHAR * BaseHttp_ExtractServerName(const TCHAR * szFileName, TCHAR * szServerName)
+static LPCTSTR BaseHttp_ExtractServerName(LPCTSTR szFileName, LPTSTR szServerName)
{
// Check for HTTP
if(!_tcsnicmp(szFileName, _T("http://"), 7))
@@ -607,7 +620,7 @@ static const TCHAR * BaseHttp_ExtractServerName(const TCHAR * szFileName, TCHAR
return szFileName;
}
-static bool BaseHttp_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
+static bool BaseHttp_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStreamFlags)
{
#ifdef PLATFORM_WINDOWS
@@ -1018,13 +1031,13 @@ static STREAM_INIT StreamBaseInit[4] =
// The stream structure is created as flat block, variable length
// The file name is placed after the end of the stream structure data
static TFileStream * AllocateFileStream(
- const TCHAR * szFileName,
+ LPCTSTR szFileName,
size_t StreamSize,
DWORD dwStreamFlags)
{
TFileStream * pMaster = NULL;
TFileStream * pStream;
- const TCHAR * szNextFile = szFileName;
+ LPCTSTR szNextFile = szFileName;
size_t FileNameSize;
// Sanity check
@@ -1063,10 +1076,13 @@ static TFileStream * AllocateFileStream(
pStream->dwFlags = dwStreamFlags;
// Initialize the file name
- pStream->szFileName = (TCHAR *)((BYTE *)pStream + StreamSize);
+ pStream->szFileName = (LPTSTR)((BYTE *)pStream + StreamSize);
memcpy(pStream->szFileName, szFileName, FileNameSize);
pStream->szFileName[FileNameSize / sizeof(TCHAR)] = 0;
+ // Initialize the stream lock
+ CascInitLock(pStream->Lock);
+
// Initialize the stream functions
StreamBaseInit[dwStreamFlags & 0x03](pStream);
}
@@ -1367,7 +1383,7 @@ static bool FlatStream_CreateMirror(TBlockStream * pStream)
return true;
}
-static TFileStream * FlatStream_Open(const TCHAR * szFileName, DWORD dwStreamFlags)
+static TFileStream * FlatStream_Open(LPCTSTR szFileName, DWORD dwStreamFlags)
{
TBlockStream * pStream;
ULONGLONG ByteOffset = 0;
@@ -1788,7 +1804,7 @@ static bool PartStream_CreateMirror(TBlockStream * pStream)
return true;
}
-static TFileStream * PartStream_Open(const TCHAR * szFileName, DWORD dwStreamFlags)
+static TFileStream * PartStream_Open(LPCTSTR szFileName, DWORD dwStreamFlags)
{
TBlockStream * pStream;
@@ -1898,13 +1914,6 @@ static const char * AuthCodeArray[] =
NULL
};
-static DWORD Rol32(DWORD dwValue, DWORD dwRolCount)
-{
- DWORD dwShiftRight = 32 - dwRolCount;
-
- return (dwValue << dwRolCount) | (dwValue >> dwShiftRight);
-}
-
static void CreateKeyFromAuthCode(
LPBYTE pbKeyBuffer,
const char * szAuthCode)
@@ -2105,7 +2114,7 @@ static bool EncrStream_BlockRead(
return true;
}
-static TFileStream * EncrStream_Open(const TCHAR * szFileName, DWORD dwStreamFlags)
+static TFileStream * EncrStream_Open(LPCTSTR szFileName, DWORD dwStreamFlags)
{
TEncryptedStream * pStream;
@@ -2232,14 +2241,14 @@ static void Block4Stream_Close(TBlockStream * pStream)
return;
}
-static TFileStream * Block4Stream_Open(const TCHAR * szFileName, DWORD dwStreamFlags)
+static TFileStream * Block4Stream_Open(LPCTSTR szFileName, DWORD dwStreamFlags)
{
TBaseProviderData * NewBaseArray = NULL;
ULONGLONG RemainderBlock;
ULONGLONG BlockCount;
ULONGLONG FileSize;
TBlockStream * pStream;
- TCHAR * szNameBuff;
+ LPTSTR szNameBuff;
size_t nNameLength;
DWORD dwBaseFiles = 0;
DWORD dwBaseFlags;
@@ -2458,7 +2467,7 @@ TFileStream * FileStream_OpenFile(
*
* \a pStream Pointer to an open stream
*/
-const TCHAR * FileStream_GetFileName(TFileStream * pStream)
+LPCTSTR FileStream_GetFileName(TFileStream * pStream)
{
assert(pStream != NULL);
return pStream->szFileName;
@@ -2754,6 +2763,9 @@ void FileStream_Close(TFileStream * pStream)
else if(pStream->BaseClose != NULL)
pStream->BaseClose(pStream);
+ // Free the stream lock
+ CascFreeLock(pStream->Lock);
+
// Free the stream itself
CASC_FREE(pStream);
}
diff --git a/dep/CascLib/src/common/FileStream.h b/dep/CascLib/src/common/FileStream.h
index e934cca062f..acd0683a596 100644
--- a/dep/CascLib/src/common/FileStream.h
+++ b/dep/CascLib/src/common/FileStream.h
@@ -48,7 +48,7 @@ typedef bool (*STREAM_CREATE)(
typedef bool (*STREAM_OPEN)(
struct TFileStream * pStream, // Pointer to an unopened stream
- const TCHAR * szFileName, // Pointer to file name to be open
+ LPCTSTR szFileName, // Pointer to file name to be open
DWORD dwStreamFlags // Stream flags
);
@@ -205,11 +205,12 @@ struct TFileStream
STREAM_CLOSE BaseClose; // Pointer to function closing the stream
// Base provider data (file size, file position)
- TBaseProviderData Base;
+ TBaseProviderData Base; // Stream information, like size or current position
+ CASC_LOCK Lock; // For multi-threaded synchronization
// Stream provider data
TFileStream * pMaster; // Master stream (e.g. MPQ on a web server)
- TCHAR * szFileName; // File name (self-relative pointer)
+ LPTSTR szFileName; // File name (self-relative pointer)
ULONGLONG StreamSize; // Stream size (can be less than file size)
ULONGLONG StreamPos; // Stream position
@@ -249,7 +250,7 @@ struct TEncryptedStream : public TBlockStream
TFileStream * FileStream_CreateFile(LPCTSTR szFileName, DWORD dwStreamFlags);
TFileStream * FileStream_OpenFile(LPCTSTR szFileName, DWORD dwStreamFlags);
-const TCHAR * FileStream_GetFileName(TFileStream * pStream);
+LPCTSTR FileStream_GetFileName(TFileStream * pStream);
size_t FileStream_Prefix(LPCTSTR szFileName, DWORD * pdwProvider);
bool FileStream_SetCallback(TFileStream * pStream, STREAM_DOWNLOAD_CALLBACK pfnCallback, void * pvUserData);
diff --git a/dep/CascLib/src/common/FileTree.cpp b/dep/CascLib/src/common/FileTree.cpp
index ceb578cf578..6a44940bd8a 100644
--- a/dep/CascLib/src/common/FileTree.cpp
+++ b/dep/CascLib/src/common/FileTree.cpp
@@ -293,13 +293,7 @@ PCASC_FILE_NODE CASC_FILE_TREE::InsertByName(PCASC_CKEY_ENTRY pCKeyEntry, const
assert(szFileName != NULL && szFileName[0] != 0);
assert(pCKeyEntry != NULL);
- //char szCKey[MD5_STRING_SIZE+1];
- //char szEKey[MD5_STRING_SIZE+1];
- //StringFromBinary(pCKeyEntry->CKey, MD5_HASH_SIZE, szCKey);
- //StringFromBinary(pCKeyEntry->EKey, MD5_HASH_SIZE, szEKey);
- //printf("%s\t%s\t%s\n", szCKey, szEKey, szFileName);
-
- //BREAK_ON_XKEY3(pCKeyEntry->EKey, 0x03, 0xDC, 0x7D);
+ //BREAK_ON_XKEY3(pCKeyEntry->EKey, 0x00, 0x00, 0x0F);
// Calculate the file name hash
FileNameHash = CalcFileNameHash(szFileName);
diff --git a/dep/CascLib/src/common/ListFile.cpp b/dep/CascLib/src/common/ListFile.cpp
index bcca8b7177a..a284ef2db10 100644
--- a/dep/CascLib/src/common/ListFile.cpp
+++ b/dep/CascLib/src/common/ListFile.cpp
@@ -121,7 +121,7 @@ static int ListFile_GetFileDataId(PLISTFILE_CACHE pCache, PDWORD PtrFileDataId)
//-----------------------------------------------------------------------------
// Functions for parsing an external listfile
-void * ListFile_OpenExternal(const TCHAR * szListFile)
+void * ListFile_OpenExternal(LPCTSTR szListFile)
{
PLISTFILE_CACHE pCache = NULL;
TFileStream * pStream;
diff --git a/dep/CascLib/src/common/ListFile.h b/dep/CascLib/src/common/ListFile.h
index 1333b52c2b5..7710b269cef 100644
--- a/dep/CascLib/src/common/ListFile.h
+++ b/dep/CascLib/src/common/ListFile.h
@@ -14,7 +14,7 @@
//-----------------------------------------------------------------------------
// Functions for parsing an external listfile
-void * ListFile_OpenExternal(const TCHAR * szListFile);
+void * ListFile_OpenExternal(LPCTSTR szListFile);
void * ListFile_FromBuffer(LPBYTE pbBuffer, DWORD cbBuffer);
bool ListFile_VerifyMD5(void * pvListFile, LPBYTE pbHashMD5);
size_t ListFile_GetNextLine(void * pvListFile, const char ** pszLineBegin, const char ** pszLineEnd);