mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Tools/Extractors: Swapped to new casclib 64bit file size functions
This commit is contained in:
@@ -1755,7 +1755,7 @@ bool DB2FileLoader::LoadHeaders(DB2FileSource* source, DB2FileLoadInfo const* lo
|
||||
|
||||
if (loadInfo && !(_header.Flags & 0x1))
|
||||
{
|
||||
std::size_t expectedFileSize =
|
||||
int64 expectedFileSize =
|
||||
sizeof(DB2Header) +
|
||||
sizeof(DB2SectionHeader) * _header.SectionCount +
|
||||
sizeof(DB2FieldEntry) * _header.FieldCount +
|
||||
|
||||
@@ -101,11 +101,11 @@ struct TC_COMMON_API DB2FileSource
|
||||
virtual bool Read(void* buffer, std::size_t numBytes) = 0;
|
||||
|
||||
// Returns current read position in file
|
||||
virtual std::size_t GetPosition() const = 0;
|
||||
virtual int64 GetPosition() const = 0;
|
||||
|
||||
virtual bool SetPosition(std::size_t position) = 0;
|
||||
virtual bool SetPosition(int64 position) = 0;
|
||||
|
||||
virtual std::size_t GetFileSize() const = 0;
|
||||
virtual int64 GetFileSize() const = 0;
|
||||
|
||||
virtual char const* GetFileName() const = 0;
|
||||
};
|
||||
|
||||
@@ -40,20 +40,20 @@ bool DB2FileSystemSource::Read(void* buffer, std::size_t numBytes)
|
||||
return fread(buffer, numBytes, 1, _file) == 1;
|
||||
}
|
||||
|
||||
std::size_t DB2FileSystemSource::GetPosition() const
|
||||
int64 DB2FileSystemSource::GetPosition() const
|
||||
{
|
||||
return ftell(_file);
|
||||
}
|
||||
|
||||
bool DB2FileSystemSource::SetPosition(std::size_t position)
|
||||
bool DB2FileSystemSource::SetPosition(int64 position)
|
||||
{
|
||||
return fseek(_file, position, SEEK_SET) == 0;
|
||||
}
|
||||
|
||||
std::size_t DB2FileSystemSource::GetFileSize() const
|
||||
int64 DB2FileSystemSource::GetFileSize() const
|
||||
{
|
||||
boost::system::error_code error;
|
||||
std::size_t size = boost::filesystem::file_size(_fileName, error);
|
||||
int64 size = boost::filesystem::file_size(_fileName, error);
|
||||
return !error ? size : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ struct TC_COMMON_API DB2FileSystemSource : public DB2FileSource
|
||||
~DB2FileSystemSource();
|
||||
bool IsOpen() const override;
|
||||
bool Read(void* buffer, std::size_t numBytes) override;
|
||||
std::size_t GetPosition() const override;
|
||||
bool SetPosition(std::size_t position) override;
|
||||
std::size_t GetFileSize() const override;
|
||||
int64 GetPosition() const override;
|
||||
bool SetPosition(int64 position) override;
|
||||
int64 GetFileSize() const override;
|
||||
char const* GetFileName() const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <CascLib.h>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
char const* CASC::HumanReadableCASCError(DWORD error)
|
||||
char const* CASC::HumanReadableCASCError(uint32 error)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ void CASC::FileDeleter::operator()(HANDLE handle)
|
||||
::CascCloseFile(handle);
|
||||
}
|
||||
|
||||
CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, DWORD localeMask, char const* product)
|
||||
CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, uint32 localeMask, char const* product)
|
||||
{
|
||||
std::string strPath = path.string();
|
||||
CASC_OPEN_STORAGE_ARGS args = {};
|
||||
@@ -87,16 +87,16 @@ namespace CASC
|
||||
}
|
||||
}
|
||||
|
||||
DWORD CASC::GetBuildNumber(StorageHandle const& storage)
|
||||
uint32 CASC::GetBuildNumber(StorageHandle const& storage)
|
||||
{
|
||||
CASC_STORAGE_PRODUCT product;
|
||||
if (GetStorageInfo(storage, CascStorageProduct, &product))
|
||||
return product.dwBuildNumber;
|
||||
return product.BuildNumber;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD CASC::GetInstalledLocalesMask(StorageHandle const& storage)
|
||||
uint32 CASC::GetInstalledLocalesMask(StorageHandle const& storage)
|
||||
{
|
||||
DWORD locales;
|
||||
if (GetStorageInfo(storage, CascStorageInstalledLocales, &locales))
|
||||
@@ -105,12 +105,12 @@ DWORD CASC::GetInstalledLocalesMask(StorageHandle const& storage)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CASC::HasTactKey(StorageHandle const& storage, ULONGLONG keyLookup)
|
||||
bool CASC::HasTactKey(StorageHandle const& storage, uint64 keyLookup)
|
||||
{
|
||||
return CascFindEncryptionKey(storage.get(), keyLookup) != nullptr;
|
||||
}
|
||||
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
{
|
||||
DWORD openFlags = CASC_OPEN_BY_NAME;
|
||||
if (zerofillEncryptedParts)
|
||||
@@ -131,7 +131,7 @@ CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileNa
|
||||
return FileHandle(handle);
|
||||
}
|
||||
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, uint32 fileDataId, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
{
|
||||
DWORD openFlags = CASC_OPEN_BY_FILEID;
|
||||
if (zerofillEncryptedParts)
|
||||
@@ -152,24 +152,39 @@ CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, DWORD fileDataId,
|
||||
return FileHandle(handle);
|
||||
}
|
||||
|
||||
DWORD CASC::GetFileSize(FileHandle const& file, PDWORD fileSizeHigh)
|
||||
int64 CASC::GetFileSize(FileHandle const& file)
|
||||
{
|
||||
return ::CascGetFileSize(file.get(), fileSizeHigh);
|
||||
ULONGLONG size;
|
||||
if (!::CascGetFileSize64(file.get(), &size))
|
||||
return -1;
|
||||
|
||||
return int64(size);
|
||||
}
|
||||
|
||||
DWORD CASC::GetFilePointer(FileHandle const& file)
|
||||
int64 CASC::GetFilePointer(FileHandle const& file)
|
||||
{
|
||||
return ::CascSetFilePointer(file.get(), 0, nullptr, FILE_CURRENT);
|
||||
ULONGLONG position;
|
||||
if (!::CascSetFilePointer64(file.get(), 0, &position, FILE_CURRENT))
|
||||
return -1;
|
||||
|
||||
return int64(position);
|
||||
}
|
||||
|
||||
bool CASC::SetFilePointer(FileHandle const& file, LONGLONG position)
|
||||
bool CASC::SetFilePointer(FileHandle const& file, int64 position)
|
||||
{
|
||||
LONG parts[2];
|
||||
memcpy(parts, &position, sizeof(parts));
|
||||
return ::CascSetFilePointer(file.get(), parts[0], &parts[1], FILE_BEGIN) != CASC_INVALID_POS;
|
||||
return ::CascSetFilePointer64(file.get(), position, nullptr, FILE_BEGIN);
|
||||
}
|
||||
|
||||
bool CASC::ReadFile(FileHandle const& file, void* buffer, DWORD bytes, PDWORD bytesRead)
|
||||
bool CASC::ReadFile(FileHandle const& file, void* buffer, uint32 bytes, uint32* bytesRead)
|
||||
{
|
||||
return ::CascReadFile(file.get(), buffer, bytes, bytesRead);
|
||||
DWORD bytesReadDWORD;
|
||||
if (!::CascReadFile(file.get(), buffer, bytes, &bytesReadDWORD))
|
||||
return false;
|
||||
|
||||
if (bytesRead)
|
||||
*bytesRead = bytesReadDWORD;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef CascHandles_h__
|
||||
#define CascHandles_h__
|
||||
|
||||
#include "Define.h"
|
||||
#include <CascPort.h>
|
||||
#include <memory>
|
||||
|
||||
@@ -46,19 +47,19 @@ namespace CASC
|
||||
typedef std::unique_ptr<HANDLE, StorageDeleter> StorageHandle;
|
||||
typedef std::unique_ptr<HANDLE, FileDeleter> FileHandle;
|
||||
|
||||
char const* HumanReadableCASCError(DWORD error);
|
||||
char const* HumanReadableCASCError(uint32 error);
|
||||
|
||||
StorageHandle OpenStorage(boost::filesystem::path const& path, DWORD localeMask, char const* product);
|
||||
DWORD GetBuildNumber(StorageHandle const& storage);
|
||||
DWORD GetInstalledLocalesMask(StorageHandle const& storage);
|
||||
bool HasTactKey(StorageHandle const& storage, ULONGLONG keyLookup);
|
||||
StorageHandle OpenStorage(boost::filesystem::path const& path, uint32 localeMask, char const* product);
|
||||
uint32 GetBuildNumber(StorageHandle const& storage);
|
||||
uint32 GetInstalledLocalesMask(StorageHandle const& storage);
|
||||
bool HasTactKey(StorageHandle const& storage, uint64 keyLookup);
|
||||
|
||||
FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false, bool zerofillEncryptedParts = false);
|
||||
FileHandle OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors = false, bool zerofillEncryptedParts = false);
|
||||
DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh);
|
||||
DWORD GetFilePointer(FileHandle const& file);
|
||||
bool SetFilePointer(FileHandle const& file, LONGLONG position);
|
||||
bool ReadFile(FileHandle const& file, void* buffer, DWORD bytes, PDWORD bytesRead);
|
||||
FileHandle OpenFile(StorageHandle const& storage, char const* fileName, uint32 localeMask, bool printErrors = false, bool zerofillEncryptedParts = false);
|
||||
FileHandle OpenFile(StorageHandle const& storage, uint32 fileDataId, uint32 localeMask, bool printErrors = false, bool zerofillEncryptedParts = false);
|
||||
int64 GetFileSize(FileHandle const& file);
|
||||
int64 GetFilePointer(FileHandle const& file);
|
||||
bool SetFilePointer(FileHandle const& file, int64 position);
|
||||
bool ReadFile(FileHandle const& file, void* buffer, uint32 bytes, uint32* bytesRead);
|
||||
}
|
||||
|
||||
#endif // CascHandles_h__
|
||||
|
||||
@@ -32,29 +32,23 @@ bool DB2CascFileSource::IsOpen() const
|
||||
|
||||
bool DB2CascFileSource::Read(void* buffer, std::size_t numBytes)
|
||||
{
|
||||
DWORD bytesRead = 0;
|
||||
uint32 bytesRead = 0;
|
||||
return CASC::ReadFile(_fileHandle, buffer, numBytes, &bytesRead) && numBytes == bytesRead;
|
||||
}
|
||||
|
||||
std::size_t DB2CascFileSource::GetPosition() const
|
||||
int64 DB2CascFileSource::GetPosition() const
|
||||
{
|
||||
return CASC::GetFilePointer(_fileHandle);
|
||||
}
|
||||
|
||||
bool DB2CascFileSource::SetPosition(std::size_t position)
|
||||
bool DB2CascFileSource::SetPosition(int64 position)
|
||||
{
|
||||
return CASC::SetFilePointer(_fileHandle, position);
|
||||
}
|
||||
|
||||
std::size_t DB2CascFileSource::GetFileSize() const
|
||||
int64 DB2CascFileSource::GetFileSize() const
|
||||
{
|
||||
DWORD sizeLow = 0;
|
||||
DWORD sizeHigh = 0;
|
||||
sizeLow = CASC::GetFileSize(_fileHandle, &sizeHigh);
|
||||
if (sizeLow == CASC_INVALID_SIZE)
|
||||
return std::size_t(-1);
|
||||
|
||||
return std::size_t(uint64(sizeLow) | (uint64(sizeHigh) << 32));
|
||||
return CASC::GetFileSize(_fileHandle);
|
||||
}
|
||||
|
||||
CASC::FileHandle const& DB2CascFileSource::GetHandle() const
|
||||
|
||||
@@ -27,9 +27,9 @@ struct DB2CascFileSource : public DB2FileSource
|
||||
DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors = true);
|
||||
bool IsOpen() const override;
|
||||
bool Read(void* buffer, std::size_t numBytes) override;
|
||||
std::size_t GetPosition() const override;
|
||||
bool SetPosition(std::size_t position) override;
|
||||
std::size_t GetFileSize() const override;
|
||||
int64 GetPosition() const override;
|
||||
bool SetPosition(int64 position) override;
|
||||
int64 GetFileSize() const override;
|
||||
CASC::FileHandle const& GetHandle() const;
|
||||
char const* GetFileName() const override;
|
||||
|
||||
|
||||
@@ -1161,9 +1161,8 @@ void ExtractMaps(uint32 build)
|
||||
|
||||
bool ExtractFile(CASC::FileHandle const& fileInArchive, std::string const& filename)
|
||||
{
|
||||
DWORD fileSize, fileSizeHigh;
|
||||
fileSize = CASC::GetFileSize(fileInArchive, &fileSizeHigh);
|
||||
if (fileSize == CASC_INVALID_SIZE)
|
||||
int64 fileSize = CASC::GetFileSize(fileInArchive);
|
||||
if (fileSize == -1)
|
||||
{
|
||||
printf("Can't read file size of '%s'\n", filename.c_str());
|
||||
return false;
|
||||
@@ -1177,12 +1176,12 @@ bool ExtractFile(CASC::FileHandle const& fileInArchive, std::string const& filen
|
||||
}
|
||||
|
||||
char buffer[0x10000];
|
||||
DWORD readBytes;
|
||||
uint32 readBytes;
|
||||
|
||||
do
|
||||
{
|
||||
readBytes = 0;
|
||||
if (!CASC::ReadFile(fileInArchive, buffer, std::min<DWORD>(fileSize, sizeof(buffer)), &readBytes))
|
||||
if (!CASC::ReadFile(fileInArchive, buffer, std::min<uint32>(fileSize, sizeof(buffer)), &readBytes))
|
||||
{
|
||||
printf("Can't read file '%s'\n", filename.c_str());
|
||||
fclose(output);
|
||||
@@ -1213,8 +1212,8 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t fileSize = source.GetFileSize();
|
||||
if (fileSize == std::size_t(-1))
|
||||
int64 fileSize = source.GetFileSize();
|
||||
if (fileSize == -1)
|
||||
{
|
||||
printf("Can't read file size of '%s'\n", cascFileName);
|
||||
return false;
|
||||
@@ -1237,7 +1236,7 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo
|
||||
|
||||
DB2Header header = db2.GetHeader();
|
||||
|
||||
std::size_t posAfterHeaders = 0;
|
||||
int64 posAfterHeaders = 0;
|
||||
posAfterHeaders += fwrite(&header, 1, sizeof(header), output);
|
||||
|
||||
// erase TactId from header if key is known
|
||||
@@ -1251,14 +1250,14 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo
|
||||
}
|
||||
|
||||
char buffer[0x10000];
|
||||
DWORD readBatchSize = 0x10000;
|
||||
DWORD readBytes;
|
||||
uint32 readBatchSize = 0x10000;
|
||||
uint32 readBytes;
|
||||
source.SetPosition(posAfterHeaders);
|
||||
|
||||
do
|
||||
{
|
||||
readBytes = 0;
|
||||
if (!CASC::ReadFile(source.GetHandle(), buffer, std::min<DWORD>(fileSize, readBatchSize), &readBytes))
|
||||
if (!CASC::ReadFile(source.GetHandle(), buffer, std::min<uint32>(fileSize, readBatchSize), &readBytes))
|
||||
{
|
||||
printf("Can't read file '%s'\n", outputFileName.c_str());
|
||||
fclose(output);
|
||||
|
||||
@@ -41,13 +41,13 @@ bool ChunkedFile::loadFile(CASC::StorageHandle const& mpq, std::string const& fi
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
DWORD fileSize = CASC::GetFileSize(file, nullptr);
|
||||
if (fileSize == CASC_INVALID_SIZE)
|
||||
int64 fileSize = CASC::GetFileSize(file);
|
||||
if (fileSize == -1)
|
||||
return false;
|
||||
|
||||
data_size = fileSize;
|
||||
data_size = uint32(fileSize);
|
||||
data = new uint8[data_size];
|
||||
DWORD bytesRead = 0;
|
||||
uint32 bytesRead = 0;
|
||||
if (!CASC::ReadFile(file, data, data_size, &bytesRead) || bytesRead != data_size)
|
||||
return false;
|
||||
|
||||
@@ -68,13 +68,13 @@ bool ChunkedFile::loadFile(CASC::StorageHandle const& mpq, uint32 fileDataId, st
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
DWORD fileSize = CASC::GetFileSize(file, nullptr);
|
||||
if (fileSize == CASC_INVALID_SIZE)
|
||||
int64 fileSize = CASC::GetFileSize(file);
|
||||
if (fileSize == -1)
|
||||
return false;
|
||||
|
||||
data_size = fileSize;
|
||||
data = new uint8[data_size];
|
||||
DWORD bytesRead = 0;
|
||||
uint32 bytesRead = 0;
|
||||
if (!CASC::ReadFile(file, data, data_size, &bytesRead) || bytesRead != data_size)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -57,25 +57,17 @@ CASCFile::CASCFile(CASC::StorageHandle const& casc, uint32 fileDataId, std::stri
|
||||
|
||||
void CASCFile::init(CASC::FileHandle const& file, const char* description)
|
||||
{
|
||||
DWORD fileSizeHigh = 0;
|
||||
DWORD fileSize = CASC::GetFileSize(file, &fileSizeHigh);
|
||||
if (fileSize == CASC_INVALID_SIZE)
|
||||
int64 fileSize = CASC::GetFileSize(file);
|
||||
if (fileSize == -1)
|
||||
{
|
||||
fprintf(stderr, "Can't open %s, failed to get size: %s!\n", description, CASC::HumanReadableCASCError(GetLastError()));
|
||||
eof = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileSizeHigh)
|
||||
{
|
||||
fprintf(stderr, "Can't open %s, file larger than 2GB", description);
|
||||
eof = true;
|
||||
return;
|
||||
}
|
||||
|
||||
size = fileSize;
|
||||
|
||||
DWORD read = 0;
|
||||
uint32 read = 0;
|
||||
buffer = new char[size];
|
||||
if (!CASC::ReadFile(file, buffer, size, &read) || size != read)
|
||||
{
|
||||
|
||||
@@ -77,7 +77,7 @@ bool GetHeaderMagic(std::string const& fileName, uint32* magic)
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
DWORD bytesRead = 0;
|
||||
uint32 bytesRead = 0;
|
||||
if (!CASC::ReadFile(file, magic, 4, &bytesRead) || bytesRead != 4)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user