RDI/src/RDI.cpp
JackCarterSmith 2da49b53ae
Reforge library structure - 3rd pass
Updated CMakeFile with MSVC options

Review Erso lib interface

Better tree display in RDIDebug tool


Change lib interface functions naming


Separate namespace for date file entries
2023-01-12 20:25:10 +01:00

143 lines
3.4 KiB
C++

/**
* @file RDI.cpp
* @date 24/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Data Interface library main entry abstraction file.
*
*/
#if defined(RDI_DLL)
# define RDI_DLLBUILD
#endif
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "config.h"
#include "Erso.hpp"
#include "DatFileEntry.hpp"
#include "Krennic.hpp"
#include "RDI.hpp"
using namespace RDI::DatFile;
/*
* Internal modules instance
*/
static RDI::Erso *ErsoModule = nullptr;
static RDI::Krennic *KrennicModule = nullptr;
/*
* Libs interface
*/
std::string RDI::RDI_getLibVersion() { return PRG_VERSION; }
void RDI::RDI_Init( std::string roguePath ) {
#ifdef DEBUG
std::cout << std::endl << "Running RDI v" << RDI_getLibVersion() << std::endl;
std::cout << "> RSPModelLib v" << "N/A" << std::endl;
std::cout << "> RSPTerrainLib v" << "N/A" << std::endl;
std::cout << "> RSPTextureLib v" << "N/A" << std::endl;
#endif
// Create new instance of Erso module
// Load and extract datas files from DATA.DAT
if (ErsoModule == nullptr) {
#ifdef DEBUG
std::cout << "[RDI][DBG] Loading Erso module..." << std::endl;
#endif
ErsoModule = new RDI::Erso(roguePath);
}
// Create new instance of Krennic module
// Process datas from Erso and build new dataset to be used outside this library
if (ErsoModule != nullptr && KrennicModule == nullptr) {
#ifdef DEBUG
std::cout << "[RDI][DBG] Loading Krennic module..." << std::endl;
#endif
KrennicModule = new RDI::Krennic(ErsoModule);
}
}
unsigned char RDI::RDI_getSectionCount() {
if (ErsoModule == nullptr) return 0;
else return ErsoModule->getDataSectionCount();
}
std::string RDI::RDI_getSectionName( unsigned char id ) {
if (ErsoModule == nullptr) return "";
else return ErsoModule->getDataSectionName(id);
}
unsigned int RDI::RDI_getSectionOffset( unsigned char id ) {
if (ErsoModule == nullptr) return 0;
else return ErsoModule->getDataSectionOffset(id);
}
unsigned int RDI::RDI_getDirectoryElementCount( std::string path ) {
DatFileEntryDirectory* result = nullptr;
if (path.empty()) return 0;
result = dynamic_cast<DatFileEntryDirectory *>(ErsoModule->getElement(boost::filesystem::path(path)));
if (result == nullptr) return 0;
else return result->getSize();
}
std::vector<std::string> RDI::RDI_getDirectoryElements( std::string path ) {
DatFileEntryDirectory* de = nullptr;
std::vector<std::string> elementsNameArray;
elementsNameArray.clear();
if (!path.empty()) {
de = dynamic_cast<DatFileEntryDirectory *>(ErsoModule->getElement(boost::filesystem::path(path)));
if (de != nullptr && de->isDirectory()) {
for (DatFileEntry* de2 : de->getFiles())
elementsNameArray.push_back(de2->getName());
}
}
return elementsNameArray;
}
bool RDI::RDI_isElementDirectory( std::string path ) {
DatFileEntry* result = nullptr;
if (path.empty()) return false;
result = ErsoModule->getElement(boost::filesystem::path(path));
if (result == nullptr) return false;
else return (result->isDirectory() || result->isRootDirectory());
}
std::vector<std::string> RDI::RDI_getLevelsName( void ) {
return KrennicModule->getLevelsList();
}
std::vector<std::string> RDI::RDI_getModelsName( void ) {
return KrennicModule->getModelsList();
}
std::vector<std::string> RDI::RDI_getMusicsName( void ) {
return KrennicModule->getMusicsList();
}
void RDI::RDI_CleanUp(){
if (KrennicModule) delete KrennicModule;
if (ErsoModule) delete ErsoModule;
}