diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index 615ea03dc49..84534855b3e 100644 --- a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp +++ b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp @@ -266,7 +266,7 @@ Java_cc_openframeworks_OFAndroid_setAppDataDir( JNIEnv* env, jobject thiz, jst jboolean iscopy; const char *mfile = env->GetStringUTFChars(data_dir, &iscopy); __android_log_print(ANDROID_LOG_INFO,"ofAppAndroidWindow",("setting app dir name to: \"" + string(mfile) + "\"").c_str()); - ofSetDataPathRoot(string(mfile)+"/"); + ofSetDataPathRoot({ string(mfile)+"/" }); env->ReleaseStringUTFChars(data_dir, mfile); } diff --git a/addons/ofxAndroid/src/ofxAndroidSoundPlayer.cpp b/addons/ofxAndroid/src/ofxAndroidSoundPlayer.cpp index 2d1af47887e..747495e69c1 100644 --- a/addons/ofxAndroid/src/ofxAndroidSoundPlayer.cpp +++ b/addons/ofxAndroid/src/ofxAndroidSoundPlayer.cpp @@ -43,7 +43,7 @@ ofxAndroidSoundPlayer::~ofxAndroidSoundPlayer(){ //------------------------------------------------------------ -bool ofxAndroidSoundPlayer::load(const std::filesystem::path& fileName, bool stream){ +bool ofxAndroidSoundPlayer::load(const of::filesystem::path& fileName, bool stream){ if(!javaSoundPlayer){ ofLogError("ofxAndroidSoundPlayer") << "loadSound(): java SoundPlayer not loaded"; return false; diff --git a/addons/ofxAndroid/src/ofxAndroidSoundPlayer.h b/addons/ofxAndroid/src/ofxAndroidSoundPlayer.h index 86cde2e3c56..d077bc21f9d 100644 --- a/addons/ofxAndroid/src/ofxAndroidSoundPlayer.h +++ b/addons/ofxAndroid/src/ofxAndroidSoundPlayer.h @@ -8,7 +8,7 @@ class ofxAndroidSoundPlayer: public ofBaseSoundPlayer{ ofxAndroidSoundPlayer(); virtual ~ofxAndroidSoundPlayer(); - bool load(const std::filesystem::path& fileName, bool stream = false); + bool load(const of::filesystem::path& fileName, bool stream = false); void unload(); void play(); void stop(); diff --git a/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp b/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp index 6df5aafd99c..f5c3effc0ba 100644 --- a/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp +++ b/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp @@ -388,20 +388,20 @@ void ofxAssimpModelLoader::loadGLResources(){ auto ogPath = texPathStr; bool bHasEmbeddedTexture = false; - string modelFolder = ofFilePath::getEnclosingDirectory( file.path() ); - string relTexPath = ofFilePath::getEnclosingDirectory(texPathStr,false); - string texFile = ofFilePath::getFileName(texPathStr); - string realPath = ofFilePath::join(ofFilePath::join(modelFolder, relTexPath), texFile); + auto modelFolder = ofFilePath::getEnclosingDirectory( file.path() ); + auto relTexPath = ofFilePath::getEnclosingDirectory(texPathStr,false); + auto realPath = modelFolder / of::filesystem::path{ texPathStr }; + #ifndef TARGET_LINUX_ARM if(bTryEmbed || ofFile::doesFileExist(realPath) == false) { auto embeddedTexture = scene->GetEmbeddedTexture(ogPath.c_str()); if( embeddedTexture ){ bHasEmbeddedTexture = true; - ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource() texture " << texFile << " is embedded "; + ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource() texture " << realPath.filename() << " is embedded "; }else{ ofLogError("ofxAssimpModelLoader") << "loadGLResource(): texture doesn't exist: \"" - << file.getFileName() + "\" in \"" << realPath << "\""; + << file.getFileName() + "\" in \"" << realPath.string() << "\""; } } #endif @@ -419,7 +419,7 @@ void ofxAssimpModelLoader::loadGLResources(){ meshHelper.addTexture(assimpTexture); ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource(): texture already loaded: \"" - << file.getFileName() + "\" from \"" << realPath << "\"" << " adding texture as " << assimpTexture.getTextureTypeAsString() ; + << file.getFileName() + "\" from \"" << realPath.string() << "\"" << " adding texture as " << assimpTexture.getTextureTypeAsString() ; } else { shared_ptr texture = std::make_shared(); @@ -463,7 +463,7 @@ void ofxAssimpModelLoader::loadGLResources(){ ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource(): texture " << tmpTex.getTextureTypeAsString() << " loaded, dimensions: " << texture->getWidth() << "x" << texture->getHeight(); }else{ ofLogError("ofxAssimpModelLoader") << "loadGLResource(): couldn't load texture: \"" - << file.getFileName() + "\" from \"" << realPath << "\""; + << file.getFileName() + "\" from \"" << realPath.string() << "\""; } } } diff --git a/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.h b/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.h index 37f34847adf..ee189c821d4 100644 --- a/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.h +++ b/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.h @@ -19,6 +19,7 @@ #include "ofxAssimpTexture.h" #include "ofMesh.h" #include "ofMath.h" +#include "ofConstants.h" #include @@ -177,7 +178,10 @@ class ofxAssimpModelLoader{ glm::mat4 modelMatrix; std::vector lights; - std::map> textures; + std::map< + of::filesystem::path, + std::shared_ptr + > textures; std::vector modelMeshes; std::vector animations; int currentAnimation; // DEPRECATED - to be removed with deprecated animation functions. diff --git a/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.cpp b/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.cpp index 52bc151ebef..a733444bec7 100644 --- a/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.cpp +++ b/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.cpp @@ -8,7 +8,7 @@ #include "ofxAssimpTexture.h" #include "ofLog.h" -void ofxAssimpTexture::setup(const ofTexture & texture, std::string texturePath, bool bTexRepeat) { +void ofxAssimpTexture::setup(const ofTexture & texture, const of::filesystem::path & texturePath, bool bTexRepeat) { this->texture = texture; if( bTexRepeat ){ this->texture.setTextureWrap(GL_REPEAT, GL_REPEAT); @@ -42,7 +42,7 @@ ofTexture & ofxAssimpTexture::getTextureRef() { return texture; } -std::string ofxAssimpTexture::getTexturePath() { +of::filesystem::path ofxAssimpTexture::getTexturePath() { return texturePath; } diff --git a/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.h b/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.h index 0c215481abc..f4c0539b344 100644 --- a/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.h +++ b/addons/ofxAssimpModelLoader/src/ofxAssimpTexture.h @@ -14,10 +14,10 @@ class ofxAssimpTexture { public: - void setup(const ofTexture & texture, std::string texturePath, bool bTexRepeat = true); + void setup(const ofTexture & texture, const of::filesystem::path & texturePath, bool bTexRepeat = true); ofTexture & getTextureRef(); - std::string getTexturePath(); + of::filesystem::path getTexturePath(); bool hasTexture(); void setTextureType(aiTextureType aTexType); @@ -27,7 +27,7 @@ class ofxAssimpTexture { private: ofTexture texture; - std::string texturePath; + of::filesystem::path texturePath; aiTextureType textureType; std::string mTexTypeStr; }; diff --git a/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.cpp b/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.cpp index ac112436872..b888e0fb302 100644 --- a/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.cpp +++ b/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.cpp @@ -22,7 +22,7 @@ ofHttpResponse ofxEmscriptenURLFileLoader::get(const string & url){ return ofHttpResponse(); } -int ofxEmscriptenURLFileLoader::getAsync(const string & url, const string & name){ +int ofxEmscriptenURLFileLoader::getAsync(const string & url, const string & name){ ofHttpRequest * req = new ofHttpRequest(url,name,false); #if __EMSCRIPTEN_major__>1 || (__EMSCRIPTEN_major__==1 && __EMSCRIPTEN_minor__>22) emscripten_async_wget2_data(url.c_str(), "GET", "", req, true, &onload_cb, &onerror_cb, NULL); @@ -30,12 +30,12 @@ int ofxEmscriptenURLFileLoader::getAsync(const string & url, const string & na return req->getId(); } -ofHttpResponse ofxEmscriptenURLFileLoader::saveTo(const string & url, const std::filesystem::path & path){ +ofHttpResponse ofxEmscriptenURLFileLoader::saveTo(const string & url, const of::filesystem::path & path){ saveAsync(url,path); return ofHttpResponse(); } -int ofxEmscriptenURLFileLoader::saveAsync(const string & url, const std::filesystem::path & path){ +int ofxEmscriptenURLFileLoader::saveAsync(const string & url, const of::filesystem::path & path){ ofHttpRequest * req = new ofHttpRequest(url,url,true); #if __EMSCRIPTEN_major__>1 || (__EMSCRIPTEN_major__==1 && __EMSCRIPTEN_minor__>22) emscripten_async_wget2(url.c_str(), path.c_str(), "GET", "", req, &onload_file_cb, &onerror_file_cb, NULL); diff --git a/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.h b/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.h index 1c9ae5339be..aa40a7aa282 100644 --- a/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.h +++ b/addons/ofxEmscripten/src/ofxEmscriptenURLFileLoader.h @@ -11,10 +11,10 @@ class ofxEmscriptenURLFileLoader: public ofBaseURLFileLoader { public: ofxEmscriptenURLFileLoader(); virtual ~ofxEmscriptenURLFileLoader(); - ofHttpResponse get(const std::string & url); - int getAsync(const std::string & url, const std::string & name=""); // returns id - ofHttpResponse saveTo(const std::string & url, const std::filesystem::path & path); - int saveAsync(const std::string & url, const std::filesystem::path & path); + ofHttpResponse get(const std::string & url); + int getAsync(const std::string & url, const std::string & name=""); // returns id + ofHttpResponse saveTo(const std::string & url, const of::filesystem::path & path); + int saveAsync(const std::string & url, const of::filesystem::path & path); ofHttpResponse handleRequest(const ofHttpRequest & request); int handleRequestAsync(const ofHttpRequest & request); void remove(int id); diff --git a/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp b/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp index 75388893ec4..c8f353605d4 100644 --- a/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp +++ b/addons/ofxOpenCv/src/ofxCvHaarFinder.cpp @@ -49,6 +49,7 @@ void ofxCvHaarFinder::setNeighbors(unsigned neighbors) { this->neighbors = neighbors; } +// FIXME: convert to of::filesystem::path void ofxCvHaarFinder::setup(std::string haarFile) { this->haarFile = haarFile; diff --git a/addons/ofxPoco/src/ofxXmlPoco.cpp b/addons/ofxPoco/src/ofxXmlPoco.cpp index e5d67affbcd..b69c2431d75 100644 --- a/addons/ofxPoco/src/ofxXmlPoco.cpp +++ b/addons/ofxPoco/src/ofxXmlPoco.cpp @@ -42,8 +42,8 @@ ofxXmlPoco::ofxXmlPoco(){ } -bool ofxXmlPoco::load(const std::filesystem::path & path){ - ofFile file(path, ofFile::ReadOnly); +bool ofxXmlPoco::load(const of::filesystem::path & filePath){ + ofFile file(filePath, ofFile::ReadOnly); if(!file.exists()){ ofLogError("ofxXmlPoco") << "couldn't load, \"" << file.getFileName() << "\" not found"; return false; @@ -53,10 +53,10 @@ bool ofxXmlPoco::load(const std::filesystem::path & path){ } -bool ofxXmlPoco::save(const std::filesystem::path & path){ +bool ofxXmlPoco::save(const of::filesystem::path & filePath){ ofBuffer buffer; buffer.set(toString()); - ofFile file(path, ofFile::WriteOnly); + ofFile file(filePath, ofFile::WriteOnly); return file.writeFromBuffer(buffer); } diff --git a/addons/ofxPoco/src/ofxXmlPoco.h b/addons/ofxPoco/src/ofxXmlPoco.h index a71fa53827a..6998b39a5bf 100644 --- a/addons/ofxPoco/src/ofxXmlPoco.h +++ b/addons/ofxPoco/src/ofxXmlPoco.h @@ -41,8 +41,8 @@ class ofxXmlPoco{ ofxXmlPoco( const ofxXmlPoco& rhs ); const ofxXmlPoco& operator =( const ofxXmlPoco& rhs ); - bool load(const std::filesystem::path & path); - bool save(const std::filesystem::path & path); + bool load(const of::filesystem::path & filePath); + bool save(const of::filesystem::path & filePath); bool addChild( const std::string& path ); void addXml( ofxXmlPoco& xml, bool copyAll = false); diff --git a/addons/ofxSvg/src/ofxSvg.cpp b/addons/ofxSvg/src/ofxSvg.cpp index 670658a6575..d2df34fb83b 100644 --- a/addons/ofxSvg/src/ofxSvg.cpp +++ b/addons/ofxSvg/src/ofxSvg.cpp @@ -2,7 +2,8 @@ #include "ofConstants.h" #include -using namespace std; +using std::string; +using std::vector; extern "C"{ #include "svgtiny.h" @@ -26,18 +27,30 @@ ofPath & ofxSvg::getPathAt(int n){ return paths[n]; } -void ofxSvg::load(std::string path){ - path = ofToDataPath(path); +void ofxSvg::load(of::filesystem::path fileName){ + // fileName = ofToDataPath(fileName); + std::string file = ofToDataPath(fileName); - if(path.compare("") == 0){ - ofLogError("ofxSVG") << "load(): path does not exist: \"" << path << "\""; + // FIXME: I think this is the equivalent of .empty() which is simpler. + // maybe use file exists to check instead? + // if(fileName.compare("") == 0){ + // ofLogError("ofxSVG") << "load(): path does not exist: \"" << fileName << "\""; + // return; + // } + + // ofBuffer buffer = ofBufferFromFile(fileName); + + // loadFromString(buffer.getText(), fileName); + + if(file.compare("") == 0){ + ofLogError("ofxSVG") << "load(): path does not exist: \"" << file << "\""; return; } - ofBuffer buffer = ofBufferFromFile(path); - - loadFromString(buffer.getText(), path); + ofBuffer buffer = ofBufferFromFile(file); + loadFromString(buffer.getText(), file); + } void ofxSvg::loadFromString(std::string stringdata, std::string urlstring){ diff --git a/addons/ofxSvg/src/ofxSvg.h b/addons/ofxSvg/src/ofxSvg.h index 3e79151493d..1c839c38468 100644 --- a/addons/ofxSvg/src/ofxSvg.h +++ b/addons/ofxSvg/src/ofxSvg.h @@ -25,7 +25,7 @@ class ofxSvg { /// \brief Loads an SVG file from the provided filename. /// /// ~~~~ - void load(std::string path); + void load(of::filesystem::path fileName); /// \brief Loads an SVG from a text string. /// diff --git a/addons/ofxUnitTests/src/ofxUnitTests.h b/addons/ofxUnitTests/src/ofxUnitTests.h index cafff93a801..def6da0bf90 100644 --- a/addons/ofxUnitTests/src/ofxUnitTests.h +++ b/addons/ofxUnitTests/src/ofxUnitTests.h @@ -228,9 +228,9 @@ class ofxUnitTestsApp: public ofBaseApp{ const std::string APPVEYOR_API_URL = "APPVEYOR_API_URL"; if(ofGetEnv(APPVEYOR_API_URL)!=""){ //ofSystem("appveyor AddTest -Name " + projectName.string() + " -Framework ofxUnitTests -FileName " + exeName.string() + " -Outcome " + (passed?"Passed":"Failed") + " -Duration " + ofToString(now-then)); - auto projectDir = std::filesystem::canonical(std::filesystem::path(ofFilePath::getCurrentExeDir()) / ".."); + auto projectDir = of::filesystem::canonical(of::filesystem::path(ofFilePath::getCurrentExeDir()) / ".."); auto projectName = projectDir.stem(); - auto exeName = std::filesystem::path(ofFilePath::getCurrentExePath()).filename(); + auto exeName = of::filesystem::path(ofFilePath::getCurrentExePath()).filename(); auto stdOut = logger->getStdOut(); ofStringReplace(stdOut, "\\", "\\\\"); ofStringReplace(stdOut, "\"", "\\\""); diff --git a/addons/ofxXmlSettings/src/ofxXmlSettings.cpp b/addons/ofxXmlSettings/src/ofxXmlSettings.cpp index c23c91d3675..1a545f17105 100644 --- a/addons/ofxXmlSettings/src/ofxXmlSettings.cpp +++ b/addons/ofxXmlSettings/src/ofxXmlSettings.cpp @@ -72,8 +72,8 @@ void ofxXmlSettings::clear(){ //--------------------------------------------------------- bool ofxXmlSettings::load(const string& xmlFile){ - string fullXmlFile = ofToDataPath(xmlFile); - bool loadOkay = doc.LoadFile(fullXmlFile); + auto fullXmlFile = ofToDataPath(xmlFile); + bool loadOkay = doc.LoadFile(fullXmlFile.c_str()); //theo removed bool check as it would //return false if the file exists but was @@ -88,8 +88,8 @@ bool ofxXmlSettings::load(const string& xmlFile){ //--------------------------------------------------------- bool ofxXmlSettings::save(const string& xmlFile){ - string fullXmlFile = ofToDataPath(xmlFile); - return doc.SaveFile(fullXmlFile); + auto fullXmlFile = ofToDataPath(xmlFile); + return doc.SaveFile(fullXmlFile.c_str()); } //--------------------------------------------------------- diff --git a/addons/ofxXmlSettings/src/ofxXmlSettings.h b/addons/ofxXmlSettings/src/ofxXmlSettings.h index 091fbe1a669..0afc2d53d62 100644 --- a/addons/ofxXmlSettings/src/ofxXmlSettings.h +++ b/addons/ofxXmlSettings/src/ofxXmlSettings.h @@ -8,7 +8,6 @@ #include "tinyxml.h" #endif -using namespace std; /* Q: what is the which = 0 argument? diff --git a/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm b/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm index 67aab9449f4..cb0f117afd8 100644 --- a/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm +++ b/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm @@ -62,7 +62,7 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application { currentScreenIndex = 0; // set the root application path - ofSetDataPathRoot([[NSString stringWithFormat:@"%@/", [[NSBundle mainBundle] resourcePath]] cStringUsingEncoding:NSUTF8StringEncoding]); + ofSetDataPathRoot(of::filesystem::path([[NSString stringWithFormat:@"%@/", [[NSBundle mainBundle] resourcePath]] cStringUsingEncoding:NSUTF8StringEncoding])); // show or hide status bar depending on OF_WINDOW or OF_FULLSCREEN [[UIApplication sharedApplication] setStatusBarHidden:(ofxiOSGetOFWindow()->getWindowMode() == OF_FULLSCREEN)]; diff --git a/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.cpp b/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.cpp index 5ec0a0aa68c..6bf3bc9b7ce 100644 --- a/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.cpp +++ b/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.cpp @@ -93,7 +93,7 @@ ofxOpenALSoundPlayer::~ofxOpenALSoundPlayer() { //-------------------------------------------------------------- -bool ofxOpenALSoundPlayer::load(const std::filesystem::path& filePath, bool stream) { +bool ofxOpenALSoundPlayer::load(const of::filesystem::path& filePath, bool stream) { if(!SoundEngineInitialized) { ofxOpenALSoundPlayer::initializeSoundEngine(); diff --git a/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.h b/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.h index f679acc4b71..00a0dd1a943 100644 --- a/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.h +++ b/addons/ofxiOS/src/sound/ofxOpenALSoundPlayer.h @@ -62,7 +62,7 @@ class ofxOpenALSoundPlayer : public ofBaseSoundPlayer{ ofxOpenALSoundPlayer(); ~ofxOpenALSoundPlayer(); - bool load(const std::filesystem::path& fileName, bool stream=false); + bool load(const of::filesystem::path& fileName, bool stream=false); void unload(); void play(); diff --git a/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.h b/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.h index 57d882aad35..4f8034e0c36 100644 --- a/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.h +++ b/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.h @@ -15,7 +15,7 @@ class ofxiOSSoundPlayer : public ofBaseSoundPlayer { ofxiOSSoundPlayer(); ~ofxiOSSoundPlayer(); - bool load(const std::filesystem::path& fileName, bool stream = false); + bool load(const of::filesystem::path& fileName, bool stream = false); void unload(); void play(); void stop(); diff --git a/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm b/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm index b33690d57f4..e9ac41124bf 100644 --- a/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm +++ b/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm @@ -19,7 +19,7 @@ unload(); } -bool ofxiOSSoundPlayer::load(const std::filesystem::path& fileName, bool stream) { +bool ofxiOSSoundPlayer::load(const of::filesystem::path& fileName, bool stream) { if(soundPlayer != NULL) { unload(); } diff --git a/libs/openFrameworks/3d/ofMesh.h b/libs/openFrameworks/3d/ofMesh.h index 763fc25ed64..6dad5a8f96f 100644 --- a/libs/openFrameworks/3d/ofMesh.h +++ b/libs/openFrameworks/3d/ofMesh.h @@ -604,7 +604,7 @@ class ofMesh_{ /// /// It expects that the file will be in the [PLY Format](http://en.wikipedia.org/wiki/PLY_(file_format)). /// It will only load meshes saved in the PLY ASCII format; the binary format is not supported. - void load(const std::filesystem::path& path); + void load(const of::filesystem::path& path); /// \brief Saves the mesh at the passed path in the [PLY Format](http://en.wikipedia.org/wiki/PLY_(file_format)). /// @@ -615,7 +615,7 @@ class ofMesh_{ /// If you're planning on reloading the mesh into ofMesh, ofMesh currently only supports loading the ASCII format. /// /// For more information, see the [PLY format specification](http://paulbourke.net/dataformats/ply/). - void save(const std::filesystem::path& path, bool useBinary = false) const; + void save(const of::filesystem::path& path, bool useBinary = false) const; /// \} diff --git a/libs/openFrameworks/3d/ofMesh.inl b/libs/openFrameworks/3d/ofMesh.inl index 5a2780e0de2..10c451c8bf2 100644 --- a/libs/openFrameworks/3d/ofMesh.inl +++ b/libs/openFrameworks/3d/ofMesh.inl @@ -1086,11 +1086,10 @@ void ofMesh_::append(const ofMesh_ & mesh){ //-------------------------------------------------------------- template -void ofMesh_::load(const std::filesystem::path& path){ - ofFile is(path, ofFile::ReadOnly); +void ofMesh_::load(const of::filesystem::path& path){ + ofFile is = {path, ofFile::ReadOnly}; auto & data = *this; - std::string error; ofBuffer buffer(is); auto backup = data; @@ -1327,7 +1326,7 @@ void ofMesh_::load(const std::filesystem::path& path){ //-------------------------------------------------------------- template -void ofMesh_::save(const std::filesystem::path& path, bool useBinary) const{ +void ofMesh_::save(const of::filesystem::path& path, bool useBinary) const{ ofFile os(path, ofFile::WriteOnly); const auto & data = *this; diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index 8646db4b7db..269c5295828 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -1375,7 +1375,7 @@ void ofAppGLFWWindow::drop_cb(GLFWwindow* windowP_, int numFiles, const char** d drag.position = {instance->events().getMouseX(), instance->events().getMouseY()}; drag.files.resize(numFiles); for(int i=0; i<(int)drag.files.size(); i++){ - drag.files[i] = std::filesystem::path(dropString[i]).string(); + drag.files[i] = of::filesystem::path(dropString[i]).string(); } instance->events().notifyDragEvent(drag); } diff --git a/libs/openFrameworks/gl/ofCubeMap.cpp b/libs/openFrameworks/gl/ofCubeMap.cpp index daa27cf547f..34335867d99 100644 --- a/libs/openFrameworks/gl/ofCubeMap.cpp +++ b/libs/openFrameworks/gl/ofCubeMap.cpp @@ -394,6 +394,7 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { } else { } + // encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ).string(); encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ); } std::string baseName = ofFilePath::getBaseName( data->settings.filePath ); diff --git a/libs/openFrameworks/gl/ofShader.cpp b/libs/openFrameworks/gl/ofShader.cpp index 654aebc2a64..6e838786539 100644 --- a/libs/openFrameworks/gl/ofShader.cpp +++ b/libs/openFrameworks/gl/ofShader.cpp @@ -199,12 +199,12 @@ ofShader & ofShader::operator=(ofShader && mom){ } //-------------------------------------------------------------- -bool ofShader::load(const std::filesystem::path& shaderName) { +bool ofShader::load(const of::filesystem::path& shaderName) { return load(shaderName.string() + ".vert", shaderName.string() + ".frag"); } //-------------------------------------------------------------- -bool ofShader::load(const std::filesystem::path& vertName, const std::filesystem::path& fragName, const std::filesystem::path& geomName) { +bool ofShader::load(const of::filesystem::path& vertName, const of::filesystem::path& fragName, const of::filesystem::path& geomName) { if(vertName.empty() == false) setupShaderFromFile(GL_VERTEX_SHADER, vertName); if(fragName.empty() == false) setupShaderFromFile(GL_FRAGMENT_SHADER, fragName); #ifndef TARGET_OPENGLES @@ -218,7 +218,7 @@ bool ofShader::load(const std::filesystem::path& vertName, const std::filesystem #if !defined(TARGET_OPENGLES) && defined(glDispatchCompute) //-------------------------------------------------------------- -bool ofShader::loadCompute(const std::filesystem::path& shaderName) { +bool ofShader::loadCompute(const of::filesystem::path& shaderName) { return setupShaderFromFile(GL_COMPUTE_SHADER, shaderName) && linkProgram(); } #endif @@ -295,12 +295,12 @@ bool ofShader::setup(const TransformFeedbackSettings & settings) { #endif //-------------------------------------------------------------- -bool ofShader::setupShaderFromFile(GLenum type, const std::filesystem::path& filename) { +bool ofShader::setupShaderFromFile(GLenum type, const of::filesystem::path & filename) { ofBuffer buffer = ofBufferFromFile(filename); // we need to make absolutely sure to have an absolute path here, so that any #includes // within the shader files have a root directory to traverse from. - string absoluteFilePath = ofFilePath::getAbsolutePath(filename, true); - string sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false); + auto absoluteFilePath = ofFilePath::getAbsolutePath(filename, true); + auto sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false); if(buffer.size()) { return setupShaderFromSource(type, buffer.getText(), sourceDirectoryPath); } else { @@ -310,14 +310,15 @@ bool ofShader::setupShaderFromFile(GLenum type, const std::filesystem::path& fil } //-------------------------------------------------------------- -ofShader::Source ofShader::sourceFromFile(GLenum type, const std::filesystem::path& filename) { +ofShader::Source ofShader::sourceFromFile(GLenum type, const of::filesystem::path& filename) { ofBuffer buffer = ofBufferFromFile(filename); // we need to make absolutely sure to have an absolute path here, so that any #includes // within the shader files have a root directory to traverse from. - string absoluteFilePath = ofFilePath::getAbsolutePath(filename, true); - string sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false); + auto absoluteFilePath = ofFilePath::getAbsolutePath(filename, true); + auto sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false); if(buffer.size()) { - return Source{type, buffer.getText(), sourceDirectoryPath}; + // return Source{type, buffer.getText(), sourceDirectoryPath.string() }; + return Source{type, buffer.getText(), sourceDirectoryPath }; } else { ofLogError("ofShader") << "setupShaderFromFile(): couldn't load " << nameForType(type) << " shader " << " from \"" << absoluteFilePath << "\""; return Source{}; @@ -325,6 +326,7 @@ ofShader::Source ofShader::sourceFromFile(GLenum type, const std::filesystem::pa } //-------------------------------------------------------------- +// FIXME: change to of::filesystem bool ofShader::setupShaderFromSource(GLenum type, string source, string sourceDirectoryPath) { return setupShaderFromSource({type, source, sourceDirectoryPath}); } @@ -423,13 +425,14 @@ bool ofShader::setupShaderFromSource(ofShader::Source && source){ */ //-------------------------------------------------------------- -string ofShader::parseForIncludes( const string& source, const std::filesystem::path& sourceDirectoryPath) { +string ofShader::parseForIncludes( const string& source, const of::filesystem::path& sourceDirectoryPath) { vector included; return parseForIncludes( source, included, 0, sourceDirectoryPath); } //-------------------------------------------------------------- -string ofShader::parseForIncludes( const string& source, vector& included, int level, const std::filesystem::path& sourceDirectoryPath) { +// FIXME: update to use fs::path in vector and source +string ofShader::parseForIncludes( const string& source, vector& included, int level, const of::filesystem::path& sourceDirectoryPath) { if ( level > 32 ) { ofLogError( "ofShader", "glsl header inclusion depth limit reached, might be caused by cyclic header inclusion" ); @@ -503,8 +506,12 @@ string ofShader::parseForIncludes( const string& source, vector& include } // we store the absolute paths so as have (more) unique file identifiers. + // FIXME: Included can be a vector of of::filesystem::path in near future + include = ofFile( + sourceDirectoryPath / include + // ).getAbsolutePath().string(); + ).getAbsolutePath(); - include = ofFile(ofFilePath::join(sourceDirectoryPath, include)).getAbsolutePath(); included.push_back( include ); ofBuffer buffer = ofBufferFromFile( include ); @@ -513,7 +520,7 @@ string ofShader::parseForIncludes( const string& source, vector& include continue; } - string currentDir = ofFile(include).getEnclosingDirectory(); + auto currentDir = ofFile(include).getEnclosingDirectory(); output << parseForIncludes( buffer.getText(), included, level + 1, currentDir ) << endl; } diff --git a/libs/openFrameworks/gl/ofShader.h b/libs/openFrameworks/gl/ofShader.h index 7a3806a9ae8..3b0854f8138 100644 --- a/libs/openFrameworks/gl/ofShader.h +++ b/libs/openFrameworks/gl/ofShader.h @@ -26,18 +26,19 @@ typedef ofColor_ ofFloatColor; enum ofLogLevel: short; struct ofShaderSettings { - std::map shaderFiles; + std::map shaderFiles; std::map shaderSources; std::map intDefines; std::map floatDefines; - std::filesystem::path sourceDirectoryPath; + of::filesystem::path sourceDirectoryPath; bool bindDefaults = true; }; class ofShader { struct Source{ - Source(GLuint type, const std::string & source, const std::filesystem::path & directoryPath) + // FIXME: change source to of::filesystem::path + Source(GLuint type, const std::string & source, const of::filesystem::path & directoryPath) :type(type) ,source(source) ,directoryPath(directoryPath){} @@ -47,7 +48,7 @@ class ofShader { GLuint type; std::string source; std::string expandedSource; - std::filesystem::path directoryPath; + of::filesystem::path directoryPath; std::map intDefines; std::map floatDefines; }; @@ -60,20 +61,20 @@ class ofShader { ofShader(ofShader && shader); ofShader & operator=(ofShader && shader); - bool load(const std::filesystem::path& shaderName); - bool load(const std::filesystem::path& vertName, const std::filesystem::path& fragName, const std::filesystem::path& geomName=""); + bool load(const of::filesystem::path& shaderName); + bool load(const of::filesystem::path& vertName, const of::filesystem::path& fragName, const of::filesystem::path& geomName=""); #if !defined(TARGET_OPENGLES) && defined(glDispatchCompute) - bool loadCompute(const std::filesystem::path& shaderName); + bool loadCompute(const of::filesystem::path& shaderName); #endif #if !defined(TARGET_OPENGLES) || defined(TARGET_EMSCRIPTEN) struct TransformFeedbackSettings { - std::map shaderFiles; + std::map shaderFiles; std::map shaderSources; std::vector varyingsToCapture; std::map intDefines; std::map floatDefines; - std::filesystem::path sourceDirectoryPath; + of::filesystem::path sourceDirectoryPath; bool bindDefaults = true; GLuint bufferMode = GL_INTERLEAVED_ATTRIBS; // GL_INTERLEAVED_ATTRIBS or GL_SEPARATE_ATTRIBS }; @@ -231,7 +232,7 @@ class ofShader { // these methods create and compile a shader from source or file // type: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER_EXT etc. bool setupShaderFromSource(GLenum type, std::string source, std::string sourceDirectoryPath = ""); - bool setupShaderFromFile(GLenum type, const std::filesystem::path& filename); + bool setupShaderFromFile(GLenum type, const of::filesystem::path& filename); // links program with all compiled shaders bool linkProgram(); @@ -280,7 +281,7 @@ class ofShader { #endif bool setupShaderFromSource(Source && source); - ofShader::Source sourceFromFile(GLenum type, const std::filesystem::path& filename); + ofShader::Source sourceFromFile(GLenum type, const of::filesystem::path& filename); void checkProgramInfoLog(); bool checkProgramLinkStatus(); void checkShaderInfoLog(GLuint shader, GLenum type, ofLogLevel logLevel); @@ -297,8 +298,8 @@ class ofShader { /// @note Include paths are always specified _relative to the including file's current path_ /// @note Recursive #pragma include statements are possible /// @note Includes will be processed up to 32 levels deep - static std::string parseForIncludes( const std::string& source, const std::filesystem::path& sourceDirectoryPath = ""); - static std::string parseForIncludes( const std::string& source, std::vector& included, int level = 0, const std::filesystem::path& sourceDirectoryPath = ""); + static std::string parseForIncludes( const std::string& source, const of::filesystem::path& sourceDirectoryPath = ""); + static std::string parseForIncludes( const std::string& source, std::vector& included, int level = 0, const of::filesystem::path& sourceDirectoryPath = ""); void checkAndCreateProgram(); #ifdef TARGET_ANDROID diff --git a/libs/openFrameworks/graphics/ofCairoRenderer.cpp b/libs/openFrameworks/graphics/ofCairoRenderer.cpp index 39771dded8c..0e94081a0b8 100644 --- a/libs/openFrameworks/graphics/ofCairoRenderer.cpp +++ b/libs/openFrameworks/graphics/ofCairoRenderer.cpp @@ -37,7 +37,7 @@ ofCairoRenderer::~ofCairoRenderer(){ close(); } -void ofCairoRenderer::setup(string _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle outputsize){ +void ofCairoRenderer::setup(const std::string & _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle outputsize){ if( outputsize.width == 0 || outputsize.height == 0 ){ outputsize.set(0, 0, ofGetViewportWidth(), ofGetViewportHeight()); } diff --git a/libs/openFrameworks/graphics/ofCairoRenderer.h b/libs/openFrameworks/graphics/ofCairoRenderer.h index 5576cb9aec2..560fc134f28 100644 --- a/libs/openFrameworks/graphics/ofCairoRenderer.h +++ b/libs/openFrameworks/graphics/ofCairoRenderer.h @@ -24,7 +24,8 @@ class ofCairoRenderer: public ofBaseRenderer{ IMAGE, FROM_FILE_EXTENSION }; - void setup(std::string filename, Type type=ofCairoRenderer::FROM_FILE_EXTENSION, bool multiPage=true, bool b3D=false, ofRectangle outputsize = ofRectangle(0,0,0,0)); + + void setup(const std::string & filename, Type type=ofCairoRenderer::FROM_FILE_EXTENSION, bool multiPage=true, bool b3D=false, ofRectangle outputsize = ofRectangle(0,0,0,0)); void setupMemoryOnly(Type _type, bool multiPage=true, bool b3D=false, ofRectangle viewport = ofRectangle(0,0,0,0)); void close(); void flush(); diff --git a/libs/openFrameworks/graphics/ofImage.cpp b/libs/openFrameworks/graphics/ofImage.cpp index b3ebdc79d8f..3eaac432043 100644 --- a/libs/openFrameworks/graphics/ofImage.cpp +++ b/libs/openFrameworks/graphics/ofImage.cpp @@ -180,7 +180,7 @@ static int getJpegOptionFromImageLoadSetting(const ofImageLoadSettings &settings } template -static bool loadImage(ofPixels_ & pix, const std::filesystem::path& _fileName, const ofImageLoadSettings& settings){ +static bool loadImage(ofPixels_ & pix, const of::filesystem::path& _fileName, const ofImageLoadSettings& settings){ ofInitFreeImage(); auto uriStr = _fileName.string(); @@ -209,7 +209,7 @@ static bool loadImage(ofPixels_ & pix, const std::filesystem::path& _ return ofLoadImage(pix, ofLoadURL(_fileName.string()).data); } - std::string fileName = ofToDataPath(_fileName, true); + auto fileName = ofToDataPath(_fileName, true); bool bLoaded = false; FIBITMAP * bmp = nullptr; @@ -297,7 +297,7 @@ static bool loadImage(ofPixels_ & pix, const ofBuffer & buffer, const } //---------------------------------------------------------------- -bool ofLoadImage(ofPixels & pix, const std::filesystem::path& path, const ofImageLoadSettings &settings) { +bool ofLoadImage(ofPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings) { return loadImage(pix, path, settings); } @@ -307,7 +307,7 @@ bool ofLoadImage(ofPixels & pix, const ofBuffer & buffer, const ofImageLoadSetti } //---------------------------------------------------------------- -bool ofLoadImage(ofShortPixels & pix, const std::filesystem::path& path, const ofImageLoadSettings &settings) { +bool ofLoadImage(ofShortPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings) { return loadImage(pix, path, settings); } @@ -317,7 +317,7 @@ bool ofLoadImage(ofShortPixels & pix, const ofBuffer & buffer, const ofImageLoad } //---------------------------------------------------------------- -bool ofLoadImage(ofFloatPixels & pix, const std::filesystem::path& path, const ofImageLoadSettings &settings) { +bool ofLoadImage(ofFloatPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings) { return loadImage(pix, path, settings); } @@ -327,7 +327,7 @@ bool ofLoadImage(ofFloatPixels & pix, const ofBuffer & buffer, const ofImageLoad } //---------------------------------------------------------------- -bool ofLoadImage(ofTexture & tex, const std::filesystem::path& path, const ofImageLoadSettings &settings){ +bool ofLoadImage(ofTexture & tex, const of::filesystem::path& path, const ofImageLoadSettings &settings){ ofPixels pixels; bool loaded = ofLoadImage(pixels, path, settings); if(loaded){ @@ -350,7 +350,7 @@ bool ofLoadImage(ofTexture & tex, const ofBuffer & buffer, const ofImageLoadSett //---------------------------------------------------------------- template -static bool saveImage(const ofPixels_ & _pix, const std::filesystem::path& _fileName, ofImageQualityType qualityLevel) { +static bool saveImage(const ofPixels_ & _pix, const of::filesystem::path& _fileName, ofImageQualityType qualityLevel) { ofInitFreeImage(); if (_pix.isAllocated() == false){ ofLogError("ofImage") << "saveImage(): couldn't save \"" << _fileName << "\", pixels are not allocated"; @@ -358,7 +358,7 @@ static bool saveImage(const ofPixels_ & _pix, const std::filesystem:: } ofFilePath::createEnclosingDirectory(_fileName); - std::string fileName = ofToDataPath(_fileName); + auto fileName = ofToDataPath(_fileName); FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; fif = FreeImage_GetFileType(fileName.c_str(), 0); if(fif == FIF_UNKNOWN) { @@ -435,17 +435,17 @@ static bool saveImage(const ofPixels_ & _pix, const std::filesystem:: } //---------------------------------------------------------------- -bool ofSaveImage(const ofPixels & pix, const std::filesystem::path& fileName, ofImageQualityType qualityLevel){ +bool ofSaveImage(const ofPixels & pix, const of::filesystem::path& fileName, ofImageQualityType qualityLevel){ return saveImage(pix,fileName,qualityLevel); } //---------------------------------------------------------------- -bool ofSaveImage(const ofFloatPixels & pix, const std::filesystem::path& fileName, ofImageQualityType qualityLevel) { +bool ofSaveImage(const ofFloatPixels & pix, const of::filesystem::path& fileName, ofImageQualityType qualityLevel) { return saveImage(pix,fileName,qualityLevel); } //---------------------------------------------------------------- -bool ofSaveImage(const ofShortPixels & pix, const std::filesystem::path& fileName, ofImageQualityType qualityLevel) { +bool ofSaveImage(const ofShortPixels & pix, const of::filesystem::path& fileName, ofImageQualityType qualityLevel) { return saveImage(pix,fileName,qualityLevel); } @@ -603,7 +603,7 @@ ofImage_::ofImage_(const ofPixels_ & pix){ } template -ofImage_::ofImage_(const std::filesystem::path & fileName, const ofImageLoadSettings &settings){ +ofImage_::ofImage_(const of::filesystem::path & fileName, const ofImageLoadSettings &settings){ width = 0; height = 0; bpp = 0; @@ -700,7 +700,7 @@ bool ofImage_::loadImage(const ofFile & file){ //---------------------------------------------------------- template -bool ofImage_::load(const std::filesystem::path& fileName, const ofImageLoadSettings &settings){ +bool ofImage_::load(const of::filesystem::path& fileName, const ofImageLoadSettings &settings){ #if defined(TARGET_ANDROID) ofAddListener(ofxAndroidEvents().unloadGL,this,&ofImage_::unloadTexture); ofAddListener(ofxAndroidEvents().reloadGL,this,&ofImage_::update); @@ -746,7 +746,7 @@ bool ofImage_::loadImage(const ofBuffer & buffer){ //---------------------------------------------------------- template -bool ofImage_::save(const std::filesystem::path& fileName, ofImageQualityType qualityLevel) const { +bool ofImage_::save(const of::filesystem::path& fileName, ofImageQualityType qualityLevel) const { return ofSaveImage(pixels, fileName, qualityLevel); } diff --git a/libs/openFrameworks/graphics/ofImage.h b/libs/openFrameworks/graphics/ofImage.h index 42a2c616b22..e0267ce379e 100644 --- a/libs/openFrameworks/graphics/ofImage.h +++ b/libs/openFrameworks/graphics/ofImage.h @@ -134,27 +134,27 @@ struct ofImageLoadSettings { /// \todo Needs documentation. -bool ofLoadImage(ofPixels & pix, const std::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); +bool ofLoadImage(ofPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); bool ofLoadImage(ofPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings = ofImageLoadSettings()); -bool ofLoadImage(ofFloatPixels & pix, const std::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); +bool ofLoadImage(ofFloatPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); bool ofLoadImage(ofFloatPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings = ofImageLoadSettings()); -bool ofLoadImage(ofShortPixels & pix, const std::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); +bool ofLoadImage(ofShortPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); bool ofLoadImage(ofShortPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings = ofImageLoadSettings()); /// \todo Needs documentation. -bool ofLoadImage(ofTexture & tex, const std::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); +bool ofLoadImage(ofTexture & tex, const of::filesystem::path& path, const ofImageLoadSettings &settings = ofImageLoadSettings()); bool ofLoadImage(ofTexture & tex, const ofBuffer & buffer, const ofImageLoadSettings &settings = ofImageLoadSettings()); /// \todo Needs documentation. -bool ofSaveImage(const ofPixels & pix, const std::filesystem::path& path, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); +bool ofSaveImage(const ofPixels & pix, const of::filesystem::path& path, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); bool ofSaveImage(const ofPixels & pix, ofBuffer & buffer, ofImageFormat format = OF_IMAGE_FORMAT_PNG, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); /// \todo Needs documentation. -bool ofSaveImage(const ofFloatPixels & pix, const std::filesystem::path& path, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); +bool ofSaveImage(const ofFloatPixels & pix, const of::filesystem::path& path, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); bool ofSaveImage(const ofFloatPixels & pix, ofBuffer & buffer, ofImageFormat format = OF_IMAGE_FORMAT_PNG, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); /// \todo Needs documentation. -bool ofSaveImage(const ofShortPixels & pix, const std::filesystem::path& path, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); +bool ofSaveImage(const ofShortPixels & pix, const of::filesystem::path& path, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); bool ofSaveImage(const ofShortPixels & pix, ofBuffer & buffer, ofImageFormat format = OF_IMAGE_FORMAT_PNG, ofImageQualityType qualityLevel = OF_IMAGE_QUALITY_BEST); /// \brief Deallocates FreeImage resources. @@ -173,7 +173,7 @@ class ofImage_ : public ofBaseImage_{ ofImage_(); ofImage_(const ofPixels_ & pix); - ofImage_(const std::filesystem::path & fileName, const ofImageLoadSettings &settings = ofImageLoadSettings()); + ofImage_(const of::filesystem::path & fileName, const ofImageLoadSettings &settings = ofImageLoadSettings()); ofImage_(const ofImage_& mom); ofImage_(ofImage_&& mom); @@ -217,7 +217,7 @@ class ofImage_ : public ofBaseImage_{ /// the data folder. /// \param settings Load options /// \returns true if image loaded correctly. - bool load(const std::filesystem::path& fileName, const ofImageLoadSettings &settings = ofImageLoadSettings()); + bool load(const of::filesystem::path& fileName, const ofImageLoadSettings &settings = ofImageLoadSettings()); /// \brief Loads an image from an ofBuffer instance created by, for /// instance, ofFile::readToBuffer(). @@ -599,7 +599,7 @@ class ofImage_ : public ofBaseImage_{ /// /// \param fileName Saves image to this path, relative to the data folder. /// \param compressionLevel The ofImageQualityType. - bool save(const std::filesystem::path & fileName, ofImageQualityType compressionLevel = OF_IMAGE_QUALITY_BEST) const; + bool save(const of::filesystem::path & fileName, ofImageQualityType compressionLevel = OF_IMAGE_QUALITY_BEST) const; /// \brief This saves the image to the ofBuffer passed with the image /// quality specified by compressionLevel. diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 8802cd3340f..14ef414c850 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -375,13 +375,14 @@ static string linuxFontPathByName(const string& fontname){ #endif //----------------------------------------------------------- -static bool loadFontFace(const std::filesystem::path& _fontname, FT_Face & face, std::filesystem::path & filename, int index){ - std::filesystem::path fontname = _fontname; +static bool loadFontFace(const of::filesystem::path& _fontname, FT_Face & face, of::filesystem::path & filename, int index){ + of::filesystem::path fontname = _fontname; filename = ofToDataPath(_fontname,true); ofFile fontFile(filename,ofFile::Reference); int fontID = index; if(!fontFile.exists()){ #ifdef TARGET_LINUX + // FIXME: update function linuxFontPathByName to use path instead of string filename = linuxFontPathByName(fontname.string()); #elif defined(TARGET_OSX) if(fontname==OF_TTF_SANS){ @@ -698,7 +699,7 @@ ofTrueTypeFont::glyph ofTrueTypeFont::loadGlyph(uint32_t utf8) const{ } //----------------------------------------------------------- -bool ofTrueTypeFont::load(const std::filesystem::path& filename, int fontSize, bool antialiased, bool fullCharacterSet, bool makeContours, float simplifyAmt, int dpi) { +bool ofTrueTypeFont::load(const of::filesystem::path& filename, int fontSize, bool antialiased, bool fullCharacterSet, bool makeContours, float simplifyAmt, int dpi) { ofTrueTypeFontSettings settings(filename,fontSize); settings.antialiased = antialiased; diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.h b/libs/openFrameworks/graphics/ofTrueTypeFont.h index 90933e18f0f..8347d69fec3 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.h +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.h @@ -138,7 +138,7 @@ enum ofTrueTypeFontDirection : uint32_t { struct ofTrueTypeFontSettings{ - std::filesystem::path fontName; + of::filesystem::path fontName; int fontSize = 0; bool antialiased = true; bool contours = false; @@ -148,7 +148,7 @@ struct ofTrueTypeFontSettings{ ofTrueTypeFontDirection direction = OF_TTF_LEFT_TO_RIGHT; std::vector ranges; - ofTrueTypeFontSettings(const std::filesystem::path & name, int size) + ofTrueTypeFontSettings(const of::filesystem::path & name, int size) :fontName(name) ,fontSize(size){} @@ -196,7 +196,7 @@ class ofTrueTypeFont{ /// \param simplifyAmt the amount to simplify the vector contours. Larger number means more simplified. /// \param dpi the dots per inch used to specify rendering size. /// \returns true if the font was loaded correctly. - bool load(const std::filesystem::path& filename, + bool load(const of::filesystem::path& filename, int fontsize, bool _bAntiAliased=true, bool _bFullCharacterSet=true, diff --git a/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp b/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp index 51cc5f05ac3..797acf132ab 100644 --- a/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp +++ b/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp @@ -177,7 +177,7 @@ void ofFmodSoundPlayer::closeFmod(){ } //------------------------------------------------------------ -bool ofFmodSoundPlayer::load(const std::filesystem::path& _fileName, bool stream){ +bool ofFmodSoundPlayer::load(const of::filesystem::path& _fileName, bool stream){ auto fileName = ofToDataPath(_fileName); @@ -206,7 +206,7 @@ bool ofFmodSoundPlayer::load(const std::filesystem::path& _fileName, bool stream int fmodFlags = FMOD_DEFAULT; if(stream)fmodFlags = FMOD_DEFAULT | FMOD_CREATESTREAM; - result = FMOD_System_CreateSound(sys, fileName.data(), fmodFlags, nullptr, &sound); + result = FMOD_System_CreateSound(sys, fileName.c_str(), fmodFlags, nullptr, &sound); if (result != FMOD_OK){ bLoadedOk = false; diff --git a/libs/openFrameworks/sound/ofFmodSoundPlayer.h b/libs/openFrameworks/sound/ofFmodSoundPlayer.h index b54f1b2e62d..838a0c23127 100644 --- a/libs/openFrameworks/sound/ofFmodSoundPlayer.h +++ b/libs/openFrameworks/sound/ofFmodSoundPlayer.h @@ -41,7 +41,7 @@ class ofFmodSoundPlayer : public ofBaseSoundPlayer { ofFmodSoundPlayer(); virtual ~ofFmodSoundPlayer(); - bool load(const std::filesystem::path& fileName, bool stream = false); + bool load(const of::filesystem::path& fileName, bool stream = false); void unload(); void play(); void stop(); diff --git a/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp b/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp index 66244d886e1..8dca8913cbb 100644 --- a/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp +++ b/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp @@ -229,7 +229,7 @@ void ofOpenALSoundPlayer::close(){ } // ---------------------------------------------------------------------------- -bool ofOpenALSoundPlayer::sfReadFile(const std::filesystem::path& path, std::vector & buffer, std::vector & fftAuxBuffer){ +bool ofOpenALSoundPlayer::sfReadFile(const of::filesystem::path& path, std::vector & buffer, std::vector & fftAuxBuffer){ SF_INFO sfInfo; SNDFILE* f = sf_open(path.string().c_str(),SFM_READ,&sfInfo); if(!f){ @@ -283,7 +283,7 @@ bool ofOpenALSoundPlayer::sfReadFile(const std::filesystem::path& path, std::vec #ifdef OF_USING_MPG123 //------------------------------------------------------------ -bool ofOpenALSoundPlayer::mpg123ReadFile(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer){ +bool ofOpenALSoundPlayer::mpg123ReadFile(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer){ int err = MPG123_OK; mpg123_handle * f = mpg123_new(nullptr,&err); if(mpg123_open(f,path.string().c_str())!=MPG123_OK){ @@ -321,7 +321,7 @@ bool ofOpenALSoundPlayer::mpg123ReadFile(const std::filesystem::path& path,std:: #endif //------------------------------------------------------------ -bool ofOpenALSoundPlayer::sfStream(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer){ +bool ofOpenALSoundPlayer::sfStream(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer){ if(!streamf){ SF_INFO sfInfo; streamf = sf_open(path.string().c_str(),SFM_READ,&sfInfo); @@ -384,7 +384,7 @@ bool ofOpenALSoundPlayer::sfStream(const std::filesystem::path& path,std::vector #ifdef OF_USING_MPG123 //------------------------------------------------------------ -bool ofOpenALSoundPlayer::mpg123Stream(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer){ +bool ofOpenALSoundPlayer::mpg123Stream(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer){ if(!mp3streamf){ int err = MPG123_OK; mp3streamf = mpg123_new(nullptr,&err); @@ -435,7 +435,7 @@ bool ofOpenALSoundPlayer::mpg123Stream(const std::filesystem::path& path,std::ve #endif //------------------------------------------------------------ -bool ofOpenALSoundPlayer::stream(const std::filesystem::path& fileName, std::vector & buffer){ +bool ofOpenALSoundPlayer::stream(const of::filesystem::path& fileName, std::vector & buffer){ #ifdef OF_USING_MPG123 if(ofFilePath::getFileExt(fileName)=="mp3" || ofFilePath::getFileExt(fileName)=="MP3" || mp3streamf){ if(!mpg123Stream(fileName,buffer,fftAuxBuffer)) return false; @@ -455,7 +455,7 @@ bool ofOpenALSoundPlayer::stream(const std::filesystem::path& fileName, std::vec return true; } -bool ofOpenALSoundPlayer::readFile(const std::filesystem::path& fileName, std::vector & buffer){ +bool ofOpenALSoundPlayer::readFile(const of::filesystem::path& fileName, std::vector & buffer){ #ifdef OF_USING_MPG123 if(ofFilePath::getFileExt(fileName)!="mp3" && ofFilePath::getFileExt(fileName)!="MP3"){ if(!sfReadFile(fileName,buffer,fftAuxBuffer)) return false; @@ -478,9 +478,9 @@ bool ofOpenALSoundPlayer::readFile(const std::filesystem::path& fileName, std::v } //------------------------------------------------------------ -bool ofOpenALSoundPlayer::load(const std::filesystem::path& _fileName, bool is_stream){ +bool ofOpenALSoundPlayer::load(const of::filesystem::path& _fileName, bool is_stream){ - std::filesystem::path fileName = ofToDataPath(_fileName); + auto fileName = ofToDataPath(_fileName); bMultiPlay = false; isStreaming = is_stream; diff --git a/libs/openFrameworks/sound/ofOpenALSoundPlayer.h b/libs/openFrameworks/sound/ofOpenALSoundPlayer.h index 80df4f90cb6..7a36b77e217 100644 --- a/libs/openFrameworks/sound/ofOpenALSoundPlayer.h +++ b/libs/openFrameworks/sound/ofOpenALSoundPlayer.h @@ -49,7 +49,7 @@ class ofOpenALSoundPlayer : public ofBaseSoundPlayer, public ofThread { ofOpenALSoundPlayer(); virtual ~ofOpenALSoundPlayer(); - bool load(const std::filesystem::path& fileName, bool stream = false); + bool load(const of::filesystem::path& fileName, bool stream = false); void unload(); void play(); void stop(); @@ -93,15 +93,15 @@ class ofOpenALSoundPlayer : public ofBaseSoundPlayer, public ofThread { static void runWindow(std::vector & signal); static void initSystemFFT(int bands); - bool sfReadFile(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); - bool sfStream(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); + bool sfReadFile(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); + bool sfStream(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); #ifdef OF_USING_MPG123 - bool mpg123ReadFile(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); - bool mpg123Stream(const std::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); + bool mpg123ReadFile(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); + bool mpg123Stream(const of::filesystem::path& path,std::vector & buffer,std::vector & fftAuxBuffer); #endif - bool readFile(const std::filesystem::path& fileName,std::vector & buffer); - bool stream(const std::filesystem::path& fileName, std::vector & buffer); + bool readFile(const of::filesystem::path& fileName,std::vector & buffer); + bool stream(const of::filesystem::path& fileName, std::vector & buffer); bool isStreaming; bool bMultiPlay; diff --git a/libs/openFrameworks/sound/ofSoundBaseTypes.h b/libs/openFrameworks/sound/ofSoundBaseTypes.h index 3f2e1aa9883..e81bd73f03d 100644 --- a/libs/openFrameworks/sound/ofSoundBaseTypes.h +++ b/libs/openFrameworks/sound/ofSoundBaseTypes.h @@ -167,7 +167,7 @@ class ofBaseSoundPlayer { ofBaseSoundPlayer(){}; virtual ~ofBaseSoundPlayer(){}; - virtual bool load(const std::filesystem::path& fileName, bool stream = false)=0; + virtual bool load(const of::filesystem::path& fileName, bool stream = false)=0; virtual void unload()=0; virtual void play() = 0; virtual void stop() = 0; diff --git a/libs/openFrameworks/sound/ofSoundPlayer.cpp b/libs/openFrameworks/sound/ofSoundPlayer.cpp index 543a0579428..ad9e95dde47 100644 --- a/libs/openFrameworks/sound/ofSoundPlayer.cpp +++ b/libs/openFrameworks/sound/ofSoundPlayer.cpp @@ -73,7 +73,7 @@ std::shared_ptr ofSoundPlayer::getPlayer(){ } //-------------------------------------------------------------------- -bool ofSoundPlayer::load(const std::filesystem::path& fileName, bool stream){ +bool ofSoundPlayer::load(const of::filesystem::path& fileName, bool stream){ if( player ){ return player->load(fileName, stream); } diff --git a/libs/openFrameworks/sound/ofSoundPlayer.h b/libs/openFrameworks/sound/ofSoundPlayer.h index a24bfdcc50e..5f04073d1d6 100644 --- a/libs/openFrameworks/sound/ofSoundPlayer.h +++ b/libs/openFrameworks/sound/ofSoundPlayer.h @@ -82,7 +82,7 @@ class ofSoundPlayer : public ofBaseSoundPlayer { /// /// \param fileName Path to the sound file, relative to your app's data folder. /// \param stream set "true" to enable streaming from disk (for large files). - bool load(const std::filesystem::path& fileName, bool stream = false); + bool load(const of::filesystem::path& fileName, bool stream = false); OF_DEPRECATED_MSG("Use load",bool loadSound(std::string fileName, bool stream = false)); /// \brief Stops and unloads the current sound. diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index a929d9cdce3..0b5fa781594 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -457,6 +457,7 @@ std::unique_ptr make_unique(Args&&... args) { #define OF_HAS_CPP17 0 #endif + #ifndef OF_USING_STD_FS #if OF_HAS_CPP17 #define OF_USING_STD_FS 1 @@ -514,47 +515,46 @@ std::unique_ptr make_unique(Args&&... args) { namespace std { namespace experimental{ namespace filesystem { - namespace v1 { - class path; - } - using v1::path; + using path = v1::path; } } - namespace filesystem = experimental::filesystem; } #else namespace std { namespace experimental{ namespace filesystem { - namespace v1 { - namespace __cxx11 { - class path; - } - } - using v1::__cxx11::path; + using path = v1::__cxx11::path; } } - namespace filesystem = experimental::filesystem; } #endif + namespace of { + namespace filesystem = std::experimental::filesystem; + } #else - // Regular C++17 fs support - #include + #include + #if OF_HAS_CPP17 + // Regular C++17 fs support + namespace of { + namespace filesystem = std::filesystem; + } + #else + namespace of { + namespace filesystem = std::filesystem; + } + #endif #endif -#else +#else //not OF_USING_STD_FS // No experimental or c++17 filesytem support use boost #if !_MSC_VER #define BOOST_NO_CXX11_SCOPED_ENUMS #define BOOST_NO_SCOPED_ENUMS #endif + #include - namespace boost { - namespace filesystem { - class path; - } - } - namespace std { + namespace of { namespace filesystem = boost::filesystem; } + #endif diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index c88528a3052..6e855e53311 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -14,7 +14,7 @@ #include /* PATH_MAX */ #endif -// FIXME: better explicit declaration +// FIXME: better explicit declaration using std::string; using std::vector; using std::fstream; @@ -23,46 +23,48 @@ using std::ostream; using std::ios; namespace{ - bool enableDataPath = true; + bool enableDataPath = true; - //-------------------------------------------------- - string defaultDataPath(){ - #if defined TARGET_OSX - try{ - return std::filesystem::canonical(ofFilePath::join(ofFilePath::getCurrentExeDir(), "../../../data/")).string(); - }catch(...){ - return ofFilePath::join(ofFilePath::getCurrentExeDir(), "../../../data/"); - } - #elif defined TARGET_ANDROID - return string("sdcard/"); - #else - try{ - return std::filesystem::canonical(ofFilePath::join(ofFilePath::getCurrentExeDir(), "data/")).make_preferred().string(); + //-------------------------------------------------- +// MARK: - near future +// of::filesystem::path defaultDataPath(){ + std::string defaultDataPath(){ + #if defined TARGET_OSX + try{ + return of::filesystem::canonical(ofFilePath::getCurrentExeDir() / of::filesystem::path("../../../data/")).string(); + }catch(...){ + return (ofFilePath::getCurrentExeDir() / of::filesystem::path("../../../data/")).string(); + } + #elif defined TARGET_ANDROID + return string("sdcard/"); + #else + try{ + return of::filesystem::canonical(ofFilePath::join(ofFilePath::getCurrentExeDir(), "data/")).make_preferred().string(); }catch(...){ - return ofFilePath::join(ofFilePath::getCurrentExeDir(), "data/"); - } - #endif - } + return (ofFilePath::getCurrentExeDir() / of::filesystem::path("data/")).string(); + } + #endif + } - //-------------------------------------------------- - std::filesystem::path & defaultWorkingDirectory(){ - static auto * defaultWorkingDirectory = new std::filesystem::path(ofFilePath::getCurrentExeDir()); - return * defaultWorkingDirectory; - } + //-------------------------------------------------- + of::filesystem::path & defaultWorkingDirectory(){ + static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDir()); + return * defaultWorkingDirectory; + } - //-------------------------------------------------- - std::filesystem::path & dataPathRoot(){ - static auto * dataPathRoot = new std::filesystem::path(defaultDataPath()); - return *dataPathRoot; - } + //-------------------------------------------------- + of::filesystem::path & dataPathRoot(){ + static auto * dataPathRoot = new of::filesystem::path(defaultDataPath()); + return *dataPathRoot; + } } namespace of{ - namespace priv{ - void initfileutils(){ - defaultWorkingDirectory() = std::filesystem::absolute(std::filesystem::current_path()); - } - } + namespace priv{ + void initfileutils(){ + defaultWorkingDirectory() = of::filesystem::absolute(of::filesystem::current_path()); + } + } } @@ -450,13 +452,13 @@ istream & operator>>(istream & istr, ofBuffer & buf){ } //-------------------------------------------------- -ofBuffer ofBufferFromFile(const std::filesystem::path & path, bool binary){ +ofBuffer ofBufferFromFile(const of::filesystem::path & path, bool binary){ ofFile f(path,ofFile::ReadOnly, binary); return ofBuffer(f); } //-------------------------------------------------- -bool ofBufferToFile(const std::filesystem::path & path, const ofBuffer& buffer, bool binary){ +bool ofBufferToFile(const of::filesystem::path & path, const ofBuffer& buffer, bool binary){ ofFile f(path, ofFile::WriteOnly, binary); return buffer.writeTo(f); } @@ -473,7 +475,7 @@ ofFile::ofFile() ,binary(true){ } -ofFile::ofFile(const std::filesystem::path & path, Mode mode, bool binary) +ofFile::ofFile(const of::filesystem::path & path, Mode mode, bool binary) :mode(mode) ,binary(true){ open(path, mode, binary); @@ -555,25 +557,25 @@ bool ofFile::openStream(Mode _mode, bool _binary){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::open(const std::filesystem::path & _path, Mode _mode, bool binary){ +bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); - myFile = std::filesystem::path(ofToDataPath(_path.string())); + myFile = ofToDataPath(_path); return openStream(_mode, binary); } //------------------------------------------------------------------------------------------------------------ -bool ofFile::openFromCWD(const std::filesystem::path & _path, Mode _mode, bool binary){ +bool ofFile::openFromCWD(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); - myFile = std::filesystem::path(_path.string()); + myFile = _path; return openStream(_mode, binary); } //------------------------------------------------------------------------------------------------------------- bool ofFile::changeMode(Mode _mode, bool binary){ if(_mode != mode){ - string _path = path(); + auto _path = path(); close(); - myFile = std::filesystem::path(_path); + myFile = _path; return openStream(_mode, binary); } else{ @@ -588,7 +590,7 @@ bool ofFile::isWriteMode(){ //------------------------------------------------------------------------------------------------------------- void ofFile::close(){ - myFile = std::filesystem::path(); + myFile = of::filesystem::path(); if(mode!=Reference) fstream::close(); } @@ -598,23 +600,24 @@ bool ofFile::create(){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::create(const std::filesystem::path & path){ +bool ofFile::create(const of::filesystem::path & path){ bool success = false; auto oldmode = this->mode; auto oldpath = this->path(); success = open(path,ofFile::WriteOnly,binary); close(); - if( oldpath.length() ){ + + if( !oldpath.empty() ){ open(oldpath,oldmode,binary); } - + return success; } //------------------------------------------------------------------------------------------------------------ ofBuffer ofFile::readToBuffer(){ - if(myFile.string().empty() || !std::filesystem::exists(myFile)){ + if(myFile.string().empty() || !of::filesystem::exists(myFile)){ return ofBuffer(); } @@ -642,18 +645,21 @@ bool ofFile::exists() const { if(path().empty()){ return false; } - - return std::filesystem::exists(myFile); + return of::filesystem::exists(myFile); } //------------------------------------------------------------------------------------------------------------ -string ofFile::path() const { +// MARK: - near future +//of::filesystem::path ofFile::path() const { +//return myFile; +std::string ofFile::path() const { return myFile.string(); } //------------------------------------------------------------------------------------------------------------ string ofFile::getExtension() const { auto dotext = myFile.extension().string(); + // FIXME: probably not needed; if(!dotext.empty() && dotext.front()=='.'){ return std::string(dotext.begin()+1,dotext.end()); }else{ @@ -672,18 +678,22 @@ string ofFile::getBaseName() const { } //------------------------------------------------------------------------------------------------------------ -string ofFile::getEnclosingDirectory() const { +// MARK: - near future +//of::filesystem::path ofFile::getEnclosingDirectory() const { +std::string ofFile::getEnclosingDirectory() const { return ofFilePath::getEnclosingDirectory(path()); } //------------------------------------------------------------------------------------------------------------ -string ofFile::getAbsolutePath() const { +// MARK: - near future +//of::filesystem::path ofFile::getAbsolutePath() const { +std::string ofFile::getAbsolutePath() const { return ofFilePath::getAbsolutePath(path()); } //------------------------------------------------------------------------------------------------------------ bool ofFile::canRead() const { - auto perm = std::filesystem::status(myFile).permissions(); + auto perm = of::filesystem::status(myFile).permissions(); #ifdef TARGET_WIN32 DWORD attr = GetFileAttributes(myFile.native().c_str()); if (attr == INVALID_FILE_ATTRIBUTES) @@ -696,19 +706,19 @@ bool ofFile::canRead() const { stat(path().c_str(), &info); // Error check omitted #if OF_USING_STD_FS if(geteuid() == info.st_uid){ - return (perm & std::filesystem::perms::owner_read) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::owner_read) != of::filesystem::perms::none; }else if (getegid() == info.st_gid){ - return (perm & std::filesystem::perms::group_read) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::group_read) != of::filesystem::perms::none; }else{ - return (perm & std::filesystem::perms::others_read) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::others_read) != of::filesystem::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & std::filesystem::owner_read; + return perm & of::filesystem::perms::owner_read; }else if (getegid() == info.st_gid){ - return perm & std::filesystem::group_read; + return perm & of::filesystem::perms::group_read; }else{ - return perm & std::filesystem::others_read; + return perm & of::filesystem::perms::others_read; } #endif #endif @@ -716,7 +726,7 @@ bool ofFile::canRead() const { //------------------------------------------------------------------------------------------------------------ bool ofFile::canWrite() const { - auto perm = std::filesystem::status(myFile).permissions(); + auto perm = of::filesystem::status(myFile).permissions(); #ifdef TARGET_WIN32 DWORD attr = GetFileAttributes(myFile.native().c_str()); if (attr == INVALID_FILE_ATTRIBUTES){ @@ -729,19 +739,19 @@ bool ofFile::canWrite() const { stat(path().c_str(), &info); // Error check omitted #if OF_USING_STD_FS if(geteuid() == info.st_uid){ - return (perm & std::filesystem::perms::owner_write) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::owner_write) != of::filesystem::perms::none; }else if (getegid() == info.st_gid){ - return (perm & std::filesystem::perms::group_write) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::group_write) != of::filesystem::perms::none; }else{ - return (perm & std::filesystem::perms::others_write) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::others_write) != of::filesystem::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & std::filesystem::owner_write; + return perm & of::filesystem::owner_write; }else if (getegid() == info.st_gid){ - return perm & std::filesystem::group_write; + return perm & of::filesystem::group_write; }else{ - return perm & std::filesystem::others_write; + return perm & of::filesystem::others_write; } #endif #endif @@ -749,7 +759,7 @@ bool ofFile::canWrite() const { //------------------------------------------------------------------------------------------------------------ bool ofFile::canExecute() const { - auto perm = std::filesystem::status(myFile).permissions(); + auto perm = of::filesystem::status(myFile).permissions(); #ifdef TARGET_WIN32 return getExtension() == "exe"; #else @@ -757,37 +767,36 @@ bool ofFile::canExecute() const { stat(path().c_str(), &info); // Error check omitted #if OF_USING_STD_FS if(geteuid() == info.st_uid){ - return (perm & std::filesystem::perms::owner_exec) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::owner_exec) != of::filesystem::perms::none; }else if (getegid() == info.st_gid){ - return (perm & std::filesystem::perms::group_exec) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::group_exec) != of::filesystem::perms::none; }else{ - return (perm & std::filesystem::perms::others_exec) != std::filesystem::perms::none; + return (perm & of::filesystem::perms::others_exec) != of::filesystem::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & std::filesystem::owner_exe; + return perm & of::filesystem::owner_exe; }else if (getegid() == info.st_gid){ - return perm & std::filesystem::group_exe; + return perm & of::filesystem::group_exe; }else{ - return perm & std::filesystem::others_exe; + return perm & of::filesystem::others_exe; } #endif #endif } - //------------------------------------------------------------------------------------------------------------ bool ofFile::isFile() const { - return std::filesystem::is_regular_file(myFile); + return of::filesystem::is_regular_file(myFile); } //------------------------------------------------------------------------------------------------------------ bool ofFile::isLink() const { - return std::filesystem::is_symlink(myFile); + return of::filesystem::is_symlink(myFile); } //------------------------------------------------------------------------------------------------------------ bool ofFile::isDirectory() const { - return std::filesystem::is_directory(myFile); + return of::filesystem::is_directory(myFile); } //------------------------------------------------------------------------------------------------------------ @@ -796,9 +805,9 @@ bool ofFile::isDevice() const { return false; #else #if OF_USING_STD_FS - return std::filesystem::is_block_file(std::filesystem::status(myFile)); + return of::filesystem::is_block_file(of::filesystem::status(myFile)); #else - return std::filesystem::status(myFile).type() == std::filesystem::block_file; + return of::filesystem::status(myFile).type() == of::filesystem::block_file; #endif #endif } @@ -816,21 +825,21 @@ bool ofFile::isHidden() const { void ofFile::setWriteable(bool flag){ try{ #if !OF_USING_STD_FS || (OF_USING_STD_FS && OF_USE_EXPERIMENTAL_FS) - if(flag){ - std::filesystem::permissions(myFile,std::filesystem::perms::owner_write | std::filesystem::perms::add_perms); - }else{ - std::filesystem::permissions(myFile,std::filesystem::perms::owner_write | std::filesystem::perms::remove_perms); - } + if(flag){ + of::filesystem::permissions(myFile,of::filesystem::perms::owner_write | of::filesystem::perms::add_perms); + }else{ + of::filesystem::permissions(myFile,of::filesystem::perms::owner_write | of::filesystem::perms::remove_perms); + } #else - if(flag){ - std::filesystem::permissions(myFile, - std::filesystem::perms::owner_write, - std::filesystem::perm_options::add); - }else{ - std::filesystem::permissions(myFile, - std::filesystem::perms::owner_write, - std::filesystem::perm_options::remove); - } + if(flag){ + of::filesystem::permissions(myFile, + of::filesystem::perms::owner_write, + of::filesystem::perm_options::add); + }else{ + of::filesystem::permissions(myFile, + of::filesystem::perms::owner_write, + of::filesystem::perm_options::remove); + } #endif }catch(std::exception & e){ ofLogError() << "Couldn't set write permission on " << myFile << ": " << e.what(); @@ -847,21 +856,21 @@ void ofFile::setReadOnly(bool flag){ void ofFile::setReadable(bool flag){ try{ #if !OF_USING_STD_FS || (OF_USING_STD_FS && OF_USE_EXPERIMENTAL_FS) - if(flag){ - std::filesystem::permissions(myFile,std::filesystem::perms::owner_read | std::filesystem::perms::add_perms); - }else{ - std::filesystem::permissions(myFile,std::filesystem::perms::owner_read | std::filesystem::perms::remove_perms); - } + if(flag){ + of::filesystem::permissions(myFile,of::filesystem::perms::owner_read | of::filesystem::perms::add_perms); + }else{ + of::filesystem::permissions(myFile,of::filesystem::perms::owner_read | of::filesystem::perms::remove_perms); + } #else - if(flag){ - std::filesystem::permissions(myFile, - std::filesystem::perms::owner_read, - std::filesystem::perm_options::add); - }else{ - std::filesystem::permissions(myFile, - std::filesystem::perms::owner_read, - std::filesystem::perm_options::remove); - } + if(flag){ + of::filesystem::permissions(myFile, + of::filesystem::perms::owner_read, + of::filesystem::perm_options::add); + }else{ + of::filesystem::permissions(myFile, + of::filesystem::perms::owner_read, + of::filesystem::perm_options::remove); + } #endif }catch(std::exception & e){ ofLogError() << "Couldn't set read permission on " << myFile << ": " << e.what(); @@ -873,27 +882,27 @@ void ofFile::setExecutable(bool flag){ try{ #if OF_USING_STD_FS # if OF_USE_EXPERIMENTAL_FS - if(flag){ - std::filesystem::permissions(myFile, std::filesystem::perms::owner_exec | std::filesystem::perms::add_perms); - } else{ - std::filesystem::permissions(myFile, std::filesystem::perms::owner_exec | std::filesystem::perms::remove_perms); - } + if(flag){ + of::filesystem::permissions(myFile, of::filesystem::perms::owner_exec | of::filesystem::perms::add_perms); + } else{ + of::filesystem::permissions(myFile, of::filesystem::perms::owner_exec | of::filesystem::perms::remove_perms); + } # else - if(flag){ - std::filesystem::permissions(myFile, - std::filesystem::perms::owner_exec, - std::filesystem::perm_options::add); - } else{ - std::filesystem::permissions(myFile, - std::filesystem::perms::owner_exec, - std::filesystem::perm_options::remove); - } + if(flag){ + of::filesystem::permissions(myFile, + of::filesystem::perms::owner_exec, + of::filesystem::perm_options::add); + } else{ + of::filesystem::permissions(myFile, + of::filesystem::perms::owner_exec, + of::filesystem::perm_options::remove); + } # endif #else if(flag){ - std::filesystem::permissions(myFile, std::filesystem::perms::owner_exe | std::filesystem::perms::add_perms); + of::filesystem::permissions(myFile, of::filesystem::perms::owner_exe | of::filesystem::perms::add_perms); } else{ - std::filesystem::permissions(myFile, std::filesystem::perms::owner_exe | std::filesystem::perms::remove_perms); + of::filesystem::permissions(myFile, of::filesystem::perms::owner_exe | of::filesystem::perms::remove_perms); } #endif }catch(std::exception & e){ @@ -902,7 +911,7 @@ void ofFile::setExecutable(bool flag){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::copyTo(const std::filesystem::path& _path, bool bRelativeToData, bool overwrite) const{ +bool ofFile::copyTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite) const{ auto path = _path; if(path.empty()){ @@ -924,13 +933,13 @@ bool ofFile::copyTo(const std::filesystem::path& _path, bool bRelativeToData, bo if(bRelativeToData){ path = ofToDataPath(path); } - + if(ofFile::doesFileExist(path, false)){ if(isFile()){ ofFile tmp; tmp.openFromCWD(path,ofFile::Reference); if(tmp.isDirectory()){ - path = ofFilePath::join(path,getFileName()); + path = path / getFileName(); } } if(ofFile::doesFileExist(path, false)){ @@ -944,11 +953,12 @@ bool ofFile::copyTo(const std::filesystem::path& _path, bool bRelativeToData, bo try{ ofDirectory destDir; - destDir.openFromCWD(ofFilePath::getEnclosingDirectory(path,false)); + auto p = ofFilePath::getEnclosingDirectory(path,false); + destDir.openFromCWD(p); if(!destDir.exists()){ ofFilePath::createEnclosingDirectory(path, false); } - std::filesystem::copy_file(myFile,path); + of::filesystem::copy_file(myFile,path); }catch(std::exception & except){ ofLogError("ofFile") << "copyTo(): unable to copy \"" << path << "\": " << except.what(); return false; @@ -958,7 +968,7 @@ bool ofFile::copyTo(const std::filesystem::path& _path, bool bRelativeToData, bo } //------------------------------------------------------------------------------------------------------------ -bool ofFile::moveTo(const std::filesystem::path& _path, bool bRelativeToData, bool overwrite){ +bool ofFile::moveTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite){ auto path = _path; if(path.empty()){ @@ -974,12 +984,12 @@ bool ofFile::moveTo(const std::filesystem::path& _path, bool bRelativeToData, bo path = ofToDataPath(path); } if(ofFile::doesFileExist(path, false)){ - + if(isFile()){ ofFile tmp; tmp.openFromCWD(path,ofFile::Reference); if(tmp.isDirectory()){ - path = ofFilePath::join(path,getFileName()); + path = path / getFileName(); } } if(ofFile::doesFileExist(path, false)){ @@ -1001,7 +1011,7 @@ bool ofFile::moveTo(const std::filesystem::path& _path, bool bRelativeToData, bo if(!destDir.exists()){ ofFilePath::createEnclosingDirectory(path,false); } - std::filesystem::rename(myFile,path); + of::filesystem::rename(myFile,path); myFile = path; if(mode != ofFile::Reference){ changeMode(mode, binary); @@ -1016,7 +1026,7 @@ bool ofFile::moveTo(const std::filesystem::path& _path, bool bRelativeToData, bo } //------------------------------------------------------------------------------------------------------------ -bool ofFile::renameTo(const std::filesystem::path& path, bool bRelativeToData, bool overwrite){ +bool ofFile::renameTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ return moveTo(path,bRelativeToData,overwrite); } @@ -1036,9 +1046,9 @@ bool ofFile::remove(bool recursive){ open(path(),Reference,binary); } if(recursive){ - std::filesystem::remove_all(myFile); + of::filesystem::remove_all(myFile); }else{ - std::filesystem::remove(myFile); + of::filesystem::remove(myFile); } }catch(std::exception & except){ ofLogError("ofFile") << "remove(): unable to remove \"" << myFile << "\": " << except.what(); @@ -1051,7 +1061,7 @@ bool ofFile::remove(bool recursive){ //------------------------------------------------------------------------------------------------------------ uint64_t ofFile::getSize() const { try{ - return std::filesystem::file_size(myFile); + return of::filesystem::file_size(myFile); }catch(std::exception & except){ ofLogError("ofFile") << "getSize(): unable to get size of \"" << myFile << "\": " << except.what(); return 0; @@ -1092,7 +1102,7 @@ bool ofFile::operator>=(const ofFile & file) const { // ofFile Static Methods //------------------------------------------------------------------------------------------------------------ -bool ofFile::copyFromTo(const std::filesystem::path& pathSrc, const std::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ +bool ofFile::copyFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ ofFile tmp; if( bRelativeToData ){ tmp.open(pathSrc,ofFile::Reference); @@ -1104,7 +1114,7 @@ bool ofFile::copyFromTo(const std::filesystem::path& pathSrc, const std::filesys //be careful with slashes here - appending a slash when moving a folder will causes mad headaches //------------------------------------------------------------------------------------------------------------ -bool ofFile::moveFromTo(const std::filesystem::path& pathSrc, const std::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ +bool ofFile::moveFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ ofFile tmp; if( bRelativeToData ){ tmp.open(pathSrc,ofFile::Reference); @@ -1115,7 +1125,7 @@ bool ofFile::moveFromTo(const std::filesystem::path& pathSrc, const std::filesys } //------------------------------------------------------------------------------------------------------------ -bool ofFile::doesFileExist(const std::filesystem::path& _fPath, bool bRelativeToData){ +bool ofFile::doesFileExist(const of::filesystem::path& _fPath, bool bRelativeToData){ ofFile tmp; if(bRelativeToData){ tmp.open(_fPath,ofFile::Reference); @@ -1126,7 +1136,7 @@ bool ofFile::doesFileExist(const std::filesystem::path& _fPath, bool bRelativeTo } //------------------------------------------------------------------------------------------------------------ -bool ofFile::removeFile(const std::filesystem::path& _path, bool bRelativeToData){ +bool ofFile::removeFile(const of::filesystem::path& _path, bool bRelativeToData){ ofFile tmp; if(bRelativeToData){ tmp.open(_path,ofFile::Reference); @@ -1149,28 +1159,28 @@ ofDirectory::ofDirectory(){ } //------------------------------------------------------------------------------------------------------------ -ofDirectory::ofDirectory(const std::filesystem::path & path){ +ofDirectory::ofDirectory(const of::filesystem::path & path){ showHidden = false; open(path); } //------------------------------------------------------------------------------------------------------------ -void ofDirectory::open(const std::filesystem::path & path){ +void ofDirectory::open(const of::filesystem::path & path){ originalDirectory = ofFilePath::getPathForDirectory(path.string()); files.clear(); - myDir = std::filesystem::path(ofToDataPath(originalDirectory)); + myDir = of::filesystem::path(ofToDataPath(originalDirectory)); } //------------------------------------------------------------------------------------------------------------ -void ofDirectory::openFromCWD(const std::filesystem::path & path){ +void ofDirectory::openFromCWD(const of::filesystem::path & path){ originalDirectory = ofFilePath::getPathForDirectory(path.string()); files.clear(); - myDir = std::filesystem::path(originalDirectory); + myDir = of::filesystem::path(originalDirectory); } //------------------------------------------------------------------------------------------------------------ void ofDirectory::close(){ - myDir = std::filesystem::path(); + myDir = of::filesystem::path(); } //------------------------------------------------------------------------------------------------------------ @@ -1179,9 +1189,9 @@ bool ofDirectory::create(bool recursive){ if(!myDir.string().empty()){ try{ if(recursive){ - std::filesystem::create_directories(myDir); + of::filesystem::create_directories(myDir); }else{ - std::filesystem::create_directory(myDir); + of::filesystem::create_directory(myDir); } } catch(std::exception & except){ @@ -1195,20 +1205,31 @@ bool ofDirectory::create(bool recursive){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::exists() const { - return (myDir == "" || std::filesystem::exists(myDir)); + return (myDir == "" || of::filesystem::exists(myDir)); } //------------------------------------------------------------------------------------------------------------ -string ofDirectory::path() const { +// MARK: - near future +//of::filesystem::path ofDirectory::path() const { +// return myDir; +std::string ofDirectory::path() const { return myDir.string(); } //------------------------------------------------------------------------------------------------------------ -string ofDirectory::getAbsolutePath() const { +// MARK: - near future +//of::filesystem::path ofDirectory::getAbsolutePath() const { +// try{ +// return of::filesystem::canonical(of::filesystem::absolute(myDir)); +// }catch(...){ +// return of::filesystem::absolute(myDir); +// } +//} +std::string ofDirectory::getAbsolutePath() const { try{ - return std::filesystem::canonical(std::filesystem::absolute(myDir)).string(); + return of::filesystem::canonical(of::filesystem::absolute(myDir)).string(); }catch(...){ - return std::filesystem::absolute(myDir).string(); + return of::filesystem::absolute(myDir).string(); } } @@ -1260,22 +1281,22 @@ void ofDirectory::setShowHidden(bool showHidden){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::isDirectory() const { - return std::filesystem::is_directory(myDir); + return of::filesystem::is_directory(myDir); } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::copyTo(const std::filesystem::path& _path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite){ auto path = _path; if(myDir.string().empty()){ ofLogError("ofDirectory") << "copyTo(): source path is empty"; return false; } - if(!std::filesystem::exists(myDir)){ + if(!of::filesystem::exists(myDir)){ ofLogError("ofDirectory") << "copyTo(): source directory does not exist"; return false; } - if(!std::filesystem::is_directory(myDir)){ + if(!of::filesystem::is_directory(myDir)){ ofLogError("ofDirectory") << "copyTo(): source path is not a directory"; return false; } @@ -1293,19 +1314,19 @@ bool ofDirectory::copyTo(const std::filesystem::path& _path, bool bRelativeToDat } } - //our path is bRelativeToData handled from above - so can't open via the constructor approach + //our path is bRelativeToData handled from above - so can't open via the constructor approach ofDirectory dir; dir.openFromCWD(path); dir.create(true); - + // Iterate through the source directory - for(std::filesystem::directory_iterator file(myDir); file != std::filesystem::directory_iterator(); ++file){ - auto currentPath = std::filesystem::absolute(file->path()); - auto dst = std::filesystem::path(path) / currentPath.filename(); - if(std::filesystem::is_directory(currentPath)){ + for(of::filesystem::directory_iterator file(myDir); file != of::filesystem::directory_iterator(); ++file){ + auto currentPath = of::filesystem::absolute(file->path()); + auto dst = of::filesystem::path(path) / currentPath.filename(); + if(of::filesystem::is_directory(currentPath)){ ofDirectory current(currentPath); // Found directory: Recursion - if(!current.copyTo(dst.string(),false,overwrite)){ + if(!current.copyTo(dst,false,overwrite)){ return false; } }else{ @@ -1319,30 +1340,30 @@ bool ofDirectory::copyTo(const std::filesystem::path& _path, bool bRelativeToDat } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::moveTo(const std::filesystem::path& path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ if(copyTo(path,bRelativeToData,overwrite)){ return remove(true); } - + return false; } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::renameTo(const std::filesystem::path& path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::renameTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ return moveTo(path, bRelativeToData, overwrite); } //------------------------------------------------------------------------------------------------------------ bool ofDirectory::remove(bool recursive){ - if(path().empty() || !std::filesystem::exists(myDir)){ + if(path().empty() || !of::filesystem::exists(myDir)){ return false; } try{ if(recursive){ - std::filesystem::remove_all(std::filesystem::canonical(myDir)); + of::filesystem::remove_all(of::filesystem::canonical(myDir)); }else{ - std::filesystem::remove(std::filesystem::canonical(myDir)); + of::filesystem::remove(of::filesystem::canonical(myDir)); } }catch(std::exception & except){ ofLogError("ofDirectory") << "remove(): unable to remove file/directory: " << except.what(); @@ -1373,14 +1394,14 @@ std::size_t ofDirectory::listDir(){ ofLogError("ofDirectory") << "listDir(): directory path is empty"; return 0; } - if(!std::filesystem::exists(myDir)){ + if(!of::filesystem::exists(myDir)){ ofLogError("ofDirectory") << "listDir:() source directory does not exist: \"" << myDir << "\""; return 0; } - - std::filesystem::directory_iterator end_iter; - if ( std::filesystem::exists(myDir) && std::filesystem::is_directory(myDir)){ - for( std::filesystem::directory_iterator dir_iter(myDir) ; dir_iter != end_iter ; ++dir_iter){ + + of::filesystem::directory_iterator end_iter; + if ( of::filesystem::exists(myDir) && of::filesystem::is_directory(myDir)){ + for( of::filesystem::directory_iterator dir_iter(myDir) ; dir_iter != end_iter ; ++dir_iter){ files.emplace_back(dir_iter->path().string(), ofFile::Reference); } }else{ @@ -1399,7 +1420,7 @@ std::size_t ofDirectory::listDir(){ ofRemove(files, [&](ofFile & file){ return std::find(extensions.begin(), extensions.end(), ofToLower(file.getExtension())) == extensions.end(); }); - } + } if(ofGetLogLevel() == OF_LOG_VERBOSE){ for(int i = 0; i < (int)size(); i++){ @@ -1468,8 +1489,8 @@ static bool natural(const ofFile& a, const ofFile& b) { //------------------------------------------------------------------------------------------------------------ static bool byDate(const ofFile& a, const ofFile& b) { - auto ta = std::filesystem::last_write_time(a); - auto tb = std::filesystem::last_write_time(b); + auto ta = of::filesystem::last_write_time(a); + auto tb = of::filesystem::last_write_time(b); return ta < tb; } @@ -1512,7 +1533,7 @@ int ofDirectory::numFiles(){ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::removeDirectory(const std::filesystem::path& _path, bool deleteIfNotEmpty, bool bRelativeToData){ +bool ofDirectory::removeDirectory(const of::filesystem::path& _path, bool deleteIfNotEmpty, bool bRelativeToData){ auto path = _path; ofFile dirToRemove; @@ -1521,32 +1542,32 @@ bool ofDirectory::removeDirectory(const std::filesystem::path& _path, bool delet }else{ dirToRemove.openFromCWD(path,ofFile::Reference); } - + return dirToRemove.remove(deleteIfNotEmpty); } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::createDirectory(const std::filesystem::path& _dirPath, bool bRelativeToData, bool recursive){ +bool ofDirectory::createDirectory(const of::filesystem::path& _dirPath, bool bRelativeToData, bool recursive){ auto dirPath = _dirPath; if(bRelativeToData){ dirPath = ofToDataPath(dirPath); } - - // on OSX,std::filesystem::create_directories seems to return false *if* the path has folders that already exist + + // on OSX,of::filesystem::create_directories seems to return false *if* the path has folders that already exist // and true if it doesn't // so to avoid unnecessary warnings on OSX, we check if it exists here: - + bool bDoesExistAlready = ofDirectory::doesDirectoryExist(dirPath,false); - + if (!bDoesExistAlready){ - + bool success = false; try{ if(!recursive){ - success = std::filesystem::create_directory(dirPath); + success = of::filesystem::create_directory(dirPath); }else{ - success = std::filesystem::create_directories(dirPath); + success = of::filesystem::create_directories(dirPath); } } catch(std::exception & except){ ofLogError("ofDirectory") << "createDirectory(): couldn't create directory \"" << dirPath << "\": " << except.what(); @@ -1554,19 +1575,19 @@ bool ofDirectory::createDirectory(const std::filesystem::path& _dirPath, bool bR } return success; } - + // no need to create it - it already exists. return true; } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::doesDirectoryExist(const std::filesystem::path& _dirPath, bool bRelativeToData){ +bool ofDirectory::doesDirectoryExist(const of::filesystem::path& _dirPath, bool bRelativeToData){ auto dirPath = _dirPath; try { if (bRelativeToData) { dirPath = ofToDataPath(dirPath); } - return std::filesystem::exists(dirPath) && std::filesystem::is_directory(dirPath); + return of::filesystem::exists(dirPath) && of::filesystem::is_directory(dirPath); } catch (std::exception & except) { ofLogError("ofDirectory") << "doesDirectoryExist(): couldn't find directory \"" << dirPath << "\": " << except.what() << std::endl; @@ -1575,14 +1596,14 @@ bool ofDirectory::doesDirectoryExist(const std::filesystem::path& _dirPath, bool } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::isDirectoryEmpty(const std::filesystem::path& _dirPath, bool bRelativeToData){ +bool ofDirectory::isDirectoryEmpty(const of::filesystem::path& _dirPath, bool bRelativeToData){ auto dirPath = _dirPath; if(bRelativeToData){ dirPath = ofToDataPath(dirPath); } - if(!dirPath.empty() && std::filesystem::exists(dirPath) && std::filesystem::is_directory(dirPath)){ - return std::filesystem::directory_iterator(dirPath) == std::filesystem::directory_iterator(); + if(!dirPath.empty() && of::filesystem::exists(dirPath) && of::filesystem::is_directory(dirPath)){ + return of::filesystem::directory_iterator(dirPath) == of::filesystem::directory_iterator(); } return false; } @@ -1646,9 +1667,9 @@ vector::const_reverse_iterator ofDirectory::rend() const{ //------------------------------------------------------------------------------------------------------------ -string ofFilePath::addLeadingSlash(const std::filesystem::path& _path){ - auto path = _path.string(); - auto sep = std::filesystem::path("/").make_preferred(); +string ofFilePath::addLeadingSlash(const of::filesystem::path& _path){ + auto path = _path.string(); + auto sep = of::filesystem::path("/").make_preferred(); if(!path.empty()){ if(ofToString(path[0]) != sep.string()){ path = (sep / path).string(); @@ -1658,55 +1679,69 @@ string ofFilePath::addLeadingSlash(const std::filesystem::path& _path){ } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::addTrailingSlash(const std::filesystem::path& _path){ +// MARK: - near future +//of::filesystem::path ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ +std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ #if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS - if(_path.string().empty()) return ""; - return (std::filesystem::path(_path).make_preferred() / "").string(); + if(_path.string().empty()) return ""; + // FIXME: Remove .string() here and following + // return (of::filesystem::path(_path).make_preferred() / ""); + return (of::filesystem::path(_path).make_preferred() / "").string(); #else - auto path = std::filesystem::path(_path).make_preferred().string(); - auto sep = std::filesystem::path("/").make_preferred(); + auto path = of::filesystem::path(_path).make_preferred(); + auto sep = of::filesystem::path("/").make_preferred(); if(!path.empty()){ - if(ofToString(path.back()) != sep.string()){ - path = (path / sep).string(); + if(ofToString(path.string().back()) != sep.string()){ + path = (path / sep); } } - return path; +// return path; + return path.string(); #endif } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getFileExt(const std::filesystem::path& filename){ +string ofFilePath::getFileExt(const of::filesystem::path& filename){ return ofFile(filename,ofFile::Reference).getExtension(); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::removeExt(const std::filesystem::path& filename){ - return ofFilePath::join(getEnclosingDirectory(filename,false), ofFile(filename,ofFile::Reference).getBaseName()); +// FIXME: remove const and copy +// MARK: - near future +// of::filesystem::path ofFilePath::removeExt(const of::filesystem::path& _filename){ +std::string ofFilePath::removeExt(const of::filesystem::path& _filename){ + auto filename = _filename; +// return filename.replace_extension(); + return filename.replace_extension().string(); } - //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getPathForDirectory(const std::filesystem::path& path){ +string ofFilePath::getPathForDirectory(const of::filesystem::path& path){ // if a trailing slash is missing from a path, this will clean it up // if it's a windows-style "\" path it will add a "\" // if it's a unix-style "/" path it will add a "/" + + // FIXME: Remove .string() here and following + // FIXME: this seems over complicated and not useful anymore, using filesystem + #if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS - if(path.string().empty()) return ""; - return (path / "").string(); + if(path.string().empty()) return ""; + return (path / "").string(); #else - auto sep = std::filesystem::path("/").make_preferred(); - if(!path.empty() && ofToString(path.string().back())!=sep.string()){ - return (path / sep).string(); - }else{ - return path.string(); - } + auto sep = of::filesystem::path("/").make_preferred(); + if(!path.empty() && ofToString(path.string().back())!=sep.string()){ + return (path / sep).string(); + }else{ + return path.string(); + } #endif } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::removeTrailingSlash(const std::filesystem::path& _path){ - auto path = _path.string(); +// FIXME: convert to of::filesystem::path +string ofFilePath::removeTrailingSlash(const of::filesystem::path& _path){ + auto path = _path.string(); if(path.length() > 0 && (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')){ path = path.substr(0, path.length() - 1); } @@ -1715,62 +1750,76 @@ string ofFilePath::removeTrailingSlash(const std::filesystem::path& _path){ //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getFileName(const std::filesystem::path& _filePath, bool bRelativeToData){ - std::string filePath = _filePath.string(); +// FIXME: is this still useful? if yes convert to of::filesystem::path +string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRelativeToData){ + auto filePath = _filePath; if(bRelativeToData){ - filePath = ofToDataPath(_filePath); + filePath = ofToDataPath(filePath); } - return std::filesystem::path(filePath).filename().string(); + // FIXME: this is probably over complicated + return of::filesystem::path(filePath).filename().string(); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getBaseName(const std::filesystem::path& filePath){ +string ofFilePath::getBaseName(const of::filesystem::path& filePath){ + // FIXME: is this still useful? return ofFile(filePath,ofFile::Reference).getBaseName(); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getEnclosingDirectory(const std::filesystem::path& _filePath, bool bRelativeToData){ - std::string filePath = _filePath.string(); +// MARK: - near future +//of::filesystem::path ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ +std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ + auto fp = _filePath; if(bRelativeToData){ - filePath = ofToDataPath(filePath); + fp = ofToDataPath(fp); } - return addTrailingSlash(std::filesystem::path(filePath).parent_path().string()); + return addTrailingSlash(fp.parent_path()); } //------------------------------------------------------------------------------------------------------------ -bool ofFilePath::createEnclosingDirectory(const std::filesystem::path& filePath, bool bRelativeToData, bool bRecursive) { +bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData, bool bRecursive) { return ofDirectory::createDirectory(ofFilePath::getEnclosingDirectory(filePath,bRelativeToData), bRelativeToData, bRecursive); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getAbsolutePath(const std::filesystem::path& path, bool bRelativeToData){ +// FIXME: - near future +//of::filesystem::path ofFilePath::getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData){ +std::string ofFilePath::getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData){ if(bRelativeToData){ return ofToDataPath(path, true); }else{ try{ - return std::filesystem::canonical(std::filesystem::absolute(path)).string(); +// return of::filesystem::canonical(of::filesystem::absolute(path)); + return of::filesystem::canonical(of::filesystem::absolute(path)).string(); }catch(...){ - return std::filesystem::absolute(path).string(); +// return of::filesystem::absolute(path); + return of::filesystem::absolute(path).string(); } } } - //------------------------------------------------------------------------------------------------------------ -bool ofFilePath::isAbsolute(const std::filesystem::path& path){ - return std::filesystem::path(path).is_absolute(); +bool ofFilePath::isAbsolute(const of::filesystem::path& path){ + return of::filesystem::path(path).is_absolute(); } //------------------------------------------------------------------------------------------------------------ string ofFilePath::getCurrentWorkingDirectory(){ - return std::filesystem::current_path().string(); + return of::filesystem::current_path().string(); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::join(const std::filesystem::path& path1, const std::filesystem::path& path2){ - return (std::filesystem::path(path1) / std::filesystem::path(path2)).string(); +// MARK: - near future +//of::filesystem::path ofFilePath::join(const of::filesystem::path& path1, const of::filesystem::path& path2){ +// // FIXME: deprecate when possible. helper function more complex than actual solution +// return (path1 / path2); +//} +std::string ofFilePath::join(const of::filesystem::path& path1, const of::filesystem::path& path2){ + // FIXME: deprecate when possible. helper function more complex than actual solution + return (path1 / path2).string(); } //------------------------------------------------------------------------------------------------------------ @@ -1805,8 +1854,10 @@ string ofFilePath::getCurrentExePath(){ } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getCurrentExeDir(){ - return getEnclosingDirectory(getCurrentExePath(), false); +// MARK: - near future +//of::filesystem::path ofFilePath::getCurrentExeDir(){ +std::string ofFilePath::getCurrentExeDir(){ + return ofFilePath::getEnclosingDirectory(ofFilePath::getCurrentExePath(), false); } //------------------------------------------------------------------------------------------------------------ @@ -1824,15 +1875,17 @@ string ofFilePath::getUserHomeDir(){ #endif } -string ofFilePath::makeRelative(const std::filesystem::path & from, const std::filesystem::path & to){ - auto pathFrom = std::filesystem::absolute( from ); - auto pathTo = std::filesystem::absolute( to ); - std::filesystem::path ret; - std::filesystem::path::const_iterator itrFrom( pathFrom.begin() ), itrTo( pathTo.begin() ); +// MARK: - near future +//of::filesystem::path ofFilePath::makeRelative(const of::filesystem::path & from, const of::filesystem::path & to){ +std::string ofFilePath::makeRelative(const of::filesystem::path & from, const of::filesystem::path & to){ + auto pathFrom = of::filesystem::absolute( from ); + auto pathTo = of::filesystem::absolute( to ); + of::filesystem::path ret; + of::filesystem::path::const_iterator itrFrom( pathFrom.begin() ), itrTo( pathTo.begin() ); // Find common base - for( std::filesystem::path::const_iterator toEnd( pathTo.end() ), fromEnd( pathFrom.end() ) ; itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo ); + for( of::filesystem::path::const_iterator toEnd( pathTo.end() ), fromEnd( pathFrom.end() ) ; itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo ); // Navigate backwards in directory to reach previously found base - for( std::filesystem::path::const_iterator fromEnd( pathFrom.end() ); itrFrom != fromEnd; ++itrFrom ){ + for( of::filesystem::path::const_iterator fromEnd( pathFrom.end() ); itrFrom != fromEnd; ++itrFrom ){ if( (*itrFrom) != "." ){ ret /= ".."; } @@ -1844,116 +1897,127 @@ string ofFilePath::makeRelative(const std::filesystem::path & from, const std::f } } +// return ret; return ret.string(); } //-------------------------------------------------- void ofEnableDataPath(){ - enableDataPath = true; + enableDataPath = true; } //-------------------------------------------------- void ofDisableDataPath(){ - enableDataPath = false; + enableDataPath = false; } //-------------------------------------------------- bool ofRestoreWorkingDirectoryToDefault(){ - try{ - std::filesystem::current_path(defaultWorkingDirectory()); - return true; - }catch(...){ - return false; - } + try{ + of::filesystem::current_path(defaultWorkingDirectory()); + return true; + }catch(...){ + return false; + } } //-------------------------------------------------- -void ofSetDataPathRoot(const std::filesystem::path& newRoot){ - dataPathRoot() = newRoot; +void ofSetDataPathRoot(const of::filesystem::path& newRoot){ + dataPathRoot() = newRoot; } //-------------------------------------------------- -string ofToDataPath(const std::filesystem::path & path, bool makeAbsolute){ - if (makeAbsolute && path.is_absolute()) { - return path.string(); - } - - if (!enableDataPath) { - return path.string(); - } +// MARK: - near future +//of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ +std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ + if (makeAbsolute && path.is_absolute()) { +// return path; + return path.string(); + } - bool hasTrailingSlash = !path.empty() && path.generic_string().back()=='/'; + if (!enableDataPath) { +// return path; + return path.string(); + } - // if our Current Working Directory has changed (e.g. file open dialog) + bool hasTrailingSlash = !path.empty() && path.generic_string().back()=='/'; + + // if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 - if (defaultWorkingDirectory() != std::filesystem::current_path()) { - // change our cwd back to where it was on app load - bool ret = ofRestoreWorkingDirectoryToDefault(); - if(!ret){ - ofLogWarning("ofUtils") << "ofToDataPath: error while trying to change back to default working directory " << defaultWorkingDirectory(); - } - } + if (defaultWorkingDirectory() != of::filesystem::current_path()) { + // change our cwd back to where it was on app load + bool ret = ofRestoreWorkingDirectoryToDefault(); + if(!ret){ + ofLogWarning("ofUtils") << "ofToDataPath: error while trying to change back to default working directory " << defaultWorkingDirectory(); + } + } #endif - // this could be performed here, or wherever we might think we accidentally change the cwd, e.g. after file dialogs on windows - const auto & dataPath = dataPathRoot(); - std::filesystem::path inputPath(path); - std::filesystem::path outputPath; - - // if path is already absolute, just return it - if (inputPath.is_absolute()) { - try { - auto outpath = std::filesystem::canonical(inputPath).make_preferred(); - if(std::filesystem::is_directory(outpath) && hasTrailingSlash){ - return ofFilePath::addTrailingSlash(outpath.string()); - }else{ - return outpath.string(); - } - } - catch (...) { - return inputPath.string(); - } - } - - // here we check whether path already refers to the data folder by looking for common elements - // if the path begins with the full contents of dataPathRoot then the data path has already been added - // we compare inputPath.toString() rather that the input var path to ensure common formatting against dataPath.toString() - auto dirDataPath = dataPath.string(); - // also, we strip the trailing slash from dataPath since `path` may be input as a file formatted path even if it is a folder (i.e. missing trailing slash) - dirDataPath = ofFilePath::addTrailingSlash(dirDataPath); - - auto relativeDirDataPath = ofFilePath::makeRelative(std::filesystem::current_path().string(),dataPath.string()); - relativeDirDataPath = ofFilePath::addTrailingSlash(relativeDirDataPath); - - if (inputPath.string().find(dirDataPath) != 0 && inputPath.string().find(relativeDirDataPath)!=0) { - // inputPath doesn't contain data path already, so we build the output path as the inputPath relative to the dataPath - if(makeAbsolute){ - outputPath = dirDataPath / inputPath; - }else{ - outputPath = relativeDirDataPath / inputPath; - } - } else { - // inputPath already contains data path, so no need to change - outputPath = inputPath; - } - - // finally, if we do want an absolute path and we don't already have one - if(makeAbsolute){ - // then we return the absolute form of the path - try { - auto outpath = std::filesystem::canonical(std::filesystem::absolute(outputPath)).make_preferred(); - if(std::filesystem::is_directory(outpath) && hasTrailingSlash){ - return ofFilePath::addTrailingSlash(outpath.string()); - }else{ - return outpath.string(); - } - } - catch (std::exception &) { - return std::filesystem::absolute(outputPath).string(); - } - }else{ - // or output the relative path - return outputPath.string(); - } -} + // this could be performed here, or wherever we might think we accidentally change the cwd, e.g. after file dialogs on windows + const auto & dataPath = dataPathRoot(); + of::filesystem::path inputPath(path); + of::filesystem::path outputPath; + + // if path is already absolute, just return it + if (inputPath.is_absolute()) { + try { + auto outpath = of::filesystem::canonical(inputPath).make_preferred(); + if(of::filesystem::is_directory(outpath) && hasTrailingSlash){ + return ofFilePath::addTrailingSlash(outpath); + }else{ + return outpath.string(); + // return outpath; + } + } + catch (...) { + return inputPath.string(); + // return inputPath; + } + } + + // here we check whether path already refers to the data folder by looking for common elements + // if the path begins with the full contents of dataPathRoot then the data path has already been added + // we compare inputPath.toString() rather that the input var path to ensure common formatting against dataPath.toString() + auto dirDataPath = dataPath; + // also, we strip the trailing slash from dataPath since `path` may be input as a file formatted path even if it is a folder (i.e. missing trailing slash) + dirDataPath = ofFilePath::addTrailingSlash(dataPath); + + auto relativeDirDataPath = ofFilePath::makeRelative(of::filesystem::current_path(), dataPath); + relativeDirDataPath = ofFilePath::addTrailingSlash(relativeDirDataPath); + // FIXME: this can be simplified without using string conversion + // if (inputPath.string().find(dirDataPath.string()) != 0 && inputPath.string().find(relativeDirDataPath.string())!=0) { + if (inputPath.string().find(dirDataPath.string()) != 0 && inputPath.string().find(relativeDirDataPath)!=0) { + // inputPath doesn't contain data path already, so we build the output path as the inputPath relative to the dataPath + if(makeAbsolute){ + outputPath = dirDataPath / inputPath; + }else{ + outputPath = relativeDirDataPath / inputPath; + } + } else { + // inputPath already contains data path, so no need to change + outputPath = inputPath; + } + + // finally, if we do want an absolute path and we don't already have one + if(makeAbsolute){ + // then we return the absolute form of the path + try { + auto outpath = of::filesystem::canonical(of::filesystem::absolute(outputPath)).make_preferred(); + if(of::filesystem::is_directory(outpath) && hasTrailingSlash){ + return ofFilePath::addTrailingSlash(outpath); + }else{ +// return outpath; + return outpath.string(); + } + } + catch (std::exception &) { + return of::filesystem::absolute(outputPath).string(); + // return of::filesystem::absolute(outputPath); + } + }else{ + // or output the relative path +// return outputPath; + return outputPath.string(); + } +} diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 4868485712f..db9c09edd20 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -269,7 +269,7 @@ class ofBuffer{ /// \param path file to open /// \param binary set to false if you are reading a text file & want lines /// split at endline characters automatically -ofBuffer ofBufferFromFile(const std::filesystem::path & path, bool binary=true); +ofBuffer ofBufferFromFile(const of::filesystem::path & path, bool binary=true); //-------------------------------------------------- /// Write the contents of a buffer to a file at path. @@ -280,7 +280,7 @@ ofBuffer ofBufferFromFile(const std::filesystem::path & path, bool binary=true); /// \param buffer data source to write from /// \param binary set to false if you are writing a text file & want lines /// split at endline characters automatically -bool ofBufferToFile(const std::filesystem::path & path, const ofBuffer& buffer, bool binary=true); +bool ofBufferToFile(of::filesystem::path & path, const ofBuffer& buffer, bool binary=true); //-------------------------------------------------- /// \class ofFilePath @@ -294,32 +294,36 @@ class ofFilePath{ /// /// \param filename file path /// \returns filename extension only - static std::string getFileExt(const std::filesystem::path& filename); + static std::string getFileExt(const of::filesystem::path& filename); /// Remove extension from a filename, ie. "duck.jpg" ->"duck". /// /// \param filename file path /// \returns filename without extension - static std::string removeExt(const std::filesystem::path& filename); - +// MARK: - near future +// static of::filesystem::path removeExt(const of::filesystem::path& filename); + static std::string removeExt(const of::filesystem::path& filename); + /// Prepend path with a slash, ie. "images" -> "/images". /// /// \param path file or directory path /// \returns slah + path - static std::string addLeadingSlash(const std::filesystem::path& path); + static std::string addLeadingSlash(const of::filesystem::path& path); /// Append path with a slash, ie. "images" -> "images/". /// /// \param path directory path /// \returns path + slash - static std::string addTrailingSlash(const std::filesystem::path& path); - +// MARK: - near future +// static of::filesystem::path addTrailingSlash(const of::filesystem::path& path); + static std::string addTrailingSlash(const of::filesystem::path& path); + /// Remove a path's trailing slash (if found), /// ie. "images/" -> "images". /// /// \param path directory path /// \returns path minus trailing slash - static std::string removeTrailingSlash(const std::filesystem::path& path); + static std::string removeTrailingSlash(const of::filesystem::path& path); /// Cleaned up a directory path by adding a trailing slash if needed. /// @@ -328,7 +332,7 @@ class ofFilePath{ /// /// \param path directory path /// \returns cleaned path + trailing slash (if needed) - static std::string getPathForDirectory(const std::filesystem::path& path); + static std::string getPathForDirectory(const of::filesystem::path& path); /// Get the absolute, full path for a given path, /// ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images". @@ -338,7 +342,9 @@ class ofFilePath{ /// are *not* in the data folder and want the direct path without relative /// "../../" /// \returns absolute path - static std::string getAbsolutePath(const std::filesystem::path& path, bool bRelativeToData = true); + // MARK - near future + // static of::filesystem::path getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData = true); + static std::string getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData = true); /// Check if a path is an absolute (aka a full path), /// ie. "images" -> false, @@ -346,7 +352,7 @@ class ofFilePath{ /// /// \param path file or directory path /// \returns true if the path is an absolute path - static bool isAbsolute(const std::filesystem::path& path); + static bool isAbsolute(const of::filesystem::path& path); /// Get the filename of a given path by stripping the parent /// directories ie. "images/duck.jpg" -> "duck.jpg", assumes the path is in @@ -357,7 +363,9 @@ class ofFilePath{ /// are *not* in the data folder and want the direct path without relative /// "../../" /// \returns filename - static std::string getFileName(const std::filesystem::path& filePath, bool bRelativeToData = true); + /// + // FIXME: Deprecate / Remove this. + static std::string getFileName(const of::filesystem::path& filePath, bool bRelativeToData = true); /// Get a file name without its extension, /// ie. "images/duck.jpg" -> "duck" and @@ -365,7 +373,7 @@ class ofFilePath{ /// /// \param filePath file path /// \returns basename - static std::string getBaseName(const std::filesystem::path& filePath); + static std::string getBaseName(const of::filesystem::path& filePath); /// Get the enclosing parent directory of a path, /// ie. "images/duck.jpg" -> "images", assumes the path is in the data @@ -376,7 +384,9 @@ class ofFilePath{ /// are *not* in the data folder and want the direct path without relative /// "../../" ///\returns enclosing directory - static std::string getEnclosingDirectory(const std::filesystem::path& filePath, bool bRelativeToData = true); +// MARK: - near future +// static of::filesystem::path getEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData = true); + static std::string getEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData = true); /// Create the enclosing parent directory of a path, ie. /// "images" is the enclosing directory of "duck.jpg" = "images/duck.jpg". @@ -390,7 +400,7 @@ class ofFilePath{ /// are *not* in the data folder and want the direct path without relative /// "../../" /// \returns true if the enclosing directory was created - static bool createEnclosingDirectory(const std::filesystem::path& filePath, bool bRelativeToData = true, bool bRecursive = true); + static bool createEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData = true, bool bRecursive = true); /// Get the full path to the app's current working directory. /// @@ -408,8 +418,10 @@ class ofFilePath{ /// \param path1 left half of the path to join /// \param path2 right half of the path to join /// \returns joined path - static std::string join(const std::filesystem::path& path1, const std::filesystem::path& path2); - +// MARK: - near future +// static of::filesystem::path join(const of::filesystem::path& path1, const of::filesystem::path& path2); + static std::string join(const of::filesystem::path& path1, const of::filesystem::path& path2); + /// Get the full path to the application's executable file. /// /// Mac: the binary within the application's .app bundle Contents/MacOS dir @@ -425,6 +437,8 @@ class ofFilePath{ /// Mac: the Contents/MacOS folder within the application's .app bundle /// /// \returns current executable directory +// MARK: - near future +// static of::filesystem::path getCurrentExeDir(); static std::string getCurrentExeDir(); /// Get the absolute path to the user's home directory. @@ -443,7 +457,9 @@ class ofFilePath{ /// \param from starting path /// \param to destination path /// \returns relative path - static std::string makeRelative(const std::filesystem::path & from, const std::filesystem::path & to); + // MARK: - near future +// static of::filesystem::path makeRelative(const of::filesystem::path & from, const of::filesystem::path & to); + static std::string makeRelative(const of::filesystem::path & from, const of::filesystem::path & to); }; /// \class ofFile @@ -481,7 +497,7 @@ class ofFile: public std::fstream{ /// (read only, read write, etc) /// \param binary set to false if you are working with a text file & want /// lines split at endline characters automatically - ofFile(const std::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); + ofFile(const of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); /// Create a new file path using the same path & settings of another /// file. @@ -506,7 +522,8 @@ class ofFile: public std::fstream{ /// \param binary set to false if you are reading a text file & want lines /// split at endline characters automatically /// \returns true if the path was opened - bool open(const std::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); +// bool open(of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); + bool open(const of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); /// Open the path as a file. /// @@ -518,7 +535,7 @@ class ofFile: public std::fstream{ /// \param binary set to false if you are reading a text file & want lines /// split at endline characters automatically /// \returns true if the path was opened - bool openFromCWD(const std::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); + bool openFromCWD(const of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true); /// Reopen the current file path with a different access mode. /// @@ -545,7 +562,7 @@ class ofFile: public std::fstream{ /// /// \param path file path /// \returns true if the file was created - bool create(const std::filesystem::path & path); + bool create(const of::filesystem::path & path); /// Check if a file exists at the current path. /// @@ -555,8 +572,10 @@ class ofFile: public std::fstream{ /// Get the current path. /// /// \returns current path +// MARK: - near future +// of::filesystem::path path() const; std::string path() const; - + /// Get the current path without its extension, /// ie. "duck.jpg" ->"duck". /// @@ -581,12 +600,16 @@ class ofFile: public std::fstream{ /// directory. /// /// \returns current path's enclosing directory +// MARK: - near future +// of::filesystem::path getEnclosingDirectory() const; std::string getEnclosingDirectory() const; /// \biref Get the absolute, full path of the file, /// ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images". /// /// \returns current path as an absolute path +// MARK: - near future +// of::filesystem::path getAbsolutePath() const; std::string getAbsolutePath() const; /// Check if the current path is readable. @@ -659,7 +682,7 @@ class ofFile: public std::fstream{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - bool copyTo(const std::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false) const; + bool copyTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false) const; /// Move the current file or directory path to a new path. /// @@ -673,7 +696,7 @@ class ofFile: public std::fstream{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - bool moveTo(const std::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); + bool moveTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); /// Rename the current file or directory path to a new path. /// @@ -687,7 +710,7 @@ class ofFile: public std::fstream{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - bool renameTo(const std::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); + bool renameTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); /// Removes the file or directory at the current path. /// @@ -741,11 +764,11 @@ class ofFile: public std::fstream{ /// \return output stream std::filebuf * getFileBuffer() const; - operator std::filesystem::path(){ + operator of::filesystem::path(){ return myFile; } - - operator const std::filesystem::path() const{ +// + operator of::filesystem::path() const{ return myFile; } @@ -765,7 +788,7 @@ class ofFile: public std::fstream{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - static bool copyFromTo(const std::filesystem::path& pathSrc, const std::filesystem::path& pathDst, bool bRelativeToData = true, bool overwrite = false); + static bool copyFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData = true, bool overwrite = false); /// Move source path to destination path. /// @@ -781,7 +804,7 @@ class ofFile: public std::fstream{ /// \warning be careful with slashes here, appending a slash when moving a /// folder may cause mad headaches in OSX /// \returns true if the move was successful - static bool moveFromTo(const std::filesystem::path& pathSrc, const std::filesystem::path& pathDst, bool bRelativeToData = true, bool overwrite = false); + static bool moveFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData = true, bool overwrite = false); /// Check if a file or directory exists at a given path. /// @@ -790,7 +813,7 @@ class ofFile: public std::fstream{ /// are *not* in the data folder and want the direct path without relative /// "../../" /// \returns true if a file or directory exists - static bool doesFileExist(const std::filesystem::path& fPath, bool bRelativeToData = true); + static bool doesFileExist(const of::filesystem::path& fPath, bool bRelativeToData = true); /// Remove a file or directory at a given path. /// @@ -798,13 +821,14 @@ class ofFile: public std::fstream{ /// are *not* in the data folder and want the direct path without relative /// "../../" /// \returns true if the path was removed successfully - static bool removeFile(const std::filesystem::path& path, bool bRelativeToData = true); + static bool removeFile(const of::filesystem::path& path, bool bRelativeToData = true); private: bool isWriteMode(); bool openStream(Mode _mode, bool binary); void copyFrom(const ofFile & mom); - std::filesystem::path myFile; + + of::filesystem::path myFile; Mode mode; bool binary; }; @@ -827,17 +851,17 @@ class ofDirectory{ /// Create an ofDirectory instance and attempt to open the path. /// /// \param path directory path - ofDirectory(const std::filesystem::path & path); + ofDirectory(const of::filesystem::path & path); /// Open a directory path, clears the current file list. /// /// \param path directory path - void open(const std::filesystem::path & path); + void open(const of::filesystem::path & path); /// Open a directory path relative to the current working directory without calling ofToDataPath internally, clears the current file list. /// /// \param path directory path - void openFromCWD(const std::filesystem::path & path); + void openFromCWD(const of::filesystem::path & path); /// Close the currently open path. void close(); @@ -856,12 +880,16 @@ class ofDirectory{ /// Get the current path. /// /// \returns current path +// MARK: - near future +// of::filesystem::path path() const; std::string path() const; - + /// Get the absolute, full path of the directory, /// ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images". /// /// \return current path as an absolute path +// MARK: - near future +// of::filesystem::path getAbsolutePath() const; std::string getAbsolutePath() const; /// Check if the current path is readable. @@ -929,7 +957,7 @@ class ofDirectory{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - bool copyTo(const std::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); + bool copyTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); /// Move the current file or directory path to a new path. /// @@ -943,7 +971,7 @@ class ofDirectory{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - bool moveTo(const std::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); + bool moveTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); /// Rename the current file or directory path to a new path. /// @@ -957,7 +985,7 @@ class ofDirectory{ /// \param overwrite set to true if you want to overwrite the file or /// directory at the new path /// \returns true if the copy was successful - bool renameTo(const std::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); + bool renameTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false); /// Removes the file or directory at the current path. /// @@ -1107,11 +1135,11 @@ class ofDirectory{ bool operator>(const ofDirectory & dir) const; bool operator>=(const ofDirectory & dir) const; - operator std::filesystem::path(){ + operator of::filesystem::path(){ return myDir; } - operator const std::filesystem::path() const{ + operator of::filesystem::path() const{ return myDir; } @@ -1129,7 +1157,7 @@ class ofDirectory{ /// \param bRecursive set to true to automatically create nested directories /// as required /// \returns true if directory was created successfully - static bool createDirectory(const std::filesystem::path& dirPath, bool bRelativeToData = true, bool recursive = false); + static bool createDirectory(const of::filesystem::path& dirPath, bool bRelativeToData = true, bool recursive = false); /// Check if a directory at a given path is empty. /// @@ -1140,7 +1168,7 @@ class ofDirectory{ /// are *not* in the data directory /// \returns true if the directory is empty aka contains no files or /// directories - static bool isDirectoryEmpty(const std::filesystem::path& dirPath, bool bRelativeToData = true ); + static bool isDirectoryEmpty(const of::filesystem::path& dirPath, bool bRelativeToData = true ); /// Check if a directory exists at a given path. /// @@ -1150,7 +1178,7 @@ class ofDirectory{ /// \param bRelativeToData set to false if you are working with paths that /// are *not* in the data directory /// \returns true if the directory exists - static bool doesDirectoryExist(const std::filesystem::path& dirPath, bool bRelativeToData = true); + static bool doesDirectoryExist(const of::filesystem::path& dirPath, bool bRelativeToData = true); /// remove a directory at a given path @@ -1160,15 +1188,14 @@ class ofDirectory{ /// \param bRelativeToData set to false if you are working with paths that /// are *not* in the data directory /// \returns true if the path was removed successfully - static bool removeDirectory(const std::filesystem::path& path, bool deleteIfNotEmpty, bool bRelativeToData = true); + static bool removeDirectory(const of::filesystem::path& path, bool deleteIfNotEmpty, bool bRelativeToData = true); std::vector::const_iterator begin() const; std::vector::const_iterator end() const; std::vector::const_reverse_iterator rbegin() const; std::vector::const_reverse_iterator rend() const; -private: - std::filesystem::path myDir; + of::filesystem::path myDir; std::string originalDirectory; std::vector extensions; std::vector files; @@ -1200,7 +1227,9 @@ void ofDisableDataPath(); /// \param path The path to make relative to the data/ folder. /// \param absolute Set to true to return an absolute path. /// \returns the new path, unless paths were disabled with ofDisableDataPath(). -std::string ofToDataPath(const std::filesystem::path & path, bool absolute=false); +// MARK: - near future +//of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool absolute=false); +std::string ofToDataPath(const of::filesystem::path & path, bool absolute=false); /// \brief Reset the working directory to the platform default. /// @@ -1219,7 +1248,7 @@ bool ofRestoreWorkingDirectoryToDefault(); /// /// \warning The provided path must have a trailing slash (/). /// \param root The path to the data/ folder relative to the app executable. -void ofSetDataPathRoot(const std::filesystem::path& root); +void ofSetDataPathRoot(const of::filesystem::path& root); /*! \cond PRIVATE */ namespace of{ diff --git a/libs/openFrameworks/utils/ofJson.h b/libs/openFrameworks/utils/ofJson.h index b0edf2099ac..8907e0f84d6 100644 --- a/libs/openFrameworks/utils/ofJson.h +++ b/libs/openFrameworks/utils/ofJson.h @@ -14,7 +14,7 @@ using ofJson = nlohmann::json; /// \brief Load Json from the given path. /// \param filename The file to load from. /// \returns loaded json, or an empty json object on failure. -inline ofJson ofLoadJson(const std::filesystem::path& filename){ +inline ofJson ofLoadJson(const of::filesystem::path& filename){ ofJson json; ofFile jsonFile(filename); if(jsonFile.exists()){ @@ -35,7 +35,7 @@ inline ofJson ofLoadJson(const std::filesystem::path& filename){ /// \param filename The destination path. /// \param json The Json to save. /// \returns true if the json was saved successfully. -inline bool ofSaveJson(const std::filesystem::path& filename, const ofJson & json){ +inline bool ofSaveJson(const of::filesystem::path& filename, const ofJson & json){ ofFile jsonFile(filename, ofFile::WriteOnly); try{ jsonFile << json; @@ -53,7 +53,7 @@ inline bool ofSaveJson(const std::filesystem::path& filename, const ofJson & jso /// \param filename The destination path. /// \param json The Json to save. /// \returns true if the json was saved successfully. -inline bool ofSavePrettyJson(const std::filesystem::path& filename, const ofJson & json){ +inline bool ofSavePrettyJson(const of::filesystem::path& filename, const ofJson & json){ ofFile jsonFile(filename, ofFile::WriteOnly); try{ jsonFile << json.dump(4); diff --git a/libs/openFrameworks/utils/ofLog.cpp b/libs/openFrameworks/utils/ofLog.cpp index 13660a6b1dc..0bea13cb3d4 100644 --- a/libs/openFrameworks/utils/ofLog.cpp +++ b/libs/openFrameworks/utils/ofLog.cpp @@ -61,7 +61,7 @@ ofLogLevel ofGetLogLevel(string module){ } //-------------------------------------------------- -void ofLogToFile(const std::filesystem::path & path, bool append){ +void ofLogToFile(const of::filesystem::path & path, bool append){ ofLog::setChannel(std::make_shared(path,append)); } @@ -261,7 +261,7 @@ void ofDebugViewLoggerChannel::log(ofLogLevel level, const string & module, cons ofFileLoggerChannel::ofFileLoggerChannel(){ } -ofFileLoggerChannel::ofFileLoggerChannel(const std::filesystem::path & path, bool append){ +ofFileLoggerChannel::ofFileLoggerChannel(const of::filesystem::path & path, bool append){ setFile(path,append); } @@ -273,7 +273,7 @@ void ofFileLoggerChannel::close(){ file.close(); } -void ofFileLoggerChannel::setFile(const std::filesystem::path & path,bool append){ +void ofFileLoggerChannel::setFile(const of::filesystem::path & path,bool append){ file.open(path,append?ofFile::Append:ofFile::WriteOnly); file << std::endl; file << std::endl; diff --git a/libs/openFrameworks/utils/ofLog.h b/libs/openFrameworks/utils/ofLog.h index ddb23622054..4c587dc1c53 100644 --- a/libs/openFrameworks/utils/ofLog.h +++ b/libs/openFrameworks/utils/ofLog.h @@ -236,7 +236,7 @@ class ofBaseLoggerChannel; /// \brief Set the logging to output to a file instead of the console. /// \param path The path to the log file to use. /// \param append True if you want to append to the existing file. -void ofLogToFile(const std::filesystem::path & path, bool append=false); +void ofLogToFile(const of::filesystem::path & path, bool append=false); /// \brief Set the logging to ouptut to the console. /// @@ -703,7 +703,7 @@ class ofFileLoggerChannel: public ofBaseLoggerChannel{ /// \brief Create an ofFileLoggerChannel with parameters. /// \param path The file path for the log file. /// \param append True if the log data should be added to an existing file. - ofFileLoggerChannel(const std::filesystem::path & path, bool append); + ofFileLoggerChannel(const of::filesystem::path & path, bool append); /// \brief Destroy the file logger channel. virtual ~ofFileLoggerChannel(); @@ -711,7 +711,7 @@ class ofFileLoggerChannel: public ofBaseLoggerChannel{ /// \brief Set the log file. /// \param path The file path for the log file. /// \param append True if the log data should be added to an existing file. - void setFile(const std::filesystem::path & path,bool append=false); + void setFile(const of::filesystem::path & path,bool append=false); void log(ofLogLevel level, const std::string & module, const std::string & message); diff --git a/libs/openFrameworks/utils/ofSystemUtils.cpp b/libs/openFrameworks/utils/ofSystemUtils.cpp index e4b6fe4ed75..fd0612c9116 100644 --- a/libs/openFrameworks/utils/ofSystemUtils.cpp +++ b/libs/openFrameworks/utils/ofSystemUtils.cpp @@ -488,8 +488,10 @@ ofFileDialogResult ofSystemLoadDialog(std::string windowTitle, bool bFolderSelec //---------------------------------------------------------------------------------------- #if defined( TARGET_LINUX ) && defined (OF_USING_GTK) auto locale = std::locale(); - if(bFolderSelection) results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,windowTitle,ofToDataPath(defaultPath)); - else results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_OPEN,windowTitle,ofToDataPath(defaultPath)); + if(bFolderSelection) + results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, windowTitle, ofToDataPath(defaultPath).c_str()); + else + results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_OPEN, windowTitle, ofToDataPath(defaultPath).c_str()); resetLocale(locale); #endif //---------------------------------------------------------------------------------------- @@ -571,6 +573,7 @@ ofFileDialogResult ofSystemSaveDialog(std::string defaultName, std::string messa //---------------------------------------------------------------------------------------- #if defined( TARGET_LINUX ) && defined (OF_USING_GTK) auto locale = std::locale(); + // results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_SAVE, messageName, ofToDataPath(defaultName).string()); results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_SAVE, messageName, ofToDataPath(defaultName)); resetLocale(locale); #endif diff --git a/libs/openFrameworks/utils/ofURLFileLoader.cpp b/libs/openFrameworks/utils/ofURLFileLoader.cpp index f79c315518a..26e5f93d457 100644 --- a/libs/openFrameworks/utils/ofURLFileLoader.cpp +++ b/libs/openFrameworks/utils/ofURLFileLoader.cpp @@ -31,8 +31,8 @@ class ofURLFileLoaderImpl: public ofThread, public ofBaseURLFileLoader{ ~ofURLFileLoaderImpl(); ofHttpResponse get(const string& url); int getAsync(const string& url, const string& name=""); // returns id - ofHttpResponse saveTo(const string& url, const std::filesystem::path& path); - int saveAsync(const string& url, const std::filesystem::path& path); + ofHttpResponse saveTo(const string& url, const of::filesystem::path& path); + int saveAsync(const string& url, const of::filesystem::path& path); void remove(int id); void clear(); void stop(); @@ -79,12 +79,12 @@ int ofURLFileLoaderImpl::getAsync(const string& url, const string& name){ } -ofHttpResponse ofURLFileLoaderImpl::saveTo(const string& url, const std::filesystem::path& path){ +ofHttpResponse ofURLFileLoaderImpl::saveTo(const string& url, const of::filesystem::path& path){ ofHttpRequest request(url,path.string(),true); return handleRequest(request); } -int ofURLFileLoaderImpl::saveAsync(const string& url, const std::filesystem::path& path){ +int ofURLFileLoaderImpl::saveAsync(const string& url, const of::filesystem::path& path){ ofHttpRequest request(url,path.string(),true); requests.send(request); start(); @@ -293,11 +293,11 @@ int ofURLFileLoader::getAsync(const string& url, const string& name){ return impl->getAsync(url,name); } -ofHttpResponse ofURLFileLoader::saveTo(const string& url, const std::filesystem::path & path){ +ofHttpResponse ofURLFileLoader::saveTo(const string& url, const of::filesystem::path & path){ return impl->saveTo(url,path); } -int ofURLFileLoader::saveAsync(const string& url, const std::filesystem::path & path){ +int ofURLFileLoader::saveAsync(const string& url, const of::filesystem::path & path){ return impl->saveAsync(url,path); } @@ -388,11 +388,11 @@ int ofLoadURLAsync(const string& url, const string& name){ return getFileLoader().getAsync(url,name); } -ofHttpResponse ofSaveURLTo(const string& url, const std::filesystem::path& path){ +ofHttpResponse ofSaveURLTo(const string& url, const of::filesystem::path& path){ return getFileLoader().saveTo(url,path); } -int ofSaveURLAsync(const string& url, const std::filesystem::path& path){ +int ofSaveURLAsync(const string& url, const of::filesystem::path& path){ return getFileLoader().saveAsync(url,path); } diff --git a/libs/openFrameworks/utils/ofURLFileLoader.h b/libs/openFrameworks/utils/ofURLFileLoader.h index 10ee0af25d9..f23e6a9ef33 100644 --- a/libs/openFrameworks/utils/ofURLFileLoader.h +++ b/libs/openFrameworks/utils/ofURLFileLoader.h @@ -71,7 +71,7 @@ int ofLoadURLAsync(const std::string& url, const std::string& name=""); // retur /// \param url HTTP url to request, ie. "http://somewebsite.com/someapi/someimage.jpg" /// \param path file path to save to /// \return HTTP response on success or failure -ofHttpResponse ofSaveURLTo(const std::string& url, const std::filesystem::path& path); +ofHttpResponse ofSaveURLTo(const std::string& url, const of::filesystem::path& path); /// make an asynchronous HTTP request for a url and save the response to a file at path /// \returns unique request id for the active HTTP request @@ -81,7 +81,7 @@ ofHttpResponse ofSaveURLTo(const std::string& url, const std::filesystem::path& /// \param url HTTP url to request, ie. "http://somewebsite.com/someapi/someimage.jpg" /// \param path file path to save to /// \returns unique id for the active HTTP request -int ofSaveURLAsync(const std::string& url, const std::filesystem::path& path); +int ofSaveURLAsync(const std::string& url, const of::filesystem::path& path); /// \brief remove an active HTTP request from the queue /// \param id HTTP request id @@ -132,14 +132,14 @@ class ofURLFileLoader { /// \param url HTTP url to request, ie. "http://somewebsite.com/someapi/someimage.jpg" /// \param path file path to save to /// \return HTTP response on success or failure - ofHttpResponse saveTo(const std::string& url, const std::filesystem::path& path); + ofHttpResponse saveTo(const std::string& url, const of::filesystem::path& path); /// \brief make an asynchronous HTTP request and save the response data to a file /// will not block, placed in a queue and run using a background thread /// \param url HTTP url to request, ie. "http://somewebsite.com/someapi/someimage.jpg" /// \param path file path to save to /// \returns unique id for the active HTTP request - int saveAsync(const std::string& url, const std::filesystem::path& path); + int saveAsync(const std::string& url, const of::filesystem::path& path); /// \brief remove an active HTTP request from the queue /// \param id HTTP request id @@ -191,14 +191,14 @@ class ofBaseURLFileLoader{ /// \param url HTTP url to request, ie. "http://somewebsite.com/someapi/someimage.jpg" /// \param path file path to save to /// \return HTTP response on success or failure - virtual ofHttpResponse saveTo(const std::string& url, const std::filesystem::path& path)=0; + virtual ofHttpResponse saveTo(const std::string& url, const of::filesystem::path& path)=0; /// \brief make an asynchronous HTTP request and save the response data to a file /// will not block, placed in a queue and run using a background thread /// \param url HTTP url to request, ie. "http://somewebsite.com/someapi/someimage.jpg" /// \param path file path to save to /// \returns unique id for the active HTTP request - virtual int saveAsync(const std::string& url, const std::filesystem::path& path)=0; + virtual int saveAsync(const std::string& url, const of::filesystem::path& path)=0; /// \brief remove an active HTTP request from the queue /// \param unique HTTP request id diff --git a/libs/openFrameworks/utils/ofXml.cpp b/libs/openFrameworks/utils/ofXml.cpp index c910e4932bc..244325ddca8 100644 --- a/libs/openFrameworks/utils/ofXml.cpp +++ b/libs/openFrameworks/utils/ofXml.cpp @@ -15,8 +15,9 @@ ofXml::ofXml(std::shared_ptr doc, const pugi::xml_node & xml } -bool ofXml::load(const std::filesystem::path & file){ +bool ofXml::load(const of::filesystem::path & file){ auto auxDoc = std::make_shared(); + auto p = ofToDataPath(file); auto res = auxDoc->load_file(ofToDataPath(file).c_str()); if( res ){ doc = auxDoc; @@ -47,10 +48,10 @@ bool ofXml::parse(const std::string & xmlStr){ } } -bool ofXml::save(const std::filesystem::path & file) const{ +bool ofXml::save(const of::filesystem::path & file) const{ if(xml == doc->root()){ auto res = doc->save_file(ofToDataPath(file).c_str()); - ofLogVerbose("ofXml")<<"save: "<< res; + ofLogVerbose("ofXml")<<"ofXML Save : "<< res; ofLogVerbose("ofXml")<toString(); return res; }else{ diff --git a/libs/openFrameworks/utils/ofXml.h b/libs/openFrameworks/utils/ofXml.h index c4006615ff2..d4f62c91ce3 100644 --- a/libs/openFrameworks/utils/ofXml.h +++ b/libs/openFrameworks/utils/ofXml.h @@ -100,10 +100,10 @@ class ofXml{ ofXml(); - bool load(const std::filesystem::path & file); + bool load(const of::filesystem::path & file); bool load(const ofBuffer & buffer); bool parse(const std::string & xmlStr); - bool save(const std::filesystem::path & file) const; + bool save(const of::filesystem::path & file) const; void clear(); std::string toString(const std::string & indent = "\t") const; diff --git a/libs/openFrameworks/video/ofDirectShowPlayer.cpp b/libs/openFrameworks/video/ofDirectShowPlayer.cpp index 2ff3da97d7b..e42fb51f0cc 100644 --- a/libs/openFrameworks/video/ofDirectShowPlayer.cpp +++ b/libs/openFrameworks/video/ofDirectShowPlayer.cpp @@ -427,7 +427,7 @@ class DirectShowVideo : public ISampleGrabberCB{ return E_NOTIMPL; } - bool loadMovie(std::string path, ofPixelFormat format){ + bool loadMovie(of::filesystem::path path, ofPixelFormat format){ tearDown(); this->pixelFormat = format; @@ -530,7 +530,8 @@ class DirectShowVideo : public ISampleGrabberCB{ } //printf("step 6\n"); - std::wstring filePathW = std::wstring(path.begin(), path.end()); + std::string pathString = path.string(); + std::wstring filePathW = std::wstring(pathString.begin(), pathString.end()); //this is the easier way to connect the graph, but we have to remove the video window manually hr = m_pGraph->RenderFile(filePathW.c_str(), NULL); @@ -1125,8 +1126,9 @@ ofDirectShowPlayer & ofDirectShowPlayer::operator=(ofDirectShowPlayer&& other) { return *this; } -bool ofDirectShowPlayer::load(std::string path){ - path = ofToDataPath(path); +// FIXME: convert to filesystem::path in near future +bool ofDirectShowPlayer::load(std::string stringPath){ + auto path = ofToDataPath(of::filesystem::path(stringPath)); close(); player.reset(new DirectShowVideo()); diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index 17a7c4f81ef..9f958f07564 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -4,7 +4,7 @@ using namespace std; -std::filesystem::path initial_cwd; +of::filesystem::path initial_cwd; class ofApp: public ofxUnitTestsApp{ void run(){ @@ -180,13 +180,15 @@ class ofApp: public ofxUnitTestsApp{ ofxTestEq(ofFilePath::getBaseName("test/test.txt"),"test","ofFilePath::getBaseName",ofFilePath::getBaseName("test/test.txt")); ofxTestEq(ofFilePath::getBaseName(ofFilePath::removeTrailingSlash(ofFilePath::getEnclosingDirectory("testdir/test.txt"))),"testdir","ofFilePath::getEnclosingDirectory",ofFilePath::getBaseName(ofFilePath::getEnclosingDirectory("testdir/test.txt"))); #ifdef TARGET_WIN32 + // ofxTestEq(ofFilePath::join("d1","d2").string(),"d1\\d2","ofFilePath::join",ofFilePath::join("d1","d2").string()); ofxTestEq(ofFilePath::join("d1","d2"),"d1\\d2","ofFilePath::join",ofFilePath::join("d1","d2")); #else + // ofxTestEq(ofFilePath::join("d1","d2").string(),"d1/d2","ofFilePath::join",ofFilePath::join("d1","d2").string()); ofxTestEq(ofFilePath::join("d1","d2"),"d1/d2","ofFilePath::join",ofFilePath::join("d1","d2")); #endif - ofxTest(std::filesystem::exists(ofFile("test.txt")), "ofFile cast to filesystem::path"); - ofxTest(std::filesystem::exists(ofDirectory("d1")), "ofDirectory cast to filesystem::path"); + ofxTest(of::filesystem::exists(ofFile("test.txt")), "ofFile cast to filesystem::path"); + ofxTest(of::filesystem::exists(ofDirectory("d1")), "ofDirectory cast to filesystem::path"); @@ -204,7 +206,7 @@ class ofApp: public ofxUnitTestsApp{ //======================================================================== ofLogNotice() << ""; ofLogNotice() << "tests #4299"; - ofxTestEq(std::filesystem::path(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); + ofxTestEq(of::filesystem::path(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); if(ofGetTargetPlatform()==OF_TARGET_OSX){ ofxTestEq(ofToDataPath("",false),"../../../data/","ofToDataPath relative"); }else if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ @@ -218,12 +220,22 @@ class ofApp: public ofxUnitTestsApp{ ofLogNotice() << ""; ofLogNotice() << "tests #4462"; if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ + // ofxTestEq(ofToDataPath("movies\\",true).string().back(), '\\', "absolute ofToDataPath with \\ should end in \\"); + // ofxTestEq(ofToDataPath("movies",true).string().back(), 's', "absolute ofToDataPath without \\ should not end in \\"); + // ofDirectory("movies").create(); + // ofxTestEq(ofToDataPath("movies\\",true).string().back(), '\\', "absolute ofToDataPath with \\ should end in \\"); + // ofxTestEq(ofToDataPath("movies",true).string().back(), 's', "absolute ofToDataPath without \\ should not end in \\"); ofxTestEq(ofToDataPath("movies\\",true).back(), '\\', "absolute ofToDataPath with \\ should end in \\"); ofxTestEq(ofToDataPath("movies",true).back(), 's', "absolute ofToDataPath without \\ should not end in \\"); ofDirectory("movies").create(); ofxTestEq(ofToDataPath("movies\\",true).back(), '\\', "absolute ofToDataPath with \\ should end in \\"); ofxTestEq(ofToDataPath("movies",true).back(), 's', "absolute ofToDataPath without \\ should not end in \\"); }else{ + // ofxTestEq(ofToDataPath("movies/",true).string().back(), '/', "absolute ofToDataPath with / should end in /"); + // ofxTestEq(ofToDataPath("movies",true).string().back(), 's', "absolute ofToDataPath without / should not end in /"); + // ofDirectory("movies").create(); + // ofxTestEq(ofToDataPath("movies/",true).string().back(), '/', "absolute ofToDataPath with / should end in /"); + // ofxTestEq(ofToDataPath("movies",true).string().back(), 's', "absolute ofToDataPath without / should not end in /"); ofxTestEq(ofToDataPath("movies/",true).back(), '/', "absolute ofToDataPath with / should end in /"); ofxTestEq(ofToDataPath("movies",true).back(), 's', "absolute ofToDataPath without / should not end in /"); ofDirectory("movies").create(); @@ -235,11 +247,21 @@ class ofApp: public ofxUnitTestsApp{ //======================================================================== ofLogNotice() << ""; ofLogNotice() << "tests #4598"; - ofxTestEq(ofToDataPath("").back(), std::filesystem::path::preferred_separator, "ofToDataPath with empty string shouldn't crash"); + // ofxTestEq(ofToDataPath("").string().back(), of::filesystem::path::preferred_separator, "ofToDataPath with empty string shouldn't crash"); + ofxTestEq(ofToDataPath("").back(), of::filesystem::path::preferred_separator, "ofToDataPath with empty string shouldn't crash"); //======================================================================== ofLogNotice() << ""; ofLogNotice() << "tests #4563"; +// #ifdef TARGET_LINUX +// ofxTestEq(ofToDataPath("a.txt").string(), "data/a.txt","#4563 test1"); +// ofxTestEq(ofToDataPath("data.txt").string(), "data/data.txt", "#4563 test2"); +// ofxTestEq(ofToDataPath("").string(), "data/", "#4563 test3"); +// #elif defined(TARGET_OSX) +// ofxTestEq(ofToDataPath("a.txt").string(), "../../../data/a.txt","#4563 test1"); +// ofxTestEq(ofToDataPath("data.txt").string(), "../../../data/data.txt", "#4563 test2"); +// ofxTestEq(ofToDataPath("").string(), "../../../data/", "#4563 test3"); +// #endif #ifdef TARGET_LINUX ofxTestEq(ofToDataPath("a.txt"), "data/a.txt","#4563 test1"); ofxTestEq(ofToDataPath("data.txt"), "data/data.txt", "#4563 test2"); @@ -250,7 +272,6 @@ class ofApp: public ofxUnitTestsApp{ ofxTestEq(ofToDataPath(""), "../../../data/", "#4563 test3"); #endif - //======================================================================== // clean test files dir.open("."); @@ -268,11 +289,13 @@ class ofApp: public ofxUnitTestsApp{ dir.remove(true); if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ ofDirectory currentVideoDirectory(ofToDataPath("..\\..\\..\\video", true)); + // auto path = currentVideoDirectory.path().string(); auto path = currentVideoDirectory.path(); std::string pathEnd("data\\..\\..\\..\\video\\"); ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); }else{ ofDirectory currentVideoDirectory(ofToDataPath("../../../video", true)); + // auto path = currentVideoDirectory.path().string(); auto path = currentVideoDirectory.path(); std::string pathEnd("data/../../../video/"); ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); @@ -285,7 +308,7 @@ class ofApp: public ofxUnitTestsApp{ #include "ofAppRunner.h" //======================================================================== int main( ){ - initial_cwd = std::filesystem::current_path(); + initial_cwd = of::filesystem::current_path(); ofInit(); auto window = std::make_shared(); auto app = std::make_shared();