diff --git a/include/RDI.hpp b/include/RDI.hpp index 0399849..15d3a48 100644 --- a/include/RDI.hpp +++ b/include/RDI.hpp @@ -51,17 +51,14 @@ namespace RDI { RDI_EXTERN std::string getLibVersion( void ); /** - * @brief Create a new Rogue Data file instance. - * @details Try to open DATA.DAT file at location specified by roguePath. - * If file can be opened, it's mapped in memory and process files list. - * + * @brief Allocate memory and create default structure to access datas. + * @details Try to open DATA.DAT file at location specified by roguePath. + * If file can be opened, it's mapped in memory and process files list. * @param[in] roguePath Path to DATA.DAT and DATA.HDR location. - * - * @return Handler of RogueData file, should be used with other function of this lib. */ - RDI_EXTERN void CreateRDatHandler( std::string roguePath ); - RDI_EXTERN void CreateLegacyHandler( void ); + RDI_EXTERN void Init( std::string roguePath ); + /* Erso specific methods */ RDI_EXTERN unsigned char getSectionCount( void ); RDI_EXTERN std::string getSectionName( unsigned char id ); RDI_EXTERN unsigned int getSectionOffset( unsigned char id ); @@ -70,7 +67,7 @@ namespace RDI { RDI_EXTERN std::vector getDirectoryElements( std::string path ); RDI_EXTERN bool isElementDirectory( std::string path ); - + /* Krennic specific methods */ RDI_EXTERN std::vector getLevelsName( void ); RDI_EXTERN std::vector getModelsName( void ); RDI_EXTERN std::vector getMusicsName( void ); @@ -78,9 +75,7 @@ namespace RDI { /** * @brief Clean up global resources. */ - RDI_EXTERN void DestroyRDatHandler( void ); - RDI_EXTERN void DestroyLegacyHandler( void ); - + RDI_EXTERN void CleanUp( void ); } #endif /* RDI_HPP_ */ diff --git a/src/RDI.cpp b/src/RDI.cpp index caa4b26..b4a4a7d 100644 --- a/src/RDI.cpp +++ b/src/RDI.cpp @@ -23,28 +23,29 @@ /* - * Internal variable + * Internal modules instance */ static RDI::Erso *hErsoModule = nullptr; static RDI::Krennic *hKrennicModule = nullptr; + /* * Libs interface */ - std::string RDI::getLibVersion() { return PRG_VERSION; } -void RDI::CreateRDatHandler( std::string roguePath ){ - if (hErsoModule == nullptr) hErsoModule = new RDI::Erso(roguePath); - - //return hErsoModule; +void RDI::Init( std::string roguePath ){ + if (hErsoModule == nullptr) { + hErsoModule = new RDI::Erso(roguePath); + } + if (hErsoModule != nullptr && hKrennicModule == nullptr) { + hKrennicModule = new RDI::Krennic(hErsoModule); + } } -void RDI::CreateLegacyHandler( void ){ - if (hErsoModule != nullptr) hKrennicModule = new RDI::Krennic(hErsoModule); - //return hKrennicModule; -} + + unsigned char RDI::getSectionCount() { @@ -115,10 +116,7 @@ std::vector RDI::getMusicsName( void ) { return hKrennicModule->getMusicsList(); } -void RDI::DestroyRDatHandler(){ +void RDI::CleanUp(){ + if (hKrennicModule) delete hKrennicModule; if (hErsoModule) delete hErsoModule; } - -void RDI::DestroyLegacyHandler(){ - if (hKrennicModule) delete hKrennicModule; -} diff --git a/tools/RDIdebug.cpp b/tools/RDIDebug.cpp similarity index 94% rename from tools/RDIdebug.cpp rename to tools/RDIDebug.cpp index dd0100e..542f53f 100644 --- a/tools/RDIdebug.cpp +++ b/tools/RDIDebug.cpp @@ -24,9 +24,9 @@ int main( int argc, char *argv[] ) { //cout << "Using RDI lib v" << RDI::getLibVersion() << endl << endl; if ( argc > 1 ) - RDI::CreateRDatHandler(argv[1]); + RDI::Init(argv[1]); else - RDI::CreateRDatHandler("."); + RDI::Init("."); printf("> Section found: %d\n", RDI::getSectionCount()); for ( i = 0; i < RDI::getSectionCount(); i++ ) { @@ -46,7 +46,6 @@ int main( int argc, char *argv[] ) { PrintVirtualDirectoryContents(pathBuilder, prefix); } - RDI::CreateLegacyHandler(); for ( std::string lname : RDI::getLevelsName() ) { printf("Level found: %s\n", lname.c_str()); } @@ -57,7 +56,7 @@ int main( int argc, char *argv[] ) { printf("Music found: %s\n", mname.c_str()); } - RDI::DestroyRDatHandler(); + RDI::CleanUp(); return 0; }