almost finish vt file reader

This commit is contained in:
yyc12345 2023-02-18 14:14:29 +08:00
parent 522660e65a
commit 4173de5d2c
3 changed files with 65 additions and 14 deletions

View File

@ -230,6 +230,7 @@ namespace LibCmo {
CKERROR CKFile::ReadFileData(CKBufferParser** ParserPtr) {
CKBufferParser* parser = *ParserPtr;
CKBufferParser* parserSrc = *ParserPtr;
// ========== compress feature process ==========
if (EnumHelper::FlagEnumHas(this->m_FileInfo.FileWriteMode, CK_FILE_WRITEMODE::CKFILE_CHUNKCOMPRESSED_OLD) ||
@ -243,6 +244,9 @@ namespace LibCmo {
delete[] decomp_buffer;
return CKERROR::CKERR_OUTOFMEMORY;
}
// sync to args
*ParserPtr = parser;
}
}
@ -396,6 +400,8 @@ namespace LibCmo {
// move to next
parser->MoveCursor(oldBufLen);
}
// MARK: remove a weird assign: parserSrc = v46; it seems useless.
}
}
@ -412,6 +418,39 @@ namespace LibCmo {
}
}
// ========== included file get ==========
// WARN: we use "parserSrc" to read, not "parser"!!!
for (size_t i = 0; i < this->m_IncludedFiles.size(); ++i) {
// get file name length and resize it
CKDWORD filenamelen = 0u;
parserSrc->Read(&filenamelen, sizeof(CKDWORD));
std::string filename;
filename.resize(filenamelen);
// read filename
if (filenamelen != 0) {
parserSrc->Read(filename.data(), filenamelen);
}
// todo: construct temp folder path
// and regulate file name
// read file body length
CKDWORD filebodylen = 0u;
parserSrc->Read(&filebodylen, sizeof(CKDWORD));
// todo: read file body
parserSrc->MoveCursor(filebodylen);
}
// ========== free parser ==========
if (parserSrc != parser && parserSrc != nullptr) {
// WARN: we should free parserSrc! not free parser
// because "parser" has synced with ParserPtr and will be freed from outside.
delete parserSrc;
}
return CKERROR::CKERR_OK;
}
@ -431,9 +470,9 @@ namespace LibCmo {
// MARK: i assume FinishLoading do not calling mapped file anymore
// free file data
if (this->m_Parser != nullptr) {
delete this->m_Parser;
this->m_Parser = nullptr;
if (*ParserPtr != nullptr) {
delete *ParserPtr;
*ParserPtr = nullptr;
}
if (this->m_MappedFile != nullptr) {
delete this->m_MappedFile;

View File

@ -4,7 +4,7 @@
#include <zconf.h>
#endif
#include <zlib.h>;
#include <zlib.h>
#include "VTStruct.hpp"
namespace LibCmo {
@ -190,10 +190,6 @@ namespace LibCmo {
return 0u;
}
bool CKStateChunk::SeekIdentifier(CKDWORD identifier) {
return false;
}
bool CKStateChunk::UnPack(CKDWORD DestSize) {
// NOTE: in UnPack. pData store the compressed buffer, and
// dwSize store the length of compressed buffer as CHAR size, not DWORD size!
@ -223,6 +219,18 @@ namespace LibCmo {
return true;
}
CKDWORD CKStateChunk::GetDataSize(void) {
return sizeof(CKDWORD) * this->m_DataDwSize;
}
bool CKStateChunk::SeekIdentifier(CKDWORD identifier) {
return false;
}
void CKStateChunk::ReadString(std::string& strl) {
;
}
void LibCmo::CKStateChunk::_EnsureEnoughSpace(CKDWORD size) {
;
}

View File

@ -41,14 +41,18 @@ int main() {
CKContext* ctx = NULL;
Assert(!CKCreateContext(&ctx, NULL, 0), "Fail to execute CKCreateContext()");
// call saver
// call reader
CKObjectArray* array = CreateCKObjectArray();
CKObject* objs = ctx->CreateObject(CKCID_OBJECT, "fuck dassault", CK_OBJECTCREATION_NONAMECHECK, NULL);
array->AddIfNotHere(objs);
Assert(!ctx->Load("Language.old.nmo", array, CK_LOAD_DEFAULT, NULL), "Fail to load CMO file");
CKDependencies* dep = CKGetDefaultClassDependencies(CK_DEPENDENCIES_SAVE);
dep->m_Flags = CK_DEPENDENCIES_FULL;
Assert(!ctx->Save("result.cmo", array, 0xFFFFFFFF, dep, NULL), "Fail to save CMO file");
// call saver
//CKObjectArray* array = CreateCKObjectArray();
//CKObject* objs = ctx->CreateObject(CKCID_OBJECT, "fuck dassault", CK_OBJECTCREATION_NONAMECHECK, NULL);
//array->AddIfNotHere(objs);
//CKDependencies* dep = CKGetDefaultClassDependencies(CK_DEPENDENCIES_SAVE);
//dep->m_Flags = CK_DEPENDENCIES_FULL;
//Assert(!ctx->Save("result.cmo", array, 0xFFFFFFFF, dep, NULL), "Fail to save CMO file");
DeleteCKObjectArray(array);
CKCloseContext(ctx);