2017-03-08 18:10:02 +01:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2017-03-08 18:10:02 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DB2CascFileSource.h"
|
2019-06-08 13:19:48 +02:00
|
|
|
#include "StringFormat.h"
|
2017-03-08 18:10:02 +01:00
|
|
|
#include <CascLib.h>
|
|
|
|
|
|
2019-06-08 13:19:48 +02:00
|
|
|
DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors /*= true*/)
|
|
|
|
|
{
|
2019-06-09 21:14:42 +02:00
|
|
|
_fileHandle = CASC::OpenFile(storage, fileDataId, CASC_LOCALE_NONE, printErrors, true);
|
2019-06-08 13:19:48 +02:00
|
|
|
_fileName = Trinity::StringFormat("FileDataId: %u", fileDataId);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 18:10:02 +01:00
|
|
|
bool DB2CascFileSource::IsOpen() const
|
|
|
|
|
{
|
|
|
|
|
return _fileHandle != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DB2CascFileSource::Read(void* buffer, std::size_t numBytes)
|
|
|
|
|
{
|
2019-08-10 19:03:24 +02:00
|
|
|
uint32 bytesRead = 0;
|
2017-03-08 18:10:02 +01:00
|
|
|
return CASC::ReadFile(_fileHandle, buffer, numBytes, &bytesRead) && numBytes == bytesRead;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 19:03:24 +02:00
|
|
|
int64 DB2CascFileSource::GetPosition() const
|
2017-03-08 18:10:02 +01:00
|
|
|
{
|
|
|
|
|
return CASC::GetFilePointer(_fileHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 19:03:24 +02:00
|
|
|
bool DB2CascFileSource::SetPosition(int64 position)
|
2018-09-11 21:48:16 +02:00
|
|
|
{
|
|
|
|
|
return CASC::SetFilePointer(_fileHandle, position);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 19:03:24 +02:00
|
|
|
int64 DB2CascFileSource::GetFileSize() const
|
2018-02-18 16:32:03 +01:00
|
|
|
{
|
2019-08-10 19:03:24 +02:00
|
|
|
return CASC::GetFileSize(_fileHandle);
|
2018-02-18 16:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-08 13:19:48 +02:00
|
|
|
CASC::FileHandle const& DB2CascFileSource::GetHandle() const
|
|
|
|
|
{
|
|
|
|
|
return _fileHandle;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 18:10:02 +01:00
|
|
|
char const* DB2CascFileSource::GetFileName() const
|
|
|
|
|
{
|
|
|
|
|
return _fileName.c_str();
|
|
|
|
|
}
|