XPlor/libs/fastfile/PC/fastfile_cod6_pc.cpp

94 lines
2.3 KiB
C++
Raw Normal View History

#include "fastfile_cod6_pc.h"
#include "zonefile_cod6_pc.h"
#include "utils.h"
#include "compression.h"
#include "statusbarmanager.h"
#include <QFile>
#include <QDebug>
FastFile_COD6_PC::FastFile_COD6_PC()
: FastFile() {
SetCompany(COMPANY_INFINITY_WARD);
SetType(FILETYPE_FAST_FILE);
SetSignage(SIGNAGE_UNSIGNED);
SetMagic(0);
SetVersion(0);
SetPlatform("PC");
SetGame("COD6");
}
FastFile_COD6_PC::FastFile_COD6_PC(const QByteArray& aData)
: FastFile_COD6_PC() {
if (!aData.isEmpty()) {
Load(aData);
}
}
FastFile_COD6_PC::FastFile_COD6_PC(const QString aFilePath)
: FastFile_COD6_PC() {
if (!aFilePath.isEmpty()) {
Load(aFilePath);
}
}
FastFile_COD6_PC::~FastFile_COD6_PC() {
}
2025-09-05 18:35:17 -04:00
QByteArray FastFile_COD6_PC::GetBinaryData() const {
return QByteArray();
}
bool FastFile_COD6_PC::Load(const QString aFilePath) {
StatusBarManager::instance().updateStatus("Loading COD5 Fast File w/path", 1000);
if (aFilePath.isEmpty()) {
return false;
}
// Check fastfile can be read
QFile *file = new QFile(aFilePath);
if (!file->open(QIODevice::ReadOnly)) {
qDebug() << QString("Error: Failed to open FastFile: %1!").arg(aFilePath);
return false;
}
// Decompress fastfile and close
const QString fastFileStem = aFilePath.section("/", -1, -1);
SetStem(fastFileStem);
if (!Load(file->readAll())) {
qDebug() << "Error: Failed to load fastfile: " << fastFileStem;
return false;
}
file->close();
// Open zone file after decompressing ff and writing
return true;
}
bool FastFile_COD6_PC::Load(const QByteArray aData) {
StatusBarManager::instance().updateStatus("Loading COD5 Fast File w/data", 1000);
QByteArray decompressedData;
// Assume the first 12 bytes are a header; the rest is zlib-compressed zone data.
const QByteArray compressedData = aData.mid(21);
decompressedData = Compression::DecompressZLIB(compressedData);
Utils::ExportData(GetBaseStem() + ".zone", decompressedData);
2025-09-05 18:35:17 -04:00
ZoneFile_COD6_PC* zoneFile = new ZoneFile_COD6_PC();
zoneFile->SetStem(GetBaseStem() + ".zone");
if (!zoneFile->Load(decompressedData)) {
qWarning() << "Failed to load ZoneFile!";
return false;
}
SetZoneFile(zoneFile);
return true;
}