libcmo21/LibCmo/CKFile.hpp

194 lines
5.5 KiB
C++
Raw Normal View History

2023-02-25 17:39:39 +08:00
#pragma once
#include "CKDefines.hpp"
#include "CKEnums.hpp"
2023-02-26 21:48:03 +08:00
namespace LibCmo::CK2 {
2023-02-25 17:39:39 +08:00
class CKBufferParser {
private:
char* m_MemBegin;
size_t m_MemPos;
bool m_NeedManualFree;
size_t m_MemSize;
public:
CKBufferParser(void* ptr, size_t rsize, bool need_manual_free);
CKBufferParser(const CKBufferParser&) = delete;
CKBufferParser& operator=(const CKBufferParser&) = delete;
~CKBufferParser();
inline const void* GetPtr(void) { return (this->m_MemBegin + m_MemPos); }
inline void Read(void* data, size_t data_size) {
2023-02-26 21:48:03 +08:00
std::memcpy(data, (this->m_MemBegin + m_MemPos), data_size);
2023-02-25 17:39:39 +08:00
this->m_MemPos += data_size;
}
inline void Write(const void* data, size_t data_size) {
2023-02-26 21:48:03 +08:00
std::memcpy((this->m_MemBegin + m_MemPos), data, data_size);
2023-02-25 17:39:39 +08:00
this->m_MemPos += data_size;
}
inline void* GetBase(void) { return this->m_MemBegin; }
inline size_t GetSize(void) { return this->m_MemSize; }
inline size_t GetCursor(void) { return this->m_MemPos; }
inline void MoveCursor(size_t off) { this->m_MemPos += off; }
inline void SetCursor(size_t off) { this->m_MemPos = off; }
};
#pragma pack(push)
#pragma pack(1)
struct CKRawFileInfo {
CKBYTE NeMo[8];
CKDWORD Crc;
CKDWORD CKVersion;
CKDWORD FileVersion;
CKDWORD Zero;
CKDWORD FileWriteMode;
CKDWORD Hdr1PackSize;
CKDWORD DataPackSize;
CKDWORD DataUnPackSize;
CKDWORD ManagerCount;
CKDWORD ObjectCount;
CKDWORD MaxIDSaved;
CKDWORD ProductVersion;
CKDWORD ProductBuild;
CKDWORD Hdr1UnPackSize;
};
#pragma pack(pop)
class CKFileInfo {
public:
CKFileInfo();
2023-02-28 14:04:38 +08:00
CKFileInfo(const CKFileInfo&);
CKFileInfo& operator=(const CKFileInfo&);
2023-02-25 17:39:39 +08:00
~CKFileInfo();
CKDWORD ProductVersion; // Virtools Version (Dev/Creation). (CK_VIRTOOLS_VERSION)
CKDWORD ProductBuild; // Virtools Build Number.
CK_FILE_WRITEMODE FileWriteMode; // Options used to save this file. (CK_FILE_WRITEMODE)
CKDWORD FileVersion; // Version of file format when file was saved.
CKDWORD CKVersion; // Version of CK when file was saved.
size_t FileSize; // Size of file in bytes.
CKDWORD ObjectCount; // Number of objects stored in the file.
CKDWORD ManagerCount; // Number of managers which saved data in the file.
CKDWORD MaxIDSaved; // Maximum Object identifier saved
CKDWORD Crc; // Crc of data
CKDWORD Hdr1PackSize; // Reserved
CKDWORD Hdr1UnPackSize; // Reserved
CKDWORD DataPackSize; // Reserved
CKDWORD DataUnPackSize; // Reserved
private:
};
class CKFileObject {
public:
CKFileObject();
2023-02-28 14:04:38 +08:00
CKFileObject(const CKFileObject&);
CKFileObject& operator=(const CKFileObject&);
2023-02-25 17:39:39 +08:00
~CKFileObject();
2023-03-03 11:06:26 +08:00
CK_ID ObjectId; // ID of the object being load/saved (as it will be/was saved in the file)
CK_ID CreatedObject; // ID of the object being created
2023-03-03 11:06:26 +08:00
CK_CLASSID ObjectCid; // Class Identifier of the object
CKObjectImplements::CKObject* ObjPtr; // A pointer to the object itself (as CreatedObject when loading)
std::string Name; // Name of the Object
CKStateChunk* Data; // A CKStateChunk that contains object information
CKDWORD FileIndex; // Position of the object data inside uncompressed file buffer
2023-02-25 17:39:39 +08:00
private:
};
class CKFileManagerData {
public:
CKFileManagerData();
2023-02-28 14:04:38 +08:00
CKFileManagerData(const CKFileManagerData&);
CKFileManagerData& operator=(const CKFileManagerData&);
2023-02-25 17:39:39 +08:00
~CKFileManagerData();
2023-03-03 11:06:26 +08:00
CKManagerImplements::CKBaseManager* MgrPtr;
2023-02-25 17:39:39 +08:00
CKStateChunk* Data;
CKGUID Manager;
private:
};
class CKFilePluginDependencies {
public:
CKFilePluginDependencies();
2023-02-28 14:04:38 +08:00
CKFilePluginDependencies(const CKFilePluginDependencies&);
CKFilePluginDependencies& operator=(const CKFilePluginDependencies&);
2023-02-25 17:39:39 +08:00
~CKFilePluginDependencies();
CK_PLUGIN_TYPE m_PluginCategory;
XArray<CKGUID> m_Guids;
private:
};
2023-03-03 11:06:26 +08:00
class CKFileDocument {
public:
CKFileDocument();
~CKFileDocument();
2023-02-25 17:39:39 +08:00
2023-03-03 11:06:26 +08:00
int32_t m_SaveIDMax;
CKFileInfo m_FileInfo;
2023-02-25 17:39:39 +08:00
2023-03-03 11:06:26 +08:00
XArray<CKFileObject> m_FileObjects;
XArray<CKFileManagerData> m_FileManagersData;
XClassArray<CKFilePluginDependencies> m_PluginDep;
/*XClassArray<XIntArray> m_IndexByClassId;*/
XClassArray<XString> m_IncludedFiles;
private:
2023-02-25 17:39:39 +08:00
2023-03-03 11:06:26 +08:00
};
2023-02-25 17:39:39 +08:00
class CKFile {
public:
CKFile(CKMinContext* ctx);
CKFile(const CKFile&) = delete;
CKFile& operator=(const CKFile&) = delete;
~CKFile();
void ClearData(void);
2023-03-03 11:06:26 +08:00
CKERROR ShallowLoad(CKSTRING u8_filename, CKFileDocument** out_doc);
CKERROR DeepLoad(CKSTRING u8_filename, CKFileDocument** out_doc);
2023-02-25 17:39:39 +08:00
2023-03-03 11:06:26 +08:00
CKERROR Save(CKSTRING u8_filename, CKFileDocument* in_doc);
2023-02-25 17:39:39 +08:00
//CKERROR Load(CKSTRING u8_filename, /*CKObjectArray list, */ CK_LOAD_FLAGS flags);
//CKERROR OpenFile(CKSTRING u8_filename, CK_LOAD_FLAGS flags);
//CKERROR OpenMemory(void* MemoryBuffer, size_t BufferSize, CK_LOAD_FLAGS Flags);
//CKERROR ReadFileHeaders(CKBufferParser** ParserPtr);
//CKERROR ReadFileData(CKBufferParser** ParserPtr);
//CKERROR LoadFileData(void/*CKObjectArray list*/);
//CKERROR FinishLoading(/*CKObjectArray list, */CK_LOAD_FLAGS flags);
//int32_t m_SaveIDMax;
//XArray<CKFileObject> m_FileObject;
//XArray<CKFileManagerData> m_ManagersData;
//XClassArray<CKFilePluginDependencies> m_PluginDep;
//XClassArray<XIntArray> m_IndexByClassId;
//XClassArray<XString> m_IncludedFiles;
//CKFileInfo m_FileInfo;
//CK_LOAD_FLAGS m_Flags;
//bool m_ReadFileDataDone;
private:
// reader function and variables
2023-03-03 11:06:26 +08:00
CKERROR ReadFileHeader(CKBufferParser* ParserPtr, CKFileDocument* doc);
CKERROR ReadFileData(CKBufferParser* ParserPtr, CKFileDocument* doc);
2023-02-25 17:39:39 +08:00
// writer function and varibales
// shared function and variables
CKMinContext* m_MinCtx;
};
}