XPlor/libs/zonefile/zonefile.cpp

246 lines
4.7 KiB
C++
Raw 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"
#include "xdatastream.h"
#include "xcommoninfo.h"
2025-02-08 19:58:54 -05:00
#include <QFile>
#include <QDebug>
ZoneFile::ZoneFile()
: mStem()
, mSize()
, mTagCount()
, mTags()
, mRecordCount()
, mRecords()
, mCommonInfo(nullptr)
, mTypeMap()
, mHeaderData()
, mAssetList(this)
, mDebug(false)
2025-09-05 18:35:17 -04:00
{
2025-02-08 19:58:54 -05:00
}
ZoneFile::ZoneFile(const ZoneFile &aZoneFile)
: mStem(aZoneFile.mStem)
, mSize(aZoneFile.mSize)
, mTagCount(aZoneFile.mTagCount)
, mTags(aZoneFile.mTags)
, mRecordCount(aZoneFile.mRecordCount)
, mRecords(aZoneFile.mRecords)
, mAssetTypes(aZoneFile.mAssetTypes)
, mCommonInfo(aZoneFile.mCommonInfo)
, mTypeMap(aZoneFile.mTypeMap)
, mHeaderData(aZoneFile.mHeaderData)
, mAssetList(aZoneFile.mAssetList)
{
2025-02-08 19:58:54 -05:00
}
ZoneFile &ZoneFile::operator=(const ZoneFile &other)
{
if (this != &other)
{
mStem = other.mStem;
mSize = other.mSize;
mTagCount = other.mTagCount;
mTags = other.mTags;
2025-02-19 19:17:31 -05:00
mRecordCount = other.mRecordCount;
mRecords = other.mRecords;
mAssetTypes = other.mAssetTypes;
mCommonInfo = other.mCommonInfo;
mTypeMap = other.mTypeMap;
mHeaderData = other.mHeaderData;
mAssetList = other.mAssetList;
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(mDebug);
2025-09-05 18:35:17 -04:00
if (GetCommonInfo()->GetPlatform() == PLATFORM_PC)
{
zoneStream.setByteOrder(QDataStream::LittleEndian);
}
mHeaderData.SetCommonInfo(mCommonInfo);
2025-09-05 18:35:17 -04:00
mHeaderData.ParseData(&zoneStream);
mAssetList.SetCommonInfo(mCommonInfo);
2025-09-05 18:35:17 -04:00
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;
}
quint32 ZoneFile::RecordCount() const
{
return mRecordCount;
}
QStringList ZoneFile::Records() const
{
return mRecords;
}
QVector<XAssetType> ZoneFile::AssetTypes() const
{
return mAssetTypes;
}
void ZoneFile::SetAssetTypes(const QVector<XAssetType> &aAssetTypes)
{
mAssetTypes = aAssetTypes;
}
QMap<quint32, XAssetType> ZoneFile::TypeMap() const
{
return mTypeMap;
}
void ZoneFile::SetTypeMap(const QMap<quint32, XAssetType> &aTypeMap)
{
mTypeMap = aTypeMap;
}
XFile ZoneFile::HeaderData() const
{
return mHeaderData;
}
bool ZoneFile::Debug() const
{
return mDebug;
}
void ZoneFile::SetDebug(bool aDebug)
{
mDebug = aDebug;
}
const XCommonInfo *ZoneFile::GetCommonInfo() const
{
return mCommonInfo;
}
void ZoneFile::SetCommonInfo(const XCommonInfo *newCommonInfo)
{
mCommonInfo = newCommonInfo;
}