Using C++17 filesystem directories

+ Print processing to time to log
This commit is contained in:
JackCarterSmith 2023-02-03 17:35:28 +01:00
parent 05b3c1e88a
commit 7181d65a6e
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24

View File

@ -7,8 +7,13 @@
* *
*/ */
#if __cplusplus < 201703L
#error "This code run on C++17 or upper."
#endif
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <chrono>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
@ -17,13 +22,12 @@
#include <deque> #include <deque>
#include <thread> #include <thread>
#endif #endif
#include <filesystem>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <RDI.hpp> #include <RDI.hpp>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else
#include <sys/stat.h>
#endif #endif
using namespace boost::filesystem; using namespace boost::filesystem;
@ -210,26 +214,18 @@ static void ProcessModels() {
// Launch threaded OBJ file building // Launch threaded OBJ file building
//GenerateModelOBJThreaded(); //GenerateModelOBJThreaded();
//PrintModel(meshCollection.back()); //PrintModel(meshCollection.back());
#ifdef _WIN32
CreateDirectory(".\\objOut", NULL);
#else
mkdir("./objOut");
#endif
for ( RDI::HOB* hobFile : modelCollection ) { for ( RDI::HOB* hobFile : modelCollection ) {
if (hobFile->getObjectCount()) { if (hobFile->isLoaded() && hobFile->getObjectCount()) {
string parentPath = path(hobFile->getFullPath()).parent_path().filename().string(); string parentPath = path(hobFile->getFullPath()).string();
replace(parentPath.begin(), parentPath.end(), '/', '\\'); replace(parentPath.begin(), parentPath.end(), '/', '\\');
#ifdef _WIN32 filesystem::create_directories(".\\objOut\\" + hobFile->getFullPath());
CreateDirectory((".\\objOut\\" + parentPath).c_str(), NULL);
#else
mkdir(("./objOut/" + parentPath).c_str());
#endif
for ( i = 0; i < hobFile->getObjectCount(); i++ ) { for ( i = 0; i < hobFile->getObjectCount(); i++ ) {
cout << " Processing " << hobFile->getFullPath() << "..." << endl; cout << hobFile->getFullPath() << "/" << *(hobFile->getObjectName(i)) << "...";
GenerateModelOBJ(hobFile->getMeshFromObject(i), parentPath, hobFile->getObjectName(i)); GenerateModelOBJ(hobFile->getMeshFromObject(i), parentPath, hobFile->getObjectName(i));
cout << " OK" << endl;
} }
} }
} }
@ -288,12 +284,18 @@ int main( int argc, char *argv[] ) {
for ( std::string lname : RDI::RDI_getLevelsName() ) { for ( std::string lname : RDI::RDI_getLevelsName() ) {
cout << " " << lname << endl; cout << " " << lname << endl;
} }
cout << endl << "> Models found: " << RDI::RDI_getModelsName().size() << endl; cout << endl << "> Models found: " << RDI::RDI_getModelsName().size() << endl;
auto t_start = chrono::high_resolution_clock::now();
ProcessModels(); ProcessModels();
auto t_end = chrono::high_resolution_clock::now();
cout << "Models processing in " << chrono::duration_cast<chrono::seconds>(t_end - t_start).count() << "s" << endl;
cout << endl << "> Textures found: " << RDI::RDI_getTexturesName().size() << endl; cout << endl << "> Textures found: " << RDI::RDI_getTexturesName().size() << endl;
for ( std::string txname : RDI::RDI_getTexturesName() ) { for ( std::string txname : RDI::RDI_getTexturesName() ) {
cout << " " << txname << endl; cout << " " << txname << endl;
} }
cout << endl << "> Musics found: " << RDI::RDI_getMusicsName().size() << endl; cout << endl << "> Musics found: " << RDI::RDI_getMusicsName().size() << endl;
for ( std::string mname : RDI::RDI_getMusicsName() ) { for ( std::string mname : RDI::RDI_getMusicsName() ) {
cout << " " << mname << endl; cout << " " << mname << endl;