Files tree parser prototype
This commit is contained in:
parent
b00005e6d6
commit
e15934f881
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
namespace RDI {
|
namespace RDI {
|
||||||
|
|
||||||
|
typedef char* MEMFILE;
|
||||||
|
|
||||||
typedef enum e_rdi_result {
|
typedef enum e_rdi_result {
|
||||||
RDI_OK,
|
RDI_OK,
|
||||||
|
|
||||||
|
63
src/DatEntry.cpp
Normal file
63
src/DatEntry.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* @file DatEntry.cpp
|
||||||
|
* @date 20/09/2022
|
||||||
|
* @author JackCarterSmith
|
||||||
|
* @copyright GPL-v3.0
|
||||||
|
* @brief Data file entry descriptor class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DatEntry.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace RDI {
|
||||||
|
|
||||||
|
FileEntry::FileEntry( std::string name, DAT_FILE_FLAGS fFlags, unsigned int size, MEMFILE fPtr ) {
|
||||||
|
this->name = name;
|
||||||
|
this->size = size;
|
||||||
|
this->fFlags.raw = fFlags.raw;
|
||||||
|
this->fileMemPtr = fPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileEntry::~FileEntry() {}
|
||||||
|
|
||||||
|
/*std::string FileEntry::toString() {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
DirectoryEntry::DirectoryEntry( std::string name ) {
|
||||||
|
this->name = name;
|
||||||
|
this->fFlags.raw = 0;
|
||||||
|
this->fFlags.sectionRootDir = 1;
|
||||||
|
vSubFiles = new std::vector<DatEntry*>;
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryEntry::DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags ) {
|
||||||
|
this->name = name;
|
||||||
|
this->fFlags.raw = fFlags.raw;
|
||||||
|
vSubFiles = new std::vector<DatEntry*>;
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryEntry::DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags, DatEntry* hFileEntry ) {
|
||||||
|
this->name = name;
|
||||||
|
this->fFlags.raw = fFlags.raw;
|
||||||
|
vSubFiles = new std::vector<DatEntry*>;
|
||||||
|
AddEntry(hFileEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryEntry::~DirectoryEntry() {}
|
||||||
|
|
||||||
|
/*std::string DirectoryEntry::toString() {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void DirectoryEntry::ClearLinkedFiles() {
|
||||||
|
vSubFiles->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectoryEntry::AddEntry( DatEntry* hFileEntry ) {
|
||||||
|
vSubFiles->push_back(hFileEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
85
src/DatEntry.h
Normal file
85
src/DatEntry.h
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/**
|
||||||
|
* @file DatEntry.h
|
||||||
|
* @date 20/09/2022
|
||||||
|
* @author JackCarterSmith
|
||||||
|
* @copyright GPL-v3.0
|
||||||
|
* @brief Data file entry descriptor class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "RDI_Datatypes.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef DATENTRY_H_
|
||||||
|
#define DATENTRY_H_
|
||||||
|
|
||||||
|
|
||||||
|
namespace RDI {
|
||||||
|
|
||||||
|
typedef union u_file_flags {
|
||||||
|
struct {
|
||||||
|
unsigned short unknown0:1;
|
||||||
|
unsigned short isFile:1;
|
||||||
|
unsigned short unknown1:5;
|
||||||
|
unsigned short isDirectory:1;
|
||||||
|
unsigned short unknown2:7;
|
||||||
|
unsigned short sectionRootDir:1;
|
||||||
|
};
|
||||||
|
unsigned short raw;
|
||||||
|
} DAT_FILE_FLAGS;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DatEntry {
|
||||||
|
public:
|
||||||
|
virtual ~DatEntry() = 0;
|
||||||
|
virtual bool isDirectory() = 0;
|
||||||
|
//virtual std::string toString() = 0;
|
||||||
|
virtual unsigned int getSize() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string name;
|
||||||
|
DAT_FILE_FLAGS fFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class FileEntry : public DatEntry {
|
||||||
|
public:
|
||||||
|
FileEntry( std::string name, DAT_FILE_FLAGS fFlags, unsigned int size, MEMFILE fPtr );
|
||||||
|
~FileEntry();
|
||||||
|
|
||||||
|
MEMFILE getDatas() { return fileMemPtr; }
|
||||||
|
|
||||||
|
//std::string toString();
|
||||||
|
bool isDirectory() { return false; }
|
||||||
|
unsigned int getSize() { return size; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
MEMFILE fileMemPtr;
|
||||||
|
unsigned int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DirectoryEntry : public DatEntry {
|
||||||
|
public:
|
||||||
|
DirectoryEntry( std::string name );
|
||||||
|
DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags );
|
||||||
|
DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags, DatEntry* hFileEntry );
|
||||||
|
~DirectoryEntry();
|
||||||
|
|
||||||
|
void ClearLinkedFiles();
|
||||||
|
void AddEntry( DatEntry* hFileEntry );
|
||||||
|
|
||||||
|
//std::string toString();
|
||||||
|
bool isDirectory() { return true; }
|
||||||
|
unsigned int getSize() { return vSubFiles->size(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<DatEntry*> *vSubFiles;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DATENTRY_H_ */
|
54
src/RDat.cpp
54
src/RDat.cpp
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file RDat.cpp
|
* @file RDat.cpp
|
||||||
* @date 15/09/2022
|
* @date 20/09/2022
|
||||||
* @author JackCarterSmith
|
* @author JackCarterSmith
|
||||||
* @copyright GPL-v3.0
|
* @copyright GPL-v3.0
|
||||||
* @brief Rogue Dat file class interface.
|
* @brief Rogue Dat file class interface.
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#include <RSPTerrain.h>
|
#include <RSPTerrain.h>
|
||||||
#include <RSPTexture.h>
|
#include <RSPTexture.h>
|
||||||
#include <RDI_Datatypes.h>
|
#include <RDI_Datatypes.h>
|
||||||
|
#include "DatEntry.h"
|
||||||
#include "data_struct.h"
|
#include "data_struct.h"
|
||||||
#include "RDat.h"
|
#include "RDat.h"
|
||||||
|
|
||||||
@ -123,11 +124,60 @@ namespace RDI {
|
|||||||
* @return Error status.
|
* @return Error status.
|
||||||
*/
|
*/
|
||||||
RDI_RESULT RDat::ProcessFilesTree() {
|
RDI_RESULT RDat::ProcessFilesTree() {
|
||||||
|
unsigned int curEntriesCount = 0, i;
|
||||||
|
DirectoryEntry* curDir = nullptr;
|
||||||
|
MEMFILE pFileDescriptors = nullptr;
|
||||||
|
|
||||||
|
// Create new root files tree. One per data section.
|
||||||
|
pFTRoot = new std::vector<DirectoryEntry*>(cDatSection);
|
||||||
|
for ( i = 0; i < cDatSection; i++ ) {
|
||||||
|
curDir = new DirectoryEntry(pDatSection->at(i).name);
|
||||||
|
pFTRoot->push_back(curDir);
|
||||||
|
|
||||||
|
// Recalculate files descriptor offset for current section.
|
||||||
|
pFileDescriptors = rDatPtr + pDatSection->at(i).offset +
|
||||||
|
((T_DAT_SECTION*)rDatPtr + pDatSection->at(i).offset)->file_headers_offset;
|
||||||
|
curEntriesCount = (((T_DAT_SECTION*)rDatPtr + pDatSection->at(i).offset)->file_headers_size) / 32;
|
||||||
|
|
||||||
|
// Process arborescente in recursive method.
|
||||||
|
ProcessDirectoryContents(curDir, pFileDescriptors, curEntriesCount, rDatPtr + pDatSection->at(i).offset);
|
||||||
|
}
|
||||||
|
|
||||||
return RDI_OK;
|
return RDI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RDI_RESULT RDat::ProcessDirectoryContents( DirectoryEntry* pCurDir, MEMFILE pDesc, const unsigned int count, MEMFILE pSectionStart ) {
|
||||||
|
unsigned int i;
|
||||||
|
DAT_FILE_FLAGS curEntryFlags = {0};
|
||||||
|
|
||||||
|
FileEntry* newFile = nullptr;
|
||||||
|
DirectoryEntry* newDir = nullptr;
|
||||||
|
std::string tmpStr;
|
||||||
|
|
||||||
} /* namespace RDI */
|
if ( count == 0) return RDI_ERROR_PROCESS;
|
||||||
|
|
||||||
|
for ( i = 0; i < count; i++ ) {
|
||||||
|
curEntryFlags.raw = ((T_FILE_HEADER*)pDesc)->flags;
|
||||||
|
|
||||||
|
tmpStr.clear();
|
||||||
|
tmpStr.append(((T_FILE_HEADER*)pDesc)->name);
|
||||||
|
|
||||||
|
// Test for file or directory
|
||||||
|
if (!curEntryFlags.isDirectory) {
|
||||||
|
newFile = new FileEntry(tmpStr, curEntryFlags, ((T_FILE_HEADER*)pDesc)->datas_size, pSectionStart + ((T_FILE_HEADER*)pDesc)->datas_offset);
|
||||||
|
pCurDir->AddEntry(newFile);
|
||||||
|
} else {
|
||||||
|
newDir = new DirectoryEntry(tmpStr, curEntryFlags);
|
||||||
|
pCurDir->AddEntry(newDir);
|
||||||
|
|
||||||
|
ProcessDirectoryContents(newDir,
|
||||||
|
pDesc + i * sizeof(T_FILE_HEADER),
|
||||||
|
(((T_FILE_HEADER*)pCurDir)->dir_entries_size - sizeof(T_FILE_HEADER)) / sizeof(T_FILE_HEADER),
|
||||||
|
pSectionStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RDI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
13
src/RDat.h
13
src/RDat.h
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "DatEntry.h"
|
||||||
#include "RDI_Datatypes.h"
|
#include "RDI_Datatypes.h"
|
||||||
|
|
||||||
|
|
||||||
@ -17,14 +18,12 @@
|
|||||||
|
|
||||||
namespace RDI {
|
namespace RDI {
|
||||||
|
|
||||||
typedef char* MEMFILE;
|
|
||||||
|
|
||||||
struct dataSection {
|
struct dataSection {
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RDat {
|
class RDat final {
|
||||||
public:
|
public:
|
||||||
RDat( std::string fPath );
|
RDat( std::string fPath );
|
||||||
~RDat();
|
~RDat();
|
||||||
@ -47,10 +46,18 @@ namespace RDI {
|
|||||||
std::vector<struct dataSection> *pDatSection = nullptr;
|
std::vector<struct dataSection> *pDatSection = nullptr;
|
||||||
MEMFILE rDatPtr = nullptr;
|
MEMFILE rDatPtr = nullptr;
|
||||||
|
|
||||||
|
std::vector<DirectoryEntry*> *pFTRoot = nullptr;
|
||||||
|
|
||||||
/* File processing methods */
|
/* File processing methods */
|
||||||
RDI_RESULT DumpLegacyFiles();
|
RDI_RESULT DumpLegacyFiles();
|
||||||
MEMFILE MallocFile( boost::filesystem::path filePath );
|
MEMFILE MallocFile( boost::filesystem::path filePath );
|
||||||
RDI_RESULT ProcessFilesTree();
|
RDI_RESULT ProcessFilesTree();
|
||||||
|
RDI_RESULT ProcessDirectoryContents(
|
||||||
|
DirectoryEntry* pCurDir,
|
||||||
|
MEMFILE pDesc,
|
||||||
|
const unsigned int count,
|
||||||
|
MEMFILE pSectionStart
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,9 +32,12 @@ namespace RDI {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* DATA.DAT content type
|
* DATA.DAT content type
|
||||||
|
* +---------------+-------------------------------------------+
|
||||||
|
* | T_DAT_SECTION | T_FILE_HEADER (file_headers_size x bytes) |
|
||||||
|
* +---------------+-------------------------------------------+
|
||||||
*/
|
*/
|
||||||
typedef struct PACK file_header {
|
typedef struct PACK file_header {
|
||||||
unsigned int datas_offset;
|
unsigned int datas_offset; // From the start of section
|
||||||
unsigned int datas_size; // If file is directory, equal to sum of it's file.
|
unsigned int datas_size; // If file is directory, equal to sum of it's file.
|
||||||
unsigned int reserved0; // 0xFFFFFFFF
|
unsigned int reserved0; // 0xFFFFFFFF
|
||||||
unsigned short flags;
|
unsigned short flags;
|
||||||
@ -43,7 +46,7 @@ namespace RDI {
|
|||||||
} T_FILE_HEADER;
|
} T_FILE_HEADER;
|
||||||
|
|
||||||
typedef struct PACK dat_section {
|
typedef struct PACK dat_section {
|
||||||
unsigned int file_headers_offset;
|
unsigned int file_headers_offset; // From the start of section
|
||||||
unsigned int file_headers_size;
|
unsigned int file_headers_size;
|
||||||
unsigned char files_datas; // Should be used as start pointer for memcpy.
|
unsigned char files_datas; // Should be used as start pointer for memcpy.
|
||||||
} T_DAT_SECTION;
|
} T_DAT_SECTION;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user