libcmo21/LibCmo/CKFile.cpp

189 lines
4.9 KiB
C++
Raw Normal View History

2023-02-25 17:39:39 +08:00
#include "CKFile.hpp"
2023-02-26 21:48:03 +08:00
#include "CKStateChunk.hpp"
#include "CKMinContext.hpp"
2023-02-25 17:39:39 +08:00
#include <cstdarg>
2023-02-26 21:48:03 +08:00
namespace LibCmo::CK2 {
2023-02-25 17:39:39 +08:00
#pragma region CKBufferParser
CKBufferParser::CKBufferParser(void* ptr, size_t rsize, bool need_manual_free) :
m_MemBegin(static_cast<char*>(ptr)),
m_MemPos(0u), m_MemSize(rsize),
m_NeedManualFree(need_manual_free) {
;
}
CKBufferParser::~CKBufferParser() {
if (this->m_NeedManualFree) delete[](this->m_MemBegin);
}
#pragma endregion
2023-02-25 22:58:28 +08:00
#pragma region CKFileInfo
2023-02-28 14:04:38 +08:00
CKFileInfo::CKFileInfo() :
ProductVersion(0u), ProductBuild(0x01010000u), FileWriteMode(CK_FILE_WRITEMODE::CKFILE_UNCOMPRESSED),
FileVersion(8u), CKVersion(CKVERSION), FileSize(0u),
ObjectCount(0u), ManagerCount(0u), MaxIDSaved(0u), Crc(0u),
Hdr1PackSize(0u), Hdr1UnPackSize(0u), DataPackSize(0u), DataUnPackSize(0u) {
}
CKFileInfo::CKFileInfo(const CKFileInfo& rhs) :
ProductVersion(rhs.ProductVersion), ProductBuild(rhs.ProductBuild), FileWriteMode(rhs.FileWriteMode),
FileVersion(rhs.FileVersion), CKVersion(rhs.CKVersion), FileSize(rhs.FileSize),
ObjectCount(rhs.ObjectCount), ManagerCount(rhs.ManagerCount), MaxIDSaved(rhs.MaxIDSaved), Crc(rhs.Crc),
Hdr1PackSize(rhs.Hdr1PackSize), Hdr1UnPackSize(rhs.Hdr1UnPackSize),
DataPackSize(rhs.DataPackSize), DataUnPackSize(rhs.DataUnPackSize) {
}
CKFileInfo& CKFileInfo::operator=(const CKFileInfo& rhs) {
this->ProductVersion = rhs.ProductVersion;
this->ProductBuild = rhs.ProductBuild;
this->FileWriteMode = rhs.FileWriteMode;
this->FileVersion = rhs.FileVersion;
this->CKVersion = rhs.CKVersion;
this->FileSize = rhs.FileSize;
this->ObjectCount = rhs.ObjectCount;
this->ManagerCount = rhs.ManagerCount;
this->MaxIDSaved = rhs.MaxIDSaved;
this->Crc = rhs.Crc;
this->Hdr1PackSize = rhs.Hdr1PackSize;
this->Hdr1UnPackSize = rhs.Hdr1UnPackSize;
this->DataPackSize = rhs.DataPackSize;
this->DataUnPackSize = rhs.DataUnPackSize;
return *this;
2023-02-25 22:58:28 +08:00
}
CKFileInfo::~CKFileInfo() {
}
#pragma endregion
2023-02-25 17:39:39 +08:00
#pragma region CKFileObject
2023-02-26 21:48:03 +08:00
CKFileObject::CKFileObject() :
ObjectId(0u), CreatedObject(0u), ObjectCid(CK_CLASSID::CKCID_OBJECT), Name(),
2023-03-03 11:06:26 +08:00
ObjPtr(nullptr), Data(nullptr), FileIndex(0u) {
2023-02-28 14:04:38 +08:00
}
CKFileObject::CKFileObject(const CKFileObject& rhs) :
ObjectId(rhs.ObjectId), CreatedObject(rhs.CreatedObject), ObjectCid(rhs.ObjectCid), Name(rhs.Name),
2023-03-03 11:06:26 +08:00
ObjPtr(rhs.ObjPtr), Data(rhs.Data), FileIndex(rhs.FileIndex) {
2023-02-28 14:04:38 +08:00
2023-03-03 11:06:26 +08:00
// CKObject is managed by CKMinContext, so we just copy its pointer.
// however, we need copy CKStateChunk.
2023-02-28 14:04:38 +08:00
if (this->Data != nullptr) {
this->Data = new(std::nothrow) CKStateChunk(*(rhs.Data));
}
}
CKFileObject& CKFileObject::operator=(const CKFileObject& rhs) {
this->ObjectId = rhs.ObjectId;
this->CreatedObject = rhs.CreatedObject;
2023-02-28 14:04:38 +08:00
this->ObjectCid = rhs.ObjectCid;
this->Name = rhs.Name;
this->FileIndex = rhs.FileIndex;
2023-03-03 11:06:26 +08:00
// CKObject is managed by CKMinContext, so we just copy its pointer.
this->ObjPtr = rhs.ObjPtr;
// however, we need copy CKStateChunk.
2023-02-28 14:04:38 +08:00
this->Data = rhs.Data;
if (this->Data != nullptr) {
this->Data = new(std::nothrow) CKStateChunk(*(rhs.Data));
}
return *this;
2023-02-25 17:39:39 +08:00
}
2023-02-26 21:48:03 +08:00
CKFileObject::~CKFileObject() {
2023-02-28 11:35:54 +08:00
if (Data != nullptr) delete Data;
2023-02-25 17:39:39 +08:00
}
#pragma endregion
2023-02-25 22:58:28 +08:00
#pragma region CKFileManagerData
2023-02-28 11:35:54 +08:00
CKFileManagerData::CKFileManagerData() :
2023-03-03 11:06:26 +08:00
MgrPtr(nullptr), Data(nullptr), Manager(0u, 0u) {
2023-02-28 14:04:38 +08:00
}
CKFileManagerData::CKFileManagerData(const CKFileManagerData& rhs) :
2023-03-03 11:06:26 +08:00
MgrPtr(rhs.MgrPtr), Data(rhs.Data), Manager(rhs.Manager) {
2023-02-28 14:04:38 +08:00
if (this->Data != nullptr) {
this->Data = new(std::nothrow) CKStateChunk(*(rhs.Data));
}
}
CKFileManagerData& CKFileManagerData::operator=(const CKFileManagerData& rhs) {
this->Manager = rhs.Manager;
2023-03-03 11:06:26 +08:00
this->MgrPtr = rhs.MgrPtr;
2023-02-28 14:04:38 +08:00
this->Data = rhs.Data;
if (this->Data != nullptr) {
this->Data = new(std::nothrow) CKStateChunk(*(rhs.Data));
}
return *this;
2023-02-25 22:58:28 +08:00
}
CKFileManagerData::~CKFileManagerData() {
2023-02-28 11:35:54 +08:00
if (Data != nullptr) delete Data;
2023-02-25 22:58:28 +08:00
}
#pragma endregion
#pragma region CKFilePluginDependencies
2023-02-28 14:04:38 +08:00
CKFilePluginDependencies::CKFilePluginDependencies() :
m_PluginCategory(CK_PLUGIN_TYPE::CKPLUGIN_MANAGER_DLL), m_Guids() {
}
CKFilePluginDependencies::CKFilePluginDependencies(const CKFilePluginDependencies& rhs) :
m_PluginCategory(rhs.m_PluginCategory), m_Guids(rhs.m_Guids) {
}
CKFilePluginDependencies& CKFilePluginDependencies::operator=(const CKFilePluginDependencies& rhs) {
this->m_PluginCategory = rhs.m_PluginCategory;
this->m_Guids = rhs.m_Guids;
return *this;
2023-02-25 22:58:28 +08:00
}
CKFilePluginDependencies::~CKFilePluginDependencies() {
}
#pragma endregion
2023-02-25 17:39:39 +08:00
#pragma region ShallowDocument
2023-03-03 11:06:26 +08:00
CKFileDocument::CKFileDocument() {
/*this->m_IndexByClassId.resize(static_cast<size_t>(CK_CLASSID::CKCID_MAXCLASSID));*/
}
2023-02-25 17:39:39 +08:00
2023-03-03 11:06:26 +08:00
CKFileDocument::~CKFileDocument() {
2023-02-25 17:39:39 +08:00
2023-03-03 11:06:26 +08:00
}
2023-02-25 17:39:39 +08:00
#pragma endregion
#pragma region CKFile Misc
CKFile::CKFile(CKMinContext* ctx) :
m_MinCtx(ctx) {
2023-02-25 17:39:39 +08:00
;
}
CKFile::~CKFile() {
}
#pragma endregion
}