Reforge library structure - 2nd pass

This commit is contained in:
JackCarterSmith 2022-09-25 22:14:54 +02:00
parent b21372d1b9
commit 26629d56bc
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
3 changed files with 23 additions and 31 deletions

View File

@ -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<std::string> getDirectoryElements( std::string path );
RDI_EXTERN bool isElementDirectory( std::string path );
/* Krennic specific methods */
RDI_EXTERN std::vector<std::string> getLevelsName( void );
RDI_EXTERN std::vector<std::string> getModelsName( void );
RDI_EXTERN std::vector<std::string> 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_ */

View File

@ -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<std::string> 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;
}

View File

@ -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;
}