XPlor/libs/zonefile/zonefile.cpp

176 lines
3.3 KiB
C++
Raw Permalink Normal View History

2025-02-08 19:58:54 -05:00
#include "zonefile.h"
2025-09-05 18:35:17 -04:00
#include "xassetlist.h"
#include "xfile.h"
2025-02-08 19:58:54 -05:00
#include <QFile>
2025-09-10 21:58:26 -04:00
#include "xdatastream.h"
2025-02-08 19:58:54 -05:00
#include <QDebug>
ZoneFile::ZoneFile() :
2025-02-19 19:17:31 -05:00
mStem(),
mSize(),
mTagCount(),
mTags(),
mRecordCount(),
mRecords(),
2025-09-05 18:35:17 -04:00
mPlatform(),
mGame(),
mTypeMap(),
mHeaderData(),
mAssetList(this)
{
2025-02-08 19:58:54 -05:00
}
ZoneFile::~ZoneFile() {
}
ZoneFile::ZoneFile(const ZoneFile &aZoneFile) {
2025-02-19 19:17:31 -05:00
mStem = aZoneFile.mStem;
mSize = aZoneFile.mSize;
mTagCount = aZoneFile.mTagCount;
mTags = aZoneFile.mTags;
mRecordCount = aZoneFile.mRecordCount;
mRecords = aZoneFile.mRecords;
2025-09-05 18:35:17 -04:00
mAssetList = aZoneFile.mAssetList;
mHeaderData = aZoneFile.mHeaderData;
2025-02-08 19:58:54 -05:00
}
ZoneFile &ZoneFile::operator=(const ZoneFile &other) {
if (this != &other) {
2025-02-19 19:17:31 -05:00
mStem = other.mStem;
mSize = other.mSize;
mTagCount = other.mTagCount;
mTags = other.mTags;
mRecordCount = other.mRecordCount;
mRecords = other.mRecords;
2025-09-05 18:35:17 -04:00
mAssetList = other.mAssetList;
mHeaderData = other.mHeaderData;
2025-02-08 19:58:54 -05:00
}
return *this;
}
2025-09-05 18:35:17 -04:00
bool ZoneFile::Load(const QByteArray aFileData)
{
2025-09-10 21:58:26 -04:00
XDataStream zoneStream(aFileData);
zoneStream.SetDebug();
2025-09-05 18:35:17 -04:00
mHeaderData.ParseData(&zoneStream);
mAssetList.ParseData(&zoneStream);
return true;
}
bool ZoneFile::Load(const QString aFilePath)
{
QFile file(aFilePath);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "Failed to open file: " << aFilePath;
return false;
}
return Load(file.readAll());
}
QByteArray ZoneFile::GetBinaryData() {
return {};
}
QString ZoneFile::GetStem() const {
2025-02-19 19:17:31 -05:00
return mStem;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
QString ZoneFile::GetBaseStem() const {
return mStem.split('.').first();
}
2025-09-05 18:35:17 -04:00
quint32 ZoneFile::GetSize() const {
2025-02-19 19:17:31 -05:00
return mSize;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
quint32 ZoneFile::GetTagCount() const {
2025-02-19 19:17:31 -05:00
return mTagCount;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
QStringList ZoneFile::GetTags() const {
2025-02-19 19:17:31 -05:00
return mTags;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
QStringList ZoneFile::GetNames() const {
QStringList result;
for (int i = 0; i < mAssetList.Size(); i++)
{
auto current = mAssetList.GetAsset(i);
result.append(current->GetName());
}
return result;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
QVector<XAssetType> ZoneFile::GetTypes() const
{
QVector<XAssetType> result;
for (int i = 0; i < mAssetList.Size(); i++)
{
result.append(mAssetList.GetAsset(i)->GetType());
}
return result;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
XAssetList ZoneFile::GetAssetList() const {
return mAssetList;
2025-02-08 19:58:54 -05:00
}
2025-02-19 19:17:31 -05:00
void ZoneFile::SetStem(const QString aStem) {
mStem = aStem;
2025-02-08 19:58:54 -05:00
}
2025-02-19 19:17:31 -05:00
void ZoneFile::SetSize(quint32 aSize) {
mSize = aSize;
2025-02-08 19:58:54 -05:00
}
2025-02-19 19:17:31 -05:00
void ZoneFile::SetTagCount(quint32 aTagCount) {
mTagCount = aTagCount;
2025-02-08 19:58:54 -05:00
}
2025-02-19 19:17:31 -05:00
void ZoneFile::SetTags(const QStringList aTags) {
mTags = aTags;
2025-02-08 19:58:54 -05:00
}
2025-02-19 19:17:31 -05:00
void ZoneFile::SetRecordCount(quint32 aRecordCount) {
mRecordCount = aRecordCount;
2025-02-08 19:58:54 -05:00
}
2025-02-19 19:17:31 -05:00
void ZoneFile::SetRecords(const QStringList aRecords) {
mRecords = aRecords;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
void ZoneFile::SetHeaderData(XFile aHeaderData)
{
mHeaderData = aHeaderData;
2025-02-08 19:58:54 -05:00
}
2025-09-05 18:35:17 -04:00
void ZoneFile::SetAssetList(XAssetList aAssetList) {
mAssetList = aAssetList;
}
XAssetType ZoneFile::GetType(quint32 aRawType) const
{
if (mTypeMap.contains(aRawType))
{
return mTypeMap[aRawType];
}
2025-09-10 21:58:26 -04:00
qDebug() << "GetType has no enum for " << QString::number(aRawType, 16);
2025-09-05 18:35:17 -04:00
return ASSET_TYPE_NONE;
}
void ZoneFile::pSetType(quint32 aRawType, XAssetType aType)
{
mTypeMap[aRawType] = aType;
}