Tools/Extractors: Refactor CascHandles into classes

This commit is contained in:
Shauren
2020-05-10 15:09:19 +02:00
parent 13053538f2
commit 885d2a7213
15 changed files with 140 additions and 119 deletions
+8 -8
View File
@@ -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();