mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-31 14:17:28 +01:00
Tools/Extractors: Refactor CascHandles into classes
This commit is contained in:
@@ -43,19 +43,16 @@ char const* CASC::HumanReadableCASCError(uint32 error)
|
||||
}
|
||||
}
|
||||
|
||||
void CASC::StorageDeleter::operator()(HANDLE handle)
|
||||
CASC::Storage::Storage(HANDLE handle) : _handle(handle)
|
||||
{
|
||||
if (handle != nullptr && handle != INVALID_HANDLE_VALUE)
|
||||
::CascCloseStorage(handle);
|
||||
}
|
||||
|
||||
void CASC::FileDeleter::operator()(HANDLE handle)
|
||||
CASC::Storage::~Storage()
|
||||
{
|
||||
if (handle != nullptr && handle != INVALID_HANDLE_VALUE)
|
||||
::CascCloseFile(handle);
|
||||
::CascCloseStorage(_handle);
|
||||
}
|
||||
|
||||
CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, uint32 localeMask, char const* product)
|
||||
CASC::Storage* CASC::Storage::Open(boost::filesystem::path const& path, uint32 localeMask, char const* product)
|
||||
{
|
||||
std::string strPath = path.string();
|
||||
CASC_OPEN_STORAGE_ARGS args = {};
|
||||
@@ -70,54 +67,54 @@ CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, uint3
|
||||
printf("Error opening casc storage '%s': %s\n", path.string().c_str(), HumanReadableCASCError(lastError));
|
||||
CascCloseStorage(handle);
|
||||
SetLastError(lastError);
|
||||
return StorageHandle();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
printf("Opened casc storage '%s'\n", path.string().c_str());
|
||||
return StorageHandle(handle);
|
||||
return new Storage(handle);
|
||||
}
|
||||
|
||||
namespace CASC
|
||||
{
|
||||
template<typename T>
|
||||
static bool GetStorageInfo(StorageHandle const& storage, CASC_STORAGE_INFO_CLASS storageInfoClass, T* value)
|
||||
static bool GetStorageInfo(HANDLE storage, CASC_STORAGE_INFO_CLASS storageInfoClass, T* value)
|
||||
{
|
||||
size_t infoDataSizeNeeded = 0;
|
||||
return ::CascGetStorageInfo(storage.get(), storageInfoClass, value, sizeof(T), &infoDataSizeNeeded);
|
||||
return ::CascGetStorageInfo(storage, storageInfoClass, value, sizeof(T), &infoDataSizeNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 CASC::GetBuildNumber(StorageHandle const& storage)
|
||||
uint32 CASC::Storage::GetBuildNumber() const
|
||||
{
|
||||
CASC_STORAGE_PRODUCT product;
|
||||
if (GetStorageInfo(storage, CascStorageProduct, &product))
|
||||
if (GetStorageInfo(_handle, CascStorageProduct, &product))
|
||||
return product.BuildNumber;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 CASC::GetInstalledLocalesMask(StorageHandle const& storage)
|
||||
uint32 CASC::Storage::GetInstalledLocalesMask() const
|
||||
{
|
||||
DWORD locales;
|
||||
if (GetStorageInfo(storage, CascStorageInstalledLocales, &locales))
|
||||
if (GetStorageInfo(_handle, CascStorageInstalledLocales, &locales))
|
||||
return locales;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CASC::HasTactKey(StorageHandle const& storage, uint64 keyLookup)
|
||||
bool CASC::Storage::HasTactKey(uint64 keyLookup) const
|
||||
{
|
||||
return CascFindEncryptionKey(storage.get(), keyLookup) != nullptr;
|
||||
return CascFindEncryptionKey(_handle, keyLookup) != nullptr;
|
||||
}
|
||||
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
CASC::File* CASC::Storage::OpenFile(char const* fileName, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) const
|
||||
{
|
||||
DWORD openFlags = CASC_OPEN_BY_NAME;
|
||||
if (zerofillEncryptedParts)
|
||||
openFlags |= CASC_OVERCOME_ENCRYPTED;
|
||||
|
||||
HANDLE handle = nullptr;
|
||||
if (!::CascOpenFile(storage.get(), fileName, localeMask, openFlags, &handle))
|
||||
if (!::CascOpenFile(_handle, fileName, localeMask, openFlags, &handle))
|
||||
{
|
||||
DWORD lastError = GetLastError(); // support checking error set by *Open* call, not the next *Close*
|
||||
if (printErrors)
|
||||
@@ -125,20 +122,20 @@ CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileNa
|
||||
|
||||
CascCloseFile(handle);
|
||||
SetLastError(lastError);
|
||||
return FileHandle();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return FileHandle(handle);
|
||||
return new File(handle);
|
||||
}
|
||||
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, uint32 fileDataId, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
CASC::File* CASC::Storage::OpenFile(uint32 fileDataId, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) const
|
||||
{
|
||||
DWORD openFlags = CASC_OPEN_BY_FILEID;
|
||||
if (zerofillEncryptedParts)
|
||||
openFlags |= CASC_OVERCOME_ENCRYPTED;
|
||||
|
||||
HANDLE handle = nullptr;
|
||||
if (!::CascOpenFile(storage.get(), CASC_FILE_DATA_ID(fileDataId), localeMask, openFlags, &handle))
|
||||
if (!::CascOpenFile(_handle, CASC_FILE_DATA_ID(fileDataId), localeMask, openFlags, &handle))
|
||||
{
|
||||
DWORD lastError = GetLastError(); // support checking error set by *Open* call, not the next *Close*
|
||||
if (printErrors)
|
||||
@@ -146,41 +143,50 @@ CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, uint32 fileDataId,
|
||||
|
||||
CascCloseFile(handle);
|
||||
SetLastError(lastError);
|
||||
return FileHandle();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return FileHandle(handle);
|
||||
return new File(handle);
|
||||
}
|
||||
|
||||
int64 CASC::GetFileSize(FileHandle const& file)
|
||||
CASC::File::File(HANDLE handle) : _handle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
CASC::File::~File()
|
||||
{
|
||||
::CascCloseFile(_handle);
|
||||
}
|
||||
|
||||
int64 CASC::File::GetSize() const
|
||||
{
|
||||
ULONGLONG size;
|
||||
if (!::CascGetFileSize64(file.get(), &size))
|
||||
if (!::CascGetFileSize64(_handle, &size))
|
||||
return -1;
|
||||
|
||||
return int64(size);
|
||||
}
|
||||
|
||||
int64 CASC::GetFilePointer(FileHandle const& file)
|
||||
int64 CASC::File::GetPointer() const
|
||||
{
|
||||
ULONGLONG position;
|
||||
if (!::CascSetFilePointer64(file.get(), 0, &position, FILE_CURRENT))
|
||||
if (!::CascSetFilePointer64(_handle, 0, &position, FILE_CURRENT))
|
||||
return -1;
|
||||
|
||||
return int64(position);
|
||||
}
|
||||
|
||||
bool CASC::SetFilePointer(FileHandle const& file, int64 position)
|
||||
bool CASC::File::SetPointer(int64 position)
|
||||
{
|
||||
LONG parts[2];
|
||||
memcpy(parts, &position, sizeof(parts));
|
||||
return ::CascSetFilePointer64(file.get(), position, nullptr, FILE_BEGIN);
|
||||
return ::CascSetFilePointer64(_handle, position, nullptr, FILE_BEGIN);
|
||||
}
|
||||
|
||||
bool CASC::ReadFile(FileHandle const& file, void* buffer, uint32 bytes, uint32* bytesRead)
|
||||
bool CASC::File::ReadFile(void* buffer, uint32 bytes, uint32* bytesRead)
|
||||
{
|
||||
DWORD bytesReadDWORD;
|
||||
if (!::CascReadFile(file.get(), buffer, bytes, &bytesReadDWORD))
|
||||
if (!::CascReadFile(_handle, buffer, bytes, &bytesReadDWORD))
|
||||
return false;
|
||||
|
||||
if (bytesRead)
|
||||
|
||||
@@ -32,34 +32,48 @@ namespace boost
|
||||
|
||||
namespace CASC
|
||||
{
|
||||
struct StorageDeleter
|
||||
{
|
||||
typedef HANDLE pointer;
|
||||
void operator()(HANDLE handle);
|
||||
};
|
||||
|
||||
struct FileDeleter
|
||||
{
|
||||
typedef HANDLE pointer;
|
||||
void operator()(HANDLE handle);
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<HANDLE, StorageDeleter> StorageHandle;
|
||||
typedef std::unique_ptr<HANDLE, FileDeleter> FileHandle;
|
||||
|
||||
char const* HumanReadableCASCError(uint32 error);
|
||||
|
||||
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);
|
||||
class File;
|
||||
|
||||
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);
|
||||
class Storage
|
||||
{
|
||||
public:
|
||||
~Storage();
|
||||
|
||||
static Storage* Open(boost::filesystem::path const& path, uint32 localeMask, char const* product);
|
||||
|
||||
uint32 GetBuildNumber() const;
|
||||
uint32 GetInstalledLocalesMask() const;
|
||||
bool HasTactKey(uint64 keyLookup) const;
|
||||
|
||||
File* OpenFile(char const* fileName, uint32 localeMask, bool printErrors = false, bool zerofillEncryptedParts = false) const;
|
||||
File* OpenFile(uint32 fileDataId, uint32 localeMask, bool printErrors = false, bool zerofillEncryptedParts = false) const;
|
||||
|
||||
private:
|
||||
Storage(HANDLE handle);
|
||||
|
||||
HANDLE _handle;
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
friend File* Storage::OpenFile(char const* fileName, uint32 localeMask, bool printErrors, bool zerofillEncryptedParts) const;
|
||||
friend File* Storage::OpenFile(uint32 fileDataId, uint32 localeMask, bool printErrors, bool zerofillEncryptedParts) const;
|
||||
|
||||
public:
|
||||
~File();
|
||||
|
||||
int64 GetSize() const;
|
||||
int64 GetPointer() const;
|
||||
bool SetPointer(int64 position);
|
||||
bool ReadFile(void* buffer, uint32 bytes, uint32* bytesRead);
|
||||
|
||||
private:
|
||||
File(HANDLE handle);
|
||||
|
||||
HANDLE _handle;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CascHandles_h__
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include "StringFormat.h"
|
||||
#include <CascLib.h>
|
||||
|
||||
DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors /*= true*/)
|
||||
DB2CascFileSource::DB2CascFileSource(std::shared_ptr<CASC::Storage const> storage, uint32 fileDataId, bool printErrors /*= true*/)
|
||||
{
|
||||
_fileHandle = CASC::OpenFile(storage, fileDataId, CASC_LOCALE_NONE, printErrors, true);
|
||||
_fileHandle.reset(storage->OpenFile(fileDataId, CASC_LOCALE_NONE, printErrors, true));
|
||||
_fileName = Trinity::StringFormat("FileDataId: %u", fileDataId);
|
||||
}
|
||||
|
||||
@@ -33,27 +33,27 @@ bool DB2CascFileSource::IsOpen() const
|
||||
bool DB2CascFileSource::Read(void* buffer, std::size_t numBytes)
|
||||
{
|
||||
uint32 bytesRead = 0;
|
||||
return CASC::ReadFile(_fileHandle, buffer, numBytes, &bytesRead) && numBytes == bytesRead;
|
||||
return _fileHandle->ReadFile(buffer, numBytes, &bytesRead) && numBytes == bytesRead;
|
||||
}
|
||||
|
||||
int64 DB2CascFileSource::GetPosition() const
|
||||
{
|
||||
return CASC::GetFilePointer(_fileHandle);
|
||||
return _fileHandle->GetPointer();
|
||||
}
|
||||
|
||||
bool DB2CascFileSource::SetPosition(int64 position)
|
||||
{
|
||||
return CASC::SetFilePointer(_fileHandle, position);
|
||||
return _fileHandle->SetPointer(position);
|
||||
}
|
||||
|
||||
int64 DB2CascFileSource::GetFileSize() const
|
||||
{
|
||||
return CASC::GetFileSize(_fileHandle);
|
||||
return _fileHandle->GetSize();
|
||||
}
|
||||
|
||||
CASC::FileHandle const& DB2CascFileSource::GetHandle() const
|
||||
CASC::File* DB2CascFileSource::GetNativeHandle() const
|
||||
{
|
||||
return _fileHandle;
|
||||
return _fileHandle.get();
|
||||
}
|
||||
|
||||
char const* DB2CascFileSource::GetFileName() const
|
||||
|
||||
@@ -24,17 +24,17 @@
|
||||
|
||||
struct DB2CascFileSource : public DB2FileSource
|
||||
{
|
||||
DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors = true);
|
||||
DB2CascFileSource(std::shared_ptr<CASC::Storage const> storage, uint32 fileDataId, bool printErrors = true);
|
||||
bool IsOpen() const override;
|
||||
bool Read(void* buffer, std::size_t numBytes) override;
|
||||
int64 GetPosition() const override;
|
||||
bool SetPosition(int64 position) override;
|
||||
int64 GetFileSize() const override;
|
||||
CASC::FileHandle const& GetHandle() const;
|
||||
CASC::File* GetNativeHandle() const;
|
||||
char const* GetFileName() const override;
|
||||
|
||||
private:
|
||||
CASC::FileHandle _fileHandle;
|
||||
std::unique_ptr<CASC::File> _fileHandle;
|
||||
std::string _fileName;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
CASC::StorageHandle CascStorage;
|
||||
std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
struct MapEntry
|
||||
{
|
||||
@@ -1158,9 +1158,9 @@ void ExtractMaps(uint32 build)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
bool ExtractFile(CASC::FileHandle const& fileInArchive, std::string const& filename)
|
||||
bool ExtractFile(CASC::File* fileInArchive, std::string const& filename)
|
||||
{
|
||||
int64 fileSize = CASC::GetFileSize(fileInArchive);
|
||||
int64 fileSize = fileInArchive->GetSize();
|
||||
if (fileSize == -1)
|
||||
{
|
||||
printf("Can't read file size of '%s'\n", filename.c_str());
|
||||
@@ -1180,7 +1180,7 @@ bool ExtractFile(CASC::FileHandle const& fileInArchive, std::string const& filen
|
||||
do
|
||||
{
|
||||
readBytes = 0;
|
||||
if (!CASC::ReadFile(fileInArchive, buffer, std::min<uint32>(fileSize, sizeof(buffer)), &readBytes))
|
||||
if (!fileInArchive->ReadFile(buffer, std::min<uint32>(fileSize, sizeof(buffer)), &readBytes))
|
||||
{
|
||||
printf("Can't read file '%s'\n", filename.c_str());
|
||||
fclose(output);
|
||||
@@ -1242,7 +1242,7 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo
|
||||
for (uint32 i = 0; i < header.SectionCount; ++i)
|
||||
{
|
||||
DB2SectionHeader sectionHeader = db2.GetSectionHeader(i);
|
||||
if (sectionHeader.TactId && CASC::HasTactKey(CascStorage, sectionHeader.TactId))
|
||||
if (sectionHeader.TactId && CascStorage->HasTactKey(sectionHeader.TactId))
|
||||
sectionHeader.TactId = 0;
|
||||
|
||||
posAfterHeaders += fwrite(§ionHeader, 1, sizeof(sectionHeader), output);
|
||||
@@ -1256,7 +1256,7 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo
|
||||
do
|
||||
{
|
||||
readBytes = 0;
|
||||
if (!CASC::ReadFile(source.GetHandle(), buffer, std::min<uint32>(fileSize, readBatchSize), &readBytes))
|
||||
if (!source.GetNativeHandle()->ReadFile(buffer, std::min<uint32>(fileSize, readBatchSize), &readBytes))
|
||||
{
|
||||
printf("Can't read file '%s'\n", outputFileName.c_str());
|
||||
fclose(output);
|
||||
@@ -1329,12 +1329,13 @@ void ExtractCameraFiles()
|
||||
uint32 count = 0;
|
||||
for (uint32 cameraFileDataId : CameraFileDataIds)
|
||||
{
|
||||
if (CASC::FileHandle dbcFile = CASC::OpenFile(CascStorage, cameraFileDataId, CASC_LOCALE_NONE))
|
||||
std::unique_ptr<CASC::File> cameraFile(CascStorage->OpenFile(cameraFileDataId, CASC_LOCALE_NONE));
|
||||
if (cameraFile)
|
||||
{
|
||||
boost::filesystem::path filePath = outputPath / Trinity::StringFormat("FILE%08X.xxx", cameraFileDataId);
|
||||
|
||||
if (!boost::filesystem::exists(filePath))
|
||||
if (ExtractFile(dbcFile, filePath.string()))
|
||||
if (ExtractFile(cameraFile.get(), filePath.string()))
|
||||
++count;
|
||||
}
|
||||
else
|
||||
@@ -1384,12 +1385,13 @@ void ExtractGameTables()
|
||||
uint32 count = 0;
|
||||
for (DB2FileInfo const& gt : GameTables)
|
||||
{
|
||||
if (CASC::FileHandle dbcFile = CASC::OpenFile(CascStorage, gt.FileDataId, CASC_LOCALE_NONE))
|
||||
std::unique_ptr<CASC::File> dbcFile(CascStorage->OpenFile(gt.FileDataId, CASC_LOCALE_NONE));
|
||||
if (dbcFile)
|
||||
{
|
||||
boost::filesystem::path filePath = outputPath / gt.Name;
|
||||
|
||||
if (!boost::filesystem::exists(filePath))
|
||||
if (ExtractFile(dbcFile, filePath.string()))
|
||||
if (ExtractFile(dbcFile.get(), filePath.string()))
|
||||
++count;
|
||||
}
|
||||
else
|
||||
@@ -1404,7 +1406,7 @@ bool OpenCascStorage(int locale)
|
||||
try
|
||||
{
|
||||
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
|
||||
CascStorage = CASC::OpenStorage(storage_dir, WowLocaleToCascLocaleFlags[locale], CONF_Product);
|
||||
CascStorage.reset(CASC::Storage::Open(storage_dir, WowLocaleToCascLocaleFlags[locale], CONF_Product));
|
||||
if (!CascStorage)
|
||||
{
|
||||
printf("error opening casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]);
|
||||
@@ -1425,11 +1427,11 @@ uint32 GetInstalledLocalesMask()
|
||||
try
|
||||
{
|
||||
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
|
||||
CASC::StorageHandle storage = CASC::OpenStorage(storage_dir, CASC_LOCALE_ALL_WOW, CONF_Product);
|
||||
std::unique_ptr<CASC::Storage> storage(CASC::Storage::Open(storage_dir, CASC_LOCALE_ALL_WOW, CONF_Product));
|
||||
if (!storage)
|
||||
return false;
|
||||
|
||||
return CASC::GetInstalledLocalesMask(storage);
|
||||
return storage->GetInstalledLocalesMask();
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error const& error)
|
||||
{
|
||||
@@ -1480,7 +1482,6 @@ int main(int argc, char * arg[])
|
||||
if (!RetardCheck())
|
||||
return 1;
|
||||
|
||||
|
||||
uint32 installedLocalesMask = GetInstalledLocalesMask();
|
||||
int32 firstInstalledLocale = -1;
|
||||
uint32 build = 0;
|
||||
@@ -1502,7 +1503,7 @@ int main(int argc, char * arg[])
|
||||
if ((CONF_extract & EXTRACT_DBC) == 0)
|
||||
{
|
||||
firstInstalledLocale = i;
|
||||
build = CASC::GetBuildNumber(CascStorage);
|
||||
build = CascStorage->GetBuildNumber();
|
||||
if (!build)
|
||||
{
|
||||
CascStorage.reset();
|
||||
@@ -1514,7 +1515,7 @@ int main(int argc, char * arg[])
|
||||
}
|
||||
|
||||
//Extract DBC files
|
||||
uint32 tempBuild = CASC::GetBuildNumber(CascStorage);
|
||||
uint32 tempBuild = CascStorage->GetBuildNumber();
|
||||
if (!tempBuild)
|
||||
{
|
||||
CascStorage.reset();
|
||||
|
||||
@@ -33,21 +33,21 @@ ChunkedFile::~ChunkedFile()
|
||||
free();
|
||||
}
|
||||
|
||||
bool ChunkedFile::loadFile(CASC::StorageHandle const& mpq, std::string const& fileName, bool log)
|
||||
bool ChunkedFile::loadFile(std::shared_ptr<CASC::Storage const> mpq, std::string const& fileName, bool log)
|
||||
{
|
||||
free();
|
||||
CASC::FileHandle file = CASC::OpenFile(mpq, fileName.c_str(), CASC_LOCALE_ALL_WOW, log);
|
||||
std::unique_ptr<CASC::File> file(mpq->OpenFile(fileName.c_str(), CASC_LOCALE_ALL_WOW, log));
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
int64 fileSize = CASC::GetFileSize(file);
|
||||
int64 fileSize = file->GetSize();
|
||||
if (fileSize == -1)
|
||||
return false;
|
||||
|
||||
data_size = uint32(fileSize);
|
||||
data = new uint8[data_size];
|
||||
uint32 bytesRead = 0;
|
||||
if (!CASC::ReadFile(file, data, data_size, &bytesRead) || bytesRead != data_size)
|
||||
if (!file->ReadFile(data, data_size, &bytesRead) || bytesRead != data_size)
|
||||
return false;
|
||||
|
||||
parseChunks();
|
||||
@@ -60,21 +60,21 @@ bool ChunkedFile::loadFile(CASC::StorageHandle const& mpq, std::string const& fi
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChunkedFile::loadFile(CASC::StorageHandle const& mpq, uint32 fileDataId, std::string const& description, bool log)
|
||||
bool ChunkedFile::loadFile(std::shared_ptr<CASC::Storage const> mpq, uint32 fileDataId, std::string const& description, bool log)
|
||||
{
|
||||
free();
|
||||
CASC::FileHandle file = CASC::OpenFile(mpq, fileDataId, CASC_LOCALE_ALL_WOW, log);
|
||||
std::unique_ptr<CASC::File> file(mpq->OpenFile(fileDataId, CASC_LOCALE_ALL_WOW, log));
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
int64 fileSize = CASC::GetFileSize(file);
|
||||
int64 fileSize = file->GetSize();
|
||||
if (fileSize == -1)
|
||||
return false;
|
||||
|
||||
data_size = fileSize;
|
||||
data = new uint8[data_size];
|
||||
uint32 bytesRead = 0;
|
||||
if (!CASC::ReadFile(file, data, data_size, &bytesRead) || bytesRead != data_size)
|
||||
if (!file->ReadFile(data, data_size, &bytesRead) || bytesRead != data_size)
|
||||
return false;
|
||||
|
||||
parseChunks();
|
||||
|
||||
@@ -81,8 +81,8 @@ public:
|
||||
ChunkedFile();
|
||||
virtual ~ChunkedFile();
|
||||
bool prepareLoadedData();
|
||||
bool loadFile(CASC::StorageHandle const& mpq, std::string const& fileName, bool log = true);
|
||||
bool loadFile(CASC::StorageHandle const& mpq, uint32 fileDataId, std::string const& description, bool log = true);
|
||||
bool loadFile(std::shared_ptr<CASC::Storage const> mpq, std::string const& fileName, bool log = true);
|
||||
bool loadFile(std::shared_ptr<CASC::Storage const> mpq, uint32 fileDataId, std::string const& description, bool log = true);
|
||||
void free();
|
||||
|
||||
void parseChunks();
|
||||
|
||||
@@ -74,7 +74,7 @@ char* GetExtension(char* FileName)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern CASC::StorageHandle CascStorage;
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
ADTFile::ADTFile(std::string const& filename, bool cache) : _file(CascStorage, filename.c_str(), false)
|
||||
{
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
#include <CascLib.h>
|
||||
#include <cstdio>
|
||||
|
||||
CASCFile::CASCFile(CASC::StorageHandle const& casc, const char* filename, bool warnNoExist /*= true*/) :
|
||||
CASCFile::CASCFile(std::shared_ptr<CASC::Storage const> casc, const char* filename, bool warnNoExist /*= true*/) :
|
||||
eof(false),
|
||||
buffer(nullptr),
|
||||
pointer(0),
|
||||
size(0)
|
||||
{
|
||||
CASC::FileHandle file = CASC::OpenFile(casc, filename, CASC_LOCALE_ALL_WOW, false);
|
||||
std::unique_ptr<CASC::File> file(casc->OpenFile(filename, CASC_LOCALE_ALL_WOW, false));
|
||||
if (!file)
|
||||
{
|
||||
if (warnNoExist || GetLastError() != ERROR_FILE_NOT_FOUND)
|
||||
@@ -34,16 +34,16 @@ CASCFile::CASCFile(CASC::StorageHandle const& casc, const char* filename, bool w
|
||||
return;
|
||||
}
|
||||
|
||||
init(file, filename);
|
||||
init(file.get(), filename);
|
||||
}
|
||||
|
||||
CASCFile::CASCFile(CASC::StorageHandle const& casc, uint32 fileDataId, std::string const& description, bool warnNoExist /*= true*/) :
|
||||
CASCFile::CASCFile(std::shared_ptr<CASC::Storage const> casc, uint32 fileDataId, std::string const& description, bool warnNoExist /*= true*/) :
|
||||
eof(false),
|
||||
buffer(nullptr),
|
||||
pointer(0),
|
||||
size(0)
|
||||
{
|
||||
CASC::FileHandle file = CASC::OpenFile(casc, fileDataId, CASC_LOCALE_ALL_WOW, false);
|
||||
std::unique_ptr<CASC::File> file(casc->OpenFile(fileDataId, CASC_LOCALE_ALL_WOW, false));
|
||||
if (!file)
|
||||
{
|
||||
if (warnNoExist || GetLastError() != ERROR_FILE_NOT_FOUND)
|
||||
@@ -52,12 +52,12 @@ CASCFile::CASCFile(CASC::StorageHandle const& casc, uint32 fileDataId, std::stri
|
||||
return;
|
||||
}
|
||||
|
||||
init(file, description.c_str());
|
||||
init(file.get(), description.c_str());
|
||||
}
|
||||
|
||||
void CASCFile::init(CASC::FileHandle const& file, const char* description)
|
||||
void CASCFile::init(CASC::File* file, const char* description)
|
||||
{
|
||||
int64 fileSize = CASC::GetFileSize(file);
|
||||
int64 fileSize = file->GetSize();
|
||||
if (fileSize == -1)
|
||||
{
|
||||
fprintf(stderr, "Can't open %s, failed to get size: %s!\n", description, CASC::HumanReadableCASCError(GetLastError()));
|
||||
@@ -69,7 +69,7 @@ void CASCFile::init(CASC::FileHandle const& file, const char* description)
|
||||
|
||||
uint32 read = 0;
|
||||
buffer = new char[size];
|
||||
if (!CASC::ReadFile(file, buffer, size, &read) || size != read)
|
||||
if (!file->ReadFile(buffer, size, &read) || size != read)
|
||||
{
|
||||
fprintf(stderr, "Can't read %s, size=%u read=%u: %s\n", description, uint32(size), uint32(read), CASC::HumanReadableCASCError(GetLastError()));
|
||||
eof = true;
|
||||
|
||||
@@ -39,10 +39,10 @@ class CASCFile
|
||||
CASCFile& operator=(const CASCFile &f) = delete;
|
||||
|
||||
public:
|
||||
CASCFile(CASC::StorageHandle const& casc, const char* filename, bool warnNoExist = true); // filenames are not case sensitive
|
||||
CASCFile(CASC::StorageHandle const& casc, uint32 fileDataId, std::string const& description, bool warnNoExist = true);
|
||||
CASCFile(std::shared_ptr<CASC::Storage const> casc, const char* filename, bool warnNoExist = true); // filenames are not case sensitive
|
||||
CASCFile(std::shared_ptr<CASC::Storage const> casc, uint32 fileDataId, std::string const& description, bool warnNoExist = true);
|
||||
~CASCFile() { close(); }
|
||||
void init(CASC::FileHandle const& file, const char* description);
|
||||
void init(CASC::File* file, const char* description);
|
||||
size_t read(void* dest, size_t bytes);
|
||||
size_t getSize() { return size; }
|
||||
size_t getPos() { return pointer; }
|
||||
|
||||
@@ -60,7 +60,7 @@ bool ExtractSingleModel(std::string& fname)
|
||||
return mdl.ConvertToVMAPModel(output.c_str());
|
||||
}
|
||||
|
||||
extern CASC::StorageHandle CascStorage;
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
enum ModelTypes : uint32
|
||||
{
|
||||
@@ -72,12 +72,12 @@ enum ModelTypes : uint32
|
||||
bool GetHeaderMagic(std::string const& fileName, uint32* magic)
|
||||
{
|
||||
*magic = 0;
|
||||
CASC::FileHandle file = CASC::OpenFile(CascStorage, fileName.c_str(), CASC_LOCALE_ALL_WOW);
|
||||
std::unique_ptr<CASC::File> file(CascStorage->OpenFile(fileName.c_str(), CASC_LOCALE_ALL_WOW));
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
uint32 bytesRead = 0;
|
||||
if (!CASC::ReadFile(file, magic, 4, &bytesRead) || bytesRead != 4)
|
||||
if (!file->ReadFile(magic, 4, &bytesRead) || bytesRead != 4)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
extern CASC::StorageHandle CascStorage;
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
Model::Model(std::string &filename) : filename(filename), vertices(0), indices(0)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CASC::StorageHandle CascStorage;
|
||||
std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
struct MapEntry
|
||||
{
|
||||
@@ -106,7 +106,7 @@ bool OpenCascStorage(int locale)
|
||||
try
|
||||
{
|
||||
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
|
||||
CascStorage = CASC::OpenStorage(storage_dir, WowLocaleToCascLocaleFlags[locale], CascProduct);
|
||||
CascStorage.reset(CASC::Storage::Open(storage_dir, WowLocaleToCascLocaleFlags[locale], CascProduct));
|
||||
if (!CascStorage)
|
||||
{
|
||||
printf("error opening casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]);
|
||||
@@ -127,11 +127,11 @@ uint32 GetInstalledLocalesMask()
|
||||
try
|
||||
{
|
||||
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
|
||||
CASC::StorageHandle storage = CASC::OpenStorage(storage_dir, 0, CascProduct);
|
||||
std::unique_ptr<CASC::Storage> storage(CASC::Storage::Open(storage_dir, 0, CascProduct));
|
||||
if (!storage)
|
||||
return false;
|
||||
|
||||
return CASC::GetInstalledLocalesMask(storage);
|
||||
return storage->GetInstalledLocalesMask();
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error const& error)
|
||||
{
|
||||
@@ -453,7 +453,7 @@ int main(int argc, char ** argv)
|
||||
continue;
|
||||
|
||||
FirstLocale = i;
|
||||
uint32 build = CASC::GetBuildNumber(CascStorage);
|
||||
uint32 build = CascStorage->GetBuildNumber();
|
||||
if (!build)
|
||||
{
|
||||
CascStorage.reset();
|
||||
|
||||
@@ -32,7 +32,7 @@ char * wdtGetPlainName(char * FileName)
|
||||
return FileName;
|
||||
}
|
||||
|
||||
extern CASC::StorageHandle CascStorage;
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
WDTFile::WDTFile(uint32 fileDataId, std::string const& description, std::string mapName, bool cache)
|
||||
: _file(CascStorage, fileDataId, description), _mapName(std::move(mapName))
|
||||
|
||||
@@ -36,7 +36,7 @@ WMORoot::WMORoot(std::string const& filename)
|
||||
memset(bbcorn2, 0, sizeof(bbcorn2));
|
||||
}
|
||||
|
||||
extern CASC::StorageHandle CascStorage;
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
bool WMORoot::open()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user