From c96c60ff15e9c29a08e1cb925bbe4483b5f0b940 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 01:16:13 -0300 Subject: [PATCH 01/49] file utils simplification --- libs/openFrameworks/gl/ofCubeMap.cpp | 25 ++-- libs/openFrameworks/utils/ofFileUtils.cpp | 150 ++++++---------------- libs/openFrameworks/utils/ofFileUtils.h | 10 +- 3 files changed, 56 insertions(+), 129 deletions(-) diff --git a/libs/openFrameworks/gl/ofCubeMap.cpp b/libs/openFrameworks/gl/ofCubeMap.cpp index df36e282593..b4983f64e92 100644 --- a/libs/openFrameworks/gl/ofCubeMap.cpp +++ b/libs/openFrameworks/gl/ofCubeMap.cpp @@ -383,30 +383,33 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { // figure out the number of mip maps // data->maxMipLevels = log2(data->settings.preFilterRes) + 1; - std::string encFolder = data->settings.cacheDirectory; + of::filesystem::path encFolder = data->settings.cacheDirectory; if( !encFolder.empty() ) { if( !ofDirectory::doesDirectoryExist( ofFilePath::removeTrailingSlash( data->settings.cacheDirectory ))) { - #if !defined(TARGET_OPENGLES) +#if !defined(TARGET_OPENGLES) if(!ofDirectory::createDirectory( data->settings.cacheDirectory )) { ofLogWarning("ofCubeMap :: load : unable to create directory: ") << data->settings.cacheDirectory; } - #endif +#endif } else { } // encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ).string(); - encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ); + // encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ); + } - std::string baseName = ofFilePath::getBaseName( data->settings.filePath ); - std::string cacheIrrName = baseName+"_irr_"+ofToString(data->settings.irradianceRes,0)+".exr"; - std::string cachePrefilterName = baseName+"_pre_"+ofToString(data->settings.preFilterRes,0)+".exr"; + + // TODO: change everything to of::filesystem + of::filesystem::path baseName = ofFilePath::getBaseName( data->settings.filePath ); + of::filesystem::path cacheIrrName = baseName / ("_irr_"+ofToString(data->settings.irradianceRes,0) + ".exr"); + of::filesystem::path cachePrefilterName = baseName / ("_pre_"+ofToString(data->settings.preFilterRes,0)+".exr"); bool bHasCachedIrr = false; bool bHasCachedPre = false; if( data->settings.useCache && !data->settings.overwriteCache ) { - bHasCachedIrr = _loadIrradianceMap(encFolder+cacheIrrName); + bHasCachedIrr = _loadIrradianceMap(encFolder / cacheIrrName); ofLogVerbose("ofCubeMap :: _loadIrradianceMap: ") << bHasCachedIrr; - bHasCachedPre = _loadPrefilterMap(encFolder+cachePrefilterName); + bHasCachedPre = _loadPrefilterMap(encFolder / cachePrefilterName); ofLogVerbose("ofCubeMap :: _loadPrefilterMap: ") << bHasCachedPre; } @@ -418,12 +421,12 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { if( !bHasCachedIrr ) { ofLogVerbose("ofCubeMap :: going to create irradiance map"); - _createIrradianceMap(cubeFid,bMakeCache, encFolder+cacheIrrName); + _createIrradianceMap(cubeFid,bMakeCache, encFolder / cacheIrrName); } if( !bHasCachedPre ) { ofLogVerbose("ofCubeMap :: going to create pre filtered cube map"); - _createPrefilteredCubeMap(cubeFid, srcCubeFSize,bMakeCache,encFolder+cachePrefilterName ); + _createPrefilteredCubeMap(cubeFid, srcCubeFSize,bMakeCache,encFolder / cachePrefilterName ); } glDeleteTextures(1, &cubeFid ); diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 6e855e53311..990ce880b3e 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -30,19 +30,13 @@ namespace{ // 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(); - } + // three levels up because is a directory with path App.app/Contents/MacOS/App + return (ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_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::getCurrentExeDir() / of::filesystem::path("data/")).string(); - } + return (ofFilePath::getCurrentExeDir() / "data/").string(); #endif } @@ -1681,24 +1675,24 @@ string ofFilePath::addLeadingSlash(const of::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 ""; - // FIXME: Remove .string() here and following - // return (of::filesystem::path(_path).make_preferred() / ""); - return (of::filesystem::path(_path).make_preferred() / "").string(); -#else - auto path = of::filesystem::path(_path).make_preferred(); - auto sep = of::filesystem::path("/").make_preferred(); - if(!path.empty()){ - if(ofToString(path.string().back()) != sep.string()){ - path = (path / sep); - } - } -// return path; - return path.string(); -#endif -} +//std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ +//#if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS +// 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 = of::filesystem::path(_path).make_preferred(); +// auto sep = of::filesystem::path("/").make_preferred(); +// if(!path.empty()){ +// if(ofToString(path.string().back()) != sep.string()){ +// path = (path / sep); +// } +// } +//// return path; +// return path.string(); +//#endif +//} //------------------------------------------------------------------------------------------------------------ @@ -1776,7 +1770,9 @@ std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _file if(bRelativeToData){ fp = ofToDataPath(fp); } - return addTrailingSlash(fp.parent_path()); + +// return addTrailingSlash(fp.parent_path()); + return fp.parent_path(); } //------------------------------------------------------------------------------------------------------------ @@ -1854,10 +1850,9 @@ string ofFilePath::getCurrentExePath(){ } //------------------------------------------------------------------------------------------------------------ -// MARK: - near future -//of::filesystem::path ofFilePath::getCurrentExeDir(){ -std::string ofFilePath::getCurrentExeDir(){ - return ofFilePath::getEnclosingDirectory(ofFilePath::getCurrentExePath(), false); +of::filesystem::path ofFilePath::getCurrentExeDir(){ + auto exePath = of::filesystem::path(getCurrentExePath()); + return exePath.parent_path(); } //------------------------------------------------------------------------------------------------------------ @@ -1927,22 +1922,8 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ } //-------------------------------------------------- -// 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(); - } - - if (!enableDataPath) { -// return path; - return path.string(); - } - - bool hasTrailingSlash = !path.empty() && path.generic_string().back()=='/'; - - // if our Current Working Directory has changed (e.g. file open dialog) +of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ +// if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 if (defaultWorkingDirectory() != of::filesystem::current_path()) { // change our cwd back to where it was on app load @@ -1953,71 +1934,16 @@ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ } #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(); - 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; - } + if (makeAbsolute) { + return dataPath / path; } 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(); - } + if (!path.is_absolute()) { + auto exeDir = ofFilePath::getCurrentExeDir(); + auto result = of::filesystem::relative(dataPath / path, ofFilePath::getCurrentExeDir()); + return result; + } else { + return path; } - 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 db9c09edd20..a2ab9d22c65 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -316,7 +316,7 @@ class ofFilePath{ /// \returns path + slash // MARK: - near future // static of::filesystem::path addTrailingSlash(const of::filesystem::path& path); - static std::string 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". @@ -437,9 +437,7 @@ 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(); + static of::filesystem::path getCurrentExeDir(); /// Get the absolute path to the user's home directory. /// @@ -1228,8 +1226,8 @@ void ofDisableDataPath(); /// \param absolute Set to true to return an absolute path. /// \returns the new path, unless paths were disabled with ofDisableDataPath(). // 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); +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. /// From c199076a06b03705ba549bbdee24f47d66c037c1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 01:34:47 -0300 Subject: [PATCH 02/49] cubemap --- libs/openFrameworks/gl/ofCubeMap.cpp | 4 ++-- libs/openFrameworks/gl/ofCubeMap.h | 4 ++-- libs/openFrameworks/utils/ofFileUtils.cpp | 29 +++++++++++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/libs/openFrameworks/gl/ofCubeMap.cpp b/libs/openFrameworks/gl/ofCubeMap.cpp index b4983f64e92..55d376cdcb3 100644 --- a/libs/openFrameworks/gl/ofCubeMap.cpp +++ b/libs/openFrameworks/gl/ofCubeMap.cpp @@ -881,7 +881,7 @@ void ofCubeMap::_createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, std:: } //-------------------------------------------------------------- -bool ofCubeMap::_loadIrradianceMap(std::string aCachePath) { +bool ofCubeMap::_loadIrradianceMap(of::filesystem::path aCachePath) { if(data->bIrradianceAllocated) { return false; @@ -1098,7 +1098,7 @@ void ofCubeMap::_createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool } //-------------------------------------------------------------- -bool ofCubeMap::_loadPrefilterMap( std::string aCachePath ) { +bool ofCubeMap::_loadPrefilterMap( of::filesystem::path aCachePath ) { if(data->bPreFilteredMapAllocated) { return false; } diff --git a/libs/openFrameworks/gl/ofCubeMap.h b/libs/openFrameworks/gl/ofCubeMap.h index 30dd03e1bca..a3e64f219b3 100644 --- a/libs/openFrameworks/gl/ofCubeMap.h +++ b/libs/openFrameworks/gl/ofCubeMap.h @@ -126,10 +126,10 @@ class ofCubeMap { void _equiRectToCubeMap( GLuint& aCubeTexId, ofTexture& aSrcTex, int aSrcRes, bool aBConvertToNonFloat ); void _createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, std::string aCachePath); - bool _loadIrradianceMap(std::string aCachePath); + bool _loadIrradianceMap( of::filesystem::path aCachePath ); void _createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, std::string aCachePath); - bool _loadPrefilterMap( std::string aCachePath ); + bool _loadPrefilterMap( of::filesystem::path aCachePath ); static void _createBrdfLUT(); diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 990ce880b3e..fe14582f953 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -26,18 +26,23 @@ namespace{ bool enableDataPath = true; //-------------------------------------------------- -// MARK: - near future -// of::filesystem::path defaultDataPath(){ - std::string defaultDataPath(){ - #if defined TARGET_OSX - // three levels up because is a directory with path App.app/Contents/MacOS/App - return (ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() - / "data/").string(); - #elif defined TARGET_ANDROID - return string("sdcard/"); - #else - return (ofFilePath::getCurrentExeDir() / "data/").string(); - #endif + of::filesystem::path defaultDataPath(){ +#if defined TARGET_OSX + + // three levels up because is a directory with path App.app/Contents/MacOS/App + of::filesystem::path data = ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() / "data"; + if (!of::filesystem::is_directory(data)) { + // bundle data folder inside app + // one level up : MacOS/../Resources/data + data = ofFilePath::getCurrentExeDir().parent_path() / "Resources/data"; + } + return data; + +#elif defined TARGET_ANDROID + return { "sdcard/" }; +#else + return (ofFilePath::getCurrentExeDir() / "data"); +#endif } //-------------------------------------------------- From a8e677a299eca27bd8e639dce3805172eafd5eb8 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 01:40:33 -0300 Subject: [PATCH 03/49] cubemap fix aCachePath --- libs/openFrameworks/gl/ofCubeMap.cpp | 4 ++-- libs/openFrameworks/gl/ofCubeMap.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/gl/ofCubeMap.cpp b/libs/openFrameworks/gl/ofCubeMap.cpp index 55d376cdcb3..03ad615ccb5 100644 --- a/libs/openFrameworks/gl/ofCubeMap.cpp +++ b/libs/openFrameworks/gl/ofCubeMap.cpp @@ -740,7 +740,7 @@ void ofCubeMap::_equiRectToCubeMap( GLuint& aCubeTexId, ofTexture& aSrcTex, int } //-------------------------------------------------------------- -void ofCubeMap::_createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, std::string aCachePath) { +void ofCubeMap::_createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, of::filesystem::path aCachePath) { if(data->bIrradianceAllocated) { return; } @@ -940,7 +940,7 @@ bool ofCubeMap::_loadIrradianceMap(of::filesystem::path aCachePath) { } //-------------------------------------------------------------- -void ofCubeMap::_createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, std::string aCachePath) { +void ofCubeMap::_createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, of::filesystem::path aCachePath) { if(data->bPreFilteredMapAllocated) { return; } diff --git a/libs/openFrameworks/gl/ofCubeMap.h b/libs/openFrameworks/gl/ofCubeMap.h index a3e64f219b3..15e57399af7 100644 --- a/libs/openFrameworks/gl/ofCubeMap.h +++ b/libs/openFrameworks/gl/ofCubeMap.h @@ -125,10 +125,10 @@ class ofCubeMap { GLuint _createFloatCubeMap(ofTexture& aSrcTex, int aSrcRes); void _equiRectToCubeMap( GLuint& aCubeTexId, ofTexture& aSrcTex, int aSrcRes, bool aBConvertToNonFloat ); - void _createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, std::string aCachePath); + void _createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, of::filesystem::path aCachePath); bool _loadIrradianceMap( of::filesystem::path aCachePath ); - void _createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, std::string aCachePath); + void _createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, of::filesystem::path aCachePath); bool _loadPrefilterMap( of::filesystem::path aCachePath ); static void _createBrdfLUT(); From ce61301fe99adb8f785cb8ff85d4c797acd21bc9 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 01:56:50 -0300 Subject: [PATCH 04/49] parent_path() fix --- libs/openFrameworks/utils/ofFileUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index fe14582f953..eb99e81a8ef 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1777,7 +1777,7 @@ std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _file } // return addTrailingSlash(fp.parent_path()); - return fp.parent_path(); + return fp.parent_path().string(); } //------------------------------------------------------------------------------------------------------------ @@ -1790,7 +1790,7 @@ bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, //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); + return ofToDataPath(path, true).string(); }else{ try{ // return of::filesystem::canonical(of::filesystem::absolute(path)); From 915989653f66f07b3ca458ac5b0f67c5a496a23e Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 02:08:18 -0300 Subject: [PATCH 05/49] ofToDataPath string --- libs/openFrameworks/utils/ofFileUtils.cpp | 14 ++++++++------ libs/openFrameworks/utils/ofFileUtils.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index eb99e81a8ef..9a06bdddcfb 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1927,7 +1927,8 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ } //-------------------------------------------------- -of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ +//of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ +std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ // if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 if (defaultWorkingDirectory() != of::filesystem::current_path()) { @@ -1938,17 +1939,18 @@ of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAb } } #endif - + // FIXME: change to direct returns when return type is fs::path + of::filesystem::path outPath; const auto & dataPath = dataPathRoot(); if (makeAbsolute) { - return dataPath / path; + outPath = dataPath / path; } else { if (!path.is_absolute()) { auto exeDir = ofFilePath::getCurrentExeDir(); - auto result = of::filesystem::relative(dataPath / path, ofFilePath::getCurrentExeDir()); - return result; + outPath = of::filesystem::relative(dataPath / path, ofFilePath::getCurrentExeDir()); } else { - return path; + outPath = path; } } + return outPath.string(); } diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index a2ab9d22c65..3648601eaba 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -1226,8 +1226,8 @@ void ofDisableDataPath(); /// \param absolute Set to true to return an absolute path. /// \returns the new path, unless paths were disabled with ofDisableDataPath(). // 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); +//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. /// From 130008a772219c137597027fcdd6501aad4a7674 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 02:18:02 -0300 Subject: [PATCH 06/49] tiny fix --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 9a06bdddcfb..0c68c4ec654 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1790,7 +1790,7 @@ bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, //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).string(); + return ofToDataPath(path, true); }else{ try{ // return of::filesystem::canonical(of::filesystem::absolute(path)); From c3914c28a42c0e915548ff87d48116771dca9940 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 Mar 2023 02:38:17 -0300 Subject: [PATCH 07/49] updates --- libs/openFrameworks/utils/ofFileUtils.cpp | 41 +++++++++++------------ libs/openFrameworks/utils/ofFileUtils.h | 7 ++-- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 0c68c4ec654..e89e7fec7ab 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1381,7 +1381,7 @@ void ofDirectory::allowExt(const std::string& extension){ } //------------------------------------------------------------------------------------------------------------ -std::size_t ofDirectory::listDir(const std::string& directory){ +std::size_t ofDirectory::listDir(const of::filesystem::path & directory){ open(directory); return listDir(); } @@ -1678,26 +1678,25 @@ string ofFilePath::addLeadingSlash(const of::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 ""; -// // FIXME: Remove .string() here and following -// // return (of::filesystem::path(_path).make_preferred() / ""); -// return (of::filesystem::path(_path).make_preferred() / "").string(); -//#else -// auto path = of::filesystem::path(_path).make_preferred(); -// auto sep = of::filesystem::path("/").make_preferred(); -// if(!path.empty()){ -// if(ofToString(path.string().back()) != sep.string()){ -// path = (path / sep); -// } -// } -//// return path; -// return path.string(); -//#endif -//} +// MARK: - Remove this function after FS transition +std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ +#if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS + 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 = of::filesystem::path(_path).make_preferred(); + auto sep = of::filesystem::path("/").make_preferred(); + if(!path.empty()){ + if(ofToString(path.string().back()) != sep.string()){ + path = (path / sep); + } + } +// return path; + return path.string(); +#endif +} //------------------------------------------------------------------------------------------------------------ diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 3648601eaba..dde923d4cda 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -314,9 +314,8 @@ class ofFilePath{ /// /// \param path directory path /// \returns path + slash -// MARK: - near future -// static of::filesystem::path addTrailingSlash(const of::filesystem::path& path); -// static std::string addTrailingSlash(const of::filesystem::path& path); +// MARK: - remove after fs transition + static std::string addTrailingSlash(const of::filesystem::path& path); /// Remove a path's trailing slash (if found), /// ie. "images/" -> "images". @@ -1015,7 +1014,7 @@ class ofDirectory{ /// /// \param path directory path /// \returns number of paths found - std::size_t listDir(const std::string& path); + std::size_t listDir(const of::filesystem::path & path); /// Open and read the contents of the current directory. /// From e5e5ff2643e61b414b38b3a427cbc491773ba628 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Thu, 9 Mar 2023 16:19:10 -0300 Subject: [PATCH 08/49] things to fix yet --- libs/openFrameworks/utils/ofFileUtils.cpp | 100 ++++++++++++++++++---- tests/utils/fileUtils/src/main.cpp | 14 ++- 2 files changed, 95 insertions(+), 19 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index e89e7fec7ab..b9f64db407d 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -22,6 +22,9 @@ using std::istream; using std::ostream; using std::ios; +using std::cout; +using std::endl; + namespace{ bool enableDataPath = true; @@ -558,7 +561,9 @@ bool ofFile::openStream(Mode _mode, bool _binary){ //------------------------------------------------------------------------------------------------------------ bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); - myFile = ofToDataPath(_path); + myFile = ofToDataPath(_path, true); + cout << "offile::open=" << _path << endl; + cout << "myFile=" << myFile << endl; return openStream(_mode, binary); } @@ -1165,9 +1170,15 @@ ofDirectory::ofDirectory(const of::filesystem::path & path){ //------------------------------------------------------------------------------------------------------------ void ofDirectory::open(const of::filesystem::path & path){ - originalDirectory = ofFilePath::getPathForDirectory(path.string()); + using std::cout; + using std::endl; +// originalDirectory = ofFilePath::getPathForDirectory(path.string()); +// cout << "ofDirectory path " << path << endl; +// cout << "ofDirectory originalDirectory " << originalDirectory << endl; + files.clear(); - myDir = of::filesystem::path(ofToDataPath(originalDirectory)); + myDir = of::filesystem::path(ofToDataPath(path)); + cout << "ofDirectory myDir " << myDir << endl; } //------------------------------------------------------------------------------------------------------------ @@ -1185,7 +1196,7 @@ void ofDirectory::close(){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::create(bool recursive){ - if(!myDir.string().empty()){ + if(!myDir.empty()){ try{ if(recursive){ of::filesystem::create_directories(myDir); @@ -1339,12 +1350,40 @@ bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData } //------------------------------------------------------------------------------------------------------------ +using std::cout; +using std::endl; bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ - if(copyTo(path,bRelativeToData,overwrite)){ - return remove(true); + if (of::filesystem::exists(path)) { + cout << "exists " << path << endl; + if (overwrite) { + of::filesystem::remove_all(path); + cout << "remove all " << path << endl; + } + else { + return false; + } } + const of::filesystem::path & old = myDir; +// std::error_code ec; + try { + of::filesystem::rename(old, path); + } catch (of::filesystem::filesystem_error const& ex) { + return false; + } + myDir = path; + return true; - return false; + // error_code 0 means success. any other result will return false; +// std::cout << ec.value() << " " << ec.message() << std::endl; +// if (ec.empty()) { +// } +// return ec.empty(); + +// if(copyTo(path,bRelativeToData,overwrite)){ +// return remove(true); +// } +// +// return false; } //------------------------------------------------------------------------------------------------------------ @@ -1928,6 +1967,7 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ //-------------------------------------------------- //of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ + // if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 if (defaultWorkingDirectory() != of::filesystem::current_path()) { @@ -1939,17 +1979,45 @@ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ } #endif // FIXME: change to direct returns when return type is fs::path +// of::filesystem::path outPath; +// const auto & dataPath = dataPathRoot(); +// if (makeAbsolute) { +//// cout << dataPath << endl; +//// cout << path << endl; +//// cout << (dataPath / path) << endl; +//// outPath = of::filesystem::absolute(dataPath / path); +// if (path.is_absolute()) { +// outPath = path; +// } else { +// outPath = dataPath / path; +// } +// } else { +// if (!path.is_absolute()) { +// auto exeDir = ofFilePath::getCurrentExeDir(); +// outPath = of::filesystem::relative(dataPath / path, ofFilePath::getCurrentExeDir()); +// } else { +// outPath = path; +// } +// } + + using std::cout; + using std::endl; + cout << "path = " << path << endl; + + auto exeDir = ofFilePath::getCurrentExeDir(); + // xaxa of::filesystem::path outPath; - const auto & dataPath = dataPathRoot(); - if (makeAbsolute) { - outPath = dataPath / path; + if (path.is_absolute()) { + cout << "path is already absolute" << endl; + outPath = path; } else { - if (!path.is_absolute()) { - auto exeDir = ofFilePath::getCurrentExeDir(); - outPath = of::filesystem::relative(dataPath / path, ofFilePath::getCurrentExeDir()); - } else { - outPath = path; - } + const auto & dataPath = dataPathRoot(); + outPath = { dataPath / path }; } + if (!makeAbsolute) { + outPath = of::filesystem::relative(outPath, ofFilePath::getCurrentExeDir()); + } + cout << "outpath = " << outPath << endl; + return outPath.string(); } diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index 9f958f07564..8f423eeae1f 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -120,6 +120,8 @@ class ofApp: public ofxUnitTestsApp{ ofxTest(ofDirectory("d1").canExecute(),"ofDirectory::canExecute"); } + std::exit(0); + ofDirectory("noreaddir").create(); ofDirectory("noreaddir").setWriteable(false); ofxTest(ofDirectory("noreaddir").canRead(),"ofDirectory::canRead readonly"); @@ -139,6 +141,9 @@ class ofApp: public ofxUnitTestsApp{ ofxTest(ofFile("d5/f1").isFile(),"ofDirectory::moveTo f1 exists"); ofxTest(ofFile("d5/d3/f2").isFile(),"ofDirectory::moveTo f2 exists"); + + std::exit(0); + ofxTest(ofDirectory("d5").renameTo("d4"),"ofDirectory::renameTo"); ofxTest(ofDirectory("d4").isDirectory(),"ofDirectory::renameTo dir exists"); ofxTest(ofDirectory("d4/d3").isDirectory(),"ofDirectory::renameTo recursive dir exists"); @@ -208,13 +213,16 @@ class ofApp: public ofxUnitTestsApp{ ofLogNotice() << "tests #4299"; ofxTestEq(of::filesystem::path(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); if(ofGetTargetPlatform()==OF_TARGET_OSX){ - ofxTestEq(ofToDataPath("",false),"../../../data/","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false),"../../../data","ofToDataPath relative"); }else if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ - ofxTestEq(ofToDataPath("",false),"data\\","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false),"data","ofToDataPath relative"); }else{ - ofxTestEq(ofToDataPath("",false),"data/","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false),"data","ofToDataPath relative"); } + std::exit(0); + + //======================================================================== ofLogNotice() << ""; From 679f6dded90d6e52a69ca0f244600f71b760bef4 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 12 Mar 2023 20:44:06 -0300 Subject: [PATCH 09/49] more changes --- libs/openFrameworks/gl/ofCubeMap.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libs/openFrameworks/gl/ofCubeMap.cpp b/libs/openFrameworks/gl/ofCubeMap.cpp index 03ad615ccb5..d98e53517d4 100644 --- a/libs/openFrameworks/gl/ofCubeMap.cpp +++ b/libs/openFrameworks/gl/ofCubeMap.cpp @@ -383,7 +383,7 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { // figure out the number of mip maps // data->maxMipLevels = log2(data->settings.preFilterRes) + 1; - of::filesystem::path encFolder = data->settings.cacheDirectory; + of::filesystem::path encFolder { data->settings.cacheDirectory }; if( !encFolder.empty() ) { if( !ofDirectory::doesDirectoryExist( ofFilePath::removeTrailingSlash( data->settings.cacheDirectory ))) { #if !defined(TARGET_OPENGLES) @@ -394,15 +394,11 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { } else { } - // encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ).string(); - // encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ); - } - // TODO: change everything to of::filesystem - of::filesystem::path baseName = ofFilePath::getBaseName( data->settings.filePath ); - of::filesystem::path cacheIrrName = baseName / ("_irr_"+ofToString(data->settings.irradianceRes,0) + ".exr"); - of::filesystem::path cachePrefilterName = baseName / ("_pre_"+ofToString(data->settings.preFilterRes,0)+".exr"); + of::filesystem::path baseName { ofFilePath::getBaseName( data->settings.filePath ) }; + of::filesystem::path cacheIrrName { baseName / ("_irr_"+ofToString(data->settings.irradianceRes,0) + ".exr") }; + of::filesystem::path cachePrefilterName { baseName / ("_pre_"+ofToString(data->settings.preFilterRes,0)+".exr") }; bool bHasCachedIrr = false; bool bHasCachedPre = false; From 59db08dfc44a13a352ca63e5dbe03fcca5c69963 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 14:06:56 -0300 Subject: [PATCH 10/49] tests --- apps/projectGenerator | 2 +- libs/openFrameworks/utils/ofFileUtils.cpp | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/projectGenerator b/apps/projectGenerator index 6bcedfe705e..9fe7054b390 160000 --- a/apps/projectGenerator +++ b/apps/projectGenerator @@ -1 +1 @@ -Subproject commit 6bcedfe705e4bfbbf044c0809a739dd7f62c6116 +Subproject commit 9fe7054b390829381241581cbc3874ed6d5aafbf diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index b9f64db407d..8a68042c830 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -34,11 +34,13 @@ namespace{ // three levels up because is a directory with path App.app/Contents/MacOS/App of::filesystem::path data = ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() / "data"; +// cout << "defaultDataPath() " << data << endl; if (!of::filesystem::is_directory(data)) { // bundle data folder inside app // one level up : MacOS/../Resources/data data = ofFilePath::getCurrentExeDir().parent_path() / "Resources/data"; } + return data; #elif defined TARGET_ANDROID @@ -50,13 +52,18 @@ namespace{ //-------------------------------------------------- of::filesystem::path & defaultWorkingDirectory(){ + cout << "defaultWorkingDirectory()" << endl; static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDir()); return * defaultWorkingDirectory; } //-------------------------------------------------- of::filesystem::path & dataPathRoot(){ + static auto * dataPathRoot = new of::filesystem::path(defaultDataPath()); + cout << "dataPathRoot() internal = " << *dataPathRoot << endl; + of::filesystem::current_path(*dataPathRoot); + return *dataPathRoot; } } @@ -64,7 +71,10 @@ namespace{ namespace of{ namespace priv{ void initfileutils(){ - defaultWorkingDirectory() = of::filesystem::absolute(of::filesystem::current_path()); + cout << "initfileutils" << endl; +// defaultWorkingDirectory() = of::filesystem::absolute(of::filesystem::current_path()); + cout << defaultDataPath() << endl; + defaultWorkingDirectory() = dataPathRoot(); } } } @@ -2002,13 +2012,13 @@ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ using std::cout; using std::endl; - cout << "path = " << path << endl; +// cout << "path = " << path << endl; auto exeDir = ofFilePath::getCurrentExeDir(); // xaxa of::filesystem::path outPath; if (path.is_absolute()) { - cout << "path is already absolute" << endl; +// cout << "path is already absolute" << endl; outPath = path; } else { const auto & dataPath = dataPathRoot(); @@ -2017,7 +2027,7 @@ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ if (!makeAbsolute) { outPath = of::filesystem::relative(outPath, ofFilePath::getCurrentExeDir()); } - cout << "outpath = " << outPath << endl; +// cout << "outpath = " << outPath << endl; return outPath.string(); } From 0a11ede4a72ff69bcd2c0586d612c6dbab673568 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 14:37:49 -0300 Subject: [PATCH 11/49] up --- libs/openFrameworks/utils/ofFileUtils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 8a68042c830..0a1e95233aa 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1977,7 +1977,12 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ //-------------------------------------------------- //of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ - + if (path.is_absolute()) { + return path.string(); + } else { + return (dataPathRoot() / path).string(); + } +// return path.string(); // if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 if (defaultWorkingDirectory() != of::filesystem::current_path()) { From 90f344db46bcada37644a8f09995c8c72404d836 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 15:00:19 -0300 Subject: [PATCH 12/49] changedir to data --- libs/openFrameworks/utils/ofFileUtils.cpp | 21 +++++++++++++-------- tests/utils/fileUtils/src/main.cpp | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 0a1e95233aa..329fcedfaf6 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -52,7 +52,7 @@ namespace{ //-------------------------------------------------- of::filesystem::path & defaultWorkingDirectory(){ - cout << "defaultWorkingDirectory()" << endl; +// cout << "defaultWorkingDirectory()" << endl; static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDir()); return * defaultWorkingDirectory; } @@ -61,7 +61,7 @@ namespace{ of::filesystem::path & dataPathRoot(){ static auto * dataPathRoot = new of::filesystem::path(defaultDataPath()); - cout << "dataPathRoot() internal = " << *dataPathRoot << endl; +// cout << "" << endl; of::filesystem::current_path(*dataPathRoot); return *dataPathRoot; @@ -71,9 +71,9 @@ namespace{ namespace of{ namespace priv{ void initfileutils(){ - cout << "initfileutils" << endl; +// cout << "initfileutils :: " << dataPathRoot() << endl; // defaultWorkingDirectory() = of::filesystem::absolute(of::filesystem::current_path()); - cout << defaultDataPath() << endl; +// cout << defaultDataPath() << endl; defaultWorkingDirectory() = dataPathRoot(); } } @@ -572,8 +572,8 @@ bool ofFile::openStream(Mode _mode, bool _binary){ bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); myFile = ofToDataPath(_path, true); - cout << "offile::open=" << _path << endl; - cout << "myFile=" << myFile << endl; +// cout << "offile::open=" << _path << endl; +// cout << "myFile=" << myFile << endl; return openStream(_mode, binary); } @@ -1187,8 +1187,13 @@ void ofDirectory::open(const of::filesystem::path & path){ // cout << "ofDirectory originalDirectory " << originalDirectory << endl; files.clear(); - myDir = of::filesystem::path(ofToDataPath(path)); - cout << "ofDirectory myDir " << myDir << endl; + + myDir = of::filesystem::path(ofToDataPath(path)).lexically_normal(); +// cout << "ofDirectory " << path << endl; +// cout << of::filesystem::path(ofToDataPath(path)) << endl; +// cout << "lexically normal " << myDir << endl; +// cout << "----" << endl; + } //------------------------------------------------------------------------------------------------------------ diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index 8f423eeae1f..1d740d6ac60 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -120,7 +120,7 @@ class ofApp: public ofxUnitTestsApp{ ofxTest(ofDirectory("d1").canExecute(),"ofDirectory::canExecute"); } - std::exit(0); +// std::exit(0); ofDirectory("noreaddir").create(); ofDirectory("noreaddir").setWriteable(false); From 1a69450babe7865da72a1250f88f5104471a4a34 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 15:02:18 -0300 Subject: [PATCH 13/49] no windows check anymore --- libs/openFrameworks/utils/ofFileUtils.cpp | 59 ++++------------------- 1 file changed, 9 insertions(+), 50 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 329fcedfaf6..89aa4d00db5 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1987,57 +1987,16 @@ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ } else { return (dataPathRoot() / path).string(); } -// return path.string(); -// if our Current Working Directory has changed (e.g. file open dialog) -#ifdef TARGET_WIN32 - 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 - // FIXME: change to direct returns when return type is fs::path -// of::filesystem::path outPath; -// const auto & dataPath = dataPathRoot(); -// if (makeAbsolute) { -//// cout << dataPath << endl; -//// cout << path << endl; -//// cout << (dataPath / path) << endl; -//// outPath = of::filesystem::absolute(dataPath / path); -// if (path.is_absolute()) { -// outPath = path; -// } else { -// outPath = dataPath / path; -// } -// } else { -// if (!path.is_absolute()) { -// auto exeDir = ofFilePath::getCurrentExeDir(); -// outPath = of::filesystem::relative(dataPath / path, ofFilePath::getCurrentExeDir()); -// } else { -// outPath = path; + +//// if our Current Working Directory has changed (e.g. file open dialog) +//#ifdef TARGET_WIN32 +// 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(); // } // } - - using std::cout; - using std::endl; -// cout << "path = " << path << endl; - - auto exeDir = ofFilePath::getCurrentExeDir(); - // xaxa - of::filesystem::path outPath; - if (path.is_absolute()) { -// cout << "path is already absolute" << endl; - outPath = path; - } else { - const auto & dataPath = dataPathRoot(); - outPath = { dataPath / path }; - } - if (!makeAbsolute) { - outPath = of::filesystem::relative(outPath, ofFilePath::getCurrentExeDir()); - } -// cout << "outpath = " << outPath << endl; +//#endif - return outPath.string(); } From 026663d64ab154e1c2b06bbbaa82d795a53d1d5e Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 15:26:51 -0300 Subject: [PATCH 14/49] data folder missing in this test --- tests/utils/fileUtils/bin/data/.gitkeep | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/utils/fileUtils/bin/data/.gitkeep diff --git a/tests/utils/fileUtils/bin/data/.gitkeep b/tests/utils/fileUtils/bin/data/.gitkeep new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/utils/fileUtils/bin/data/.gitkeep @@ -0,0 +1 @@ + From b9e62990846f99f899e55a700e636b1044bb82dc Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 15:43:57 -0300 Subject: [PATCH 15/49] missing xm data folder --- tests/utils/xml/bin/data/.gitkeep | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/utils/xml/bin/data/.gitkeep diff --git a/tests/utils/xml/bin/data/.gitkeep b/tests/utils/xml/bin/data/.gitkeep new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/utils/xml/bin/data/.gitkeep @@ -0,0 +1 @@ + From 7badb5fde7fb2d8bedf665477cb95c0028f16193 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 16:16:57 -0300 Subject: [PATCH 16/49] cubemap in separate pr --- libs/openFrameworks/gl/ofCubeMap.cpp | 31 ++++++++++++++-------------- libs/openFrameworks/gl/ofCubeMap.h | 8 +++---- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/libs/openFrameworks/gl/ofCubeMap.cpp b/libs/openFrameworks/gl/ofCubeMap.cpp index d98e53517d4..df36e282593 100644 --- a/libs/openFrameworks/gl/ofCubeMap.cpp +++ b/libs/openFrameworks/gl/ofCubeMap.cpp @@ -383,29 +383,30 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { // figure out the number of mip maps // data->maxMipLevels = log2(data->settings.preFilterRes) + 1; - of::filesystem::path encFolder { data->settings.cacheDirectory }; + std::string encFolder = data->settings.cacheDirectory; if( !encFolder.empty() ) { if( !ofDirectory::doesDirectoryExist( ofFilePath::removeTrailingSlash( data->settings.cacheDirectory ))) { -#if !defined(TARGET_OPENGLES) + #if !defined(TARGET_OPENGLES) if(!ofDirectory::createDirectory( data->settings.cacheDirectory )) { ofLogWarning("ofCubeMap :: load : unable to create directory: ") << data->settings.cacheDirectory; } -#endif + #endif } else { } + // encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ).string(); + encFolder = ofFilePath::addTrailingSlash( data->settings.cacheDirectory ); } - - of::filesystem::path baseName { ofFilePath::getBaseName( data->settings.filePath ) }; - of::filesystem::path cacheIrrName { baseName / ("_irr_"+ofToString(data->settings.irradianceRes,0) + ".exr") }; - of::filesystem::path cachePrefilterName { baseName / ("_pre_"+ofToString(data->settings.preFilterRes,0)+".exr") }; + std::string baseName = ofFilePath::getBaseName( data->settings.filePath ); + std::string cacheIrrName = baseName+"_irr_"+ofToString(data->settings.irradianceRes,0)+".exr"; + std::string cachePrefilterName = baseName+"_pre_"+ofToString(data->settings.preFilterRes,0)+".exr"; bool bHasCachedIrr = false; bool bHasCachedPre = false; if( data->settings.useCache && !data->settings.overwriteCache ) { - bHasCachedIrr = _loadIrradianceMap(encFolder / cacheIrrName); + bHasCachedIrr = _loadIrradianceMap(encFolder+cacheIrrName); ofLogVerbose("ofCubeMap :: _loadIrradianceMap: ") << bHasCachedIrr; - bHasCachedPre = _loadPrefilterMap(encFolder / cachePrefilterName); + bHasCachedPre = _loadPrefilterMap(encFolder+cachePrefilterName); ofLogVerbose("ofCubeMap :: _loadPrefilterMap: ") << bHasCachedPre; } @@ -417,12 +418,12 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { if( !bHasCachedIrr ) { ofLogVerbose("ofCubeMap :: going to create irradiance map"); - _createIrradianceMap(cubeFid,bMakeCache, encFolder / cacheIrrName); + _createIrradianceMap(cubeFid,bMakeCache, encFolder+cacheIrrName); } if( !bHasCachedPre ) { ofLogVerbose("ofCubeMap :: going to create pre filtered cube map"); - _createPrefilteredCubeMap(cubeFid, srcCubeFSize,bMakeCache,encFolder / cachePrefilterName ); + _createPrefilteredCubeMap(cubeFid, srcCubeFSize,bMakeCache,encFolder+cachePrefilterName ); } glDeleteTextures(1, &cubeFid ); @@ -736,7 +737,7 @@ void ofCubeMap::_equiRectToCubeMap( GLuint& aCubeTexId, ofTexture& aSrcTex, int } //-------------------------------------------------------------- -void ofCubeMap::_createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, of::filesystem::path aCachePath) { +void ofCubeMap::_createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, std::string aCachePath) { if(data->bIrradianceAllocated) { return; } @@ -877,7 +878,7 @@ void ofCubeMap::_createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, of::f } //-------------------------------------------------------------- -bool ofCubeMap::_loadIrradianceMap(of::filesystem::path aCachePath) { +bool ofCubeMap::_loadIrradianceMap(std::string aCachePath) { if(data->bIrradianceAllocated) { return false; @@ -936,7 +937,7 @@ bool ofCubeMap::_loadIrradianceMap(of::filesystem::path aCachePath) { } //-------------------------------------------------------------- -void ofCubeMap::_createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, of::filesystem::path aCachePath) { +void ofCubeMap::_createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, std::string aCachePath) { if(data->bPreFilteredMapAllocated) { return; } @@ -1094,7 +1095,7 @@ void ofCubeMap::_createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool } //-------------------------------------------------------------- -bool ofCubeMap::_loadPrefilterMap( of::filesystem::path aCachePath ) { +bool ofCubeMap::_loadPrefilterMap( std::string aCachePath ) { if(data->bPreFilteredMapAllocated) { return false; } diff --git a/libs/openFrameworks/gl/ofCubeMap.h b/libs/openFrameworks/gl/ofCubeMap.h index 15e57399af7..30dd03e1bca 100644 --- a/libs/openFrameworks/gl/ofCubeMap.h +++ b/libs/openFrameworks/gl/ofCubeMap.h @@ -125,11 +125,11 @@ class ofCubeMap { GLuint _createFloatCubeMap(ofTexture& aSrcTex, int aSrcRes); void _equiRectToCubeMap( GLuint& aCubeTexId, ofTexture& aSrcTex, int aSrcRes, bool aBConvertToNonFloat ); - void _createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, of::filesystem::path aCachePath); - bool _loadIrradianceMap( of::filesystem::path aCachePath ); + void _createIrradianceMap(GLuint aSrcCubeFid, bool aBMakeCache, std::string aCachePath); + bool _loadIrradianceMap(std::string aCachePath); - void _createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, of::filesystem::path aCachePath); - bool _loadPrefilterMap( of::filesystem::path aCachePath ); + void _createPrefilteredCubeMap(GLuint aSrcCubeFid, int aSrcRes, bool aBMakeCache, std::string aCachePath); + bool _loadPrefilterMap( std::string aCachePath ); static void _createBrdfLUT(); From ed78257f0453878abbd5aaa754f46fa17b087f03 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 16:19:50 -0300 Subject: [PATCH 17/49] more changes --- libs/openFrameworks/utils/ofFileUtils.cpp | 24 ++--------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 89aa4d00db5..f3307e24c34 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -34,13 +34,11 @@ namespace{ // three levels up because is a directory with path App.app/Contents/MacOS/App of::filesystem::path data = ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() / "data"; -// cout << "defaultDataPath() " << data << endl; if (!of::filesystem::is_directory(data)) { // bundle data folder inside app // one level up : MacOS/../Resources/data data = ofFilePath::getCurrentExeDir().parent_path() / "Resources/data"; } - return data; #elif defined TARGET_ANDROID @@ -52,18 +50,15 @@ namespace{ //-------------------------------------------------- of::filesystem::path & defaultWorkingDirectory(){ -// cout << "defaultWorkingDirectory()" << endl; static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDir()); return * defaultWorkingDirectory; } //-------------------------------------------------- of::filesystem::path & dataPathRoot(){ - static auto * dataPathRoot = new of::filesystem::path(defaultDataPath()); -// cout << "" << endl; + // This is the most important change in the way OF handles paths. of::filesystem::current_path(*dataPathRoot); - return *dataPathRoot; } } @@ -71,9 +66,6 @@ namespace{ namespace of{ namespace priv{ void initfileutils(){ -// cout << "initfileutils :: " << dataPathRoot() << endl; -// defaultWorkingDirectory() = of::filesystem::absolute(of::filesystem::current_path()); -// cout << defaultDataPath() << endl; defaultWorkingDirectory() = dataPathRoot(); } } @@ -1180,25 +1172,13 @@ ofDirectory::ofDirectory(const of::filesystem::path & path){ //------------------------------------------------------------------------------------------------------------ void ofDirectory::open(const of::filesystem::path & path){ - using std::cout; - using std::endl; -// originalDirectory = ofFilePath::getPathForDirectory(path.string()); -// cout << "ofDirectory path " << path << endl; -// cout << "ofDirectory originalDirectory " << originalDirectory << endl; - files.clear(); - myDir = of::filesystem::path(ofToDataPath(path)).lexically_normal(); -// cout << "ofDirectory " << path << endl; -// cout << of::filesystem::path(ofToDataPath(path)) << endl; -// cout << "lexically normal " << myDir << endl; -// cout << "----" << endl; - } //------------------------------------------------------------------------------------------------------------ void ofDirectory::openFromCWD(const of::filesystem::path & path){ - originalDirectory = ofFilePath::getPathForDirectory(path.string()); + originalDirectory = ofFilePath::getPathForDirectory(path); files.clear(); myDir = of::filesystem::path(originalDirectory); } From 7249c124ac8a3112b8512da6ee34c7a69dede680 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 16:20:59 -0300 Subject: [PATCH 18/49] changes --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index f3307e24c34..c54a6ce8f4a 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -564,8 +564,6 @@ bool ofFile::openStream(Mode _mode, bool _binary){ bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); myFile = ofToDataPath(_path, true); -// cout << "offile::open=" << _path << endl; -// cout << "myFile=" << myFile << endl; return openStream(_mode, binary); } From c87c96737a51019927a4e16ab667420124a37a4f Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 16:23:56 -0300 Subject: [PATCH 19/49] ok --- libs/openFrameworks/utils/ofFileUtils.cpp | 15 --------------- libs/openFrameworks/utils/ofFileUtils.h | 1 - 2 files changed, 16 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index c54a6ce8f4a..beb64762584 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1343,8 +1343,6 @@ bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData } //------------------------------------------------------------------------------------------------------------ -using std::cout; -using std::endl; bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ if (of::filesystem::exists(path)) { cout << "exists " << path << endl; @@ -1357,7 +1355,6 @@ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, } } const of::filesystem::path & old = myDir; -// std::error_code ec; try { of::filesystem::rename(old, path); } catch (of::filesystem::filesystem_error const& ex) { @@ -1365,18 +1362,6 @@ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, } myDir = path; return true; - - // error_code 0 means success. any other result will return false; -// std::cout << ec.value() << " " << ec.message() << std::endl; -// if (ec.empty()) { -// } -// return ec.empty(); - -// if(copyTo(path,bRelativeToData,overwrite)){ -// return remove(true); -// } -// -// return false; } //------------------------------------------------------------------------------------------------------------ diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 634a0f06fad..46a8ffe0fe2 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -315,7 +315,6 @@ class ofFilePath{ /// /// \param path directory path /// \returns path + slash -// MARK: - remove after fs transition static std::string addTrailingSlash(const of::filesystem::path& path); /// Remove a path's trailing slash (if found), From e6f7815fe5ff453b74db0fd6226dab783d68c56a Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 16:24:22 -0300 Subject: [PATCH 20/49] ok --- libs/openFrameworks/utils/ofFileUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index beb64762584..893fa867741 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -22,6 +22,7 @@ using std::istream; using std::ostream; using std::ios; +// FIXME: remove this temporary using using std::cout; using std::endl; From 642bd805e3c0d424a418370ec2cb21f3b42a4fb1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 16:53:27 -0300 Subject: [PATCH 21/49] offile open relative --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 893fa867741..07794bc1421 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -564,7 +564,7 @@ bool ofFile::openStream(Mode _mode, bool _binary){ //------------------------------------------------------------------------------------------------------------ bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); - myFile = ofToDataPath(_path, true); + myFile = ofToDataPath(_path); return openStream(_mode, binary); } From bef7d34f8db7865fb0f850e01c3b87dc30f4b2f7 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 17:22:07 -0300 Subject: [PATCH 22/49] update relative paths if needed. --- libs/openFrameworks/utils/ofFileUtils.cpp | 18 +++++++++++++++--- libs/openFrameworks/utils/ofFileUtils.h | 2 -- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 07794bc1421..f3740771359 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1944,14 +1944,26 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ } //-------------------------------------------------- -//of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ + + of::filesystem::path outPath { path }; if (path.is_absolute()) { - return path.string(); + if (makeAbsolute) { + // nothing needed here. outPath is already path + } else { + auto current = of::filesystem::current_path(); + outPath = of::filesystem::relative(path, current); + } } else { - return (dataPathRoot() / path).string(); + if (makeAbsolute) { + outPath = dataPathRoot() / path; + } else { + auto current = of::filesystem::current_path(); + outPath = of::filesystem::relative(dataPathRoot() / path, current); + } } + return outPath.string(); //// if our Current Working Directory has changed (e.g. file open dialog) //#ifdef TARGET_WIN32 // if (defaultWorkingDirectory() != of::filesystem::current_path()) { diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 46a8ffe0fe2..c1be76b2288 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -1224,8 +1224,6 @@ 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(). -// 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. From f7225557f9421a633e479d8df6c4bc0ffbb6405b Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 17:57:31 -0300 Subject: [PATCH 23/49] more cleanup --- libs/openFrameworks/utils/ofFileUtils.cpp | 33 +++++------------------ 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index f3740771359..296994b745b 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -22,10 +22,6 @@ using std::istream; using std::ostream; using std::ios; -// FIXME: remove this temporary using -using std::cout; -using std::endl; - namespace{ bool enableDataPath = true; @@ -36,8 +32,7 @@ namespace{ // three levels up because is a directory with path App.app/Contents/MacOS/App of::filesystem::path data = ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() / "data"; if (!of::filesystem::is_directory(data)) { - // bundle data folder inside app - // one level up : MacOS/../Resources/data + // bundle data folder inside app = one level up : MacOS/../Resources/data data = ofFilePath::getCurrentExeDir().parent_path() / "Resources/data"; } return data; @@ -1346,12 +1341,11 @@ bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData //------------------------------------------------------------------------------------------------------------ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ if (of::filesystem::exists(path)) { - cout << "exists " << path << endl; if (overwrite) { of::filesystem::remove_all(path); - cout << "remove all " << path << endl; } else { + ofLogError("ofDirectory") << "moveTo(): destination folder exists, overwrite = false " << endl; return false; } } @@ -1359,6 +1353,7 @@ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, try { of::filesystem::rename(old, path); } catch (of::filesystem::filesystem_error const& ex) { + ofLogError("ofDirectory") << "moveTo(): can't rename folder " << ex.code().message() << endl; return false; } myDir = path; @@ -1779,21 +1774,18 @@ string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRela } //------------------------------------------------------------------------------------------------------------ +// FIXME: is this still useful? string ofFilePath::getBaseName(const of::filesystem::path& filePath){ - // FIXME: is this still useful? return ofFile(filePath,ofFile::Reference).getBaseName(); } //------------------------------------------------------------------------------------------------------------ -// MARK: - near future -//of::filesystem::path ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ +// FIXME: - near future std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ auto fp = _filePath; if(bRelativeToData){ fp = ofToDataPath(fp); } - -// return addTrailingSlash(fp.parent_path()); return fp.parent_path().string(); } @@ -1804,16 +1796,13 @@ bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, //------------------------------------------------------------------------------------------------------------ // 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 of::filesystem::canonical(of::filesystem::absolute(path)); return of::filesystem::canonical(of::filesystem::absolute(path)).string(); }catch(...){ -// return of::filesystem::absolute(path); return of::filesystem::absolute(path).string(); } } @@ -1830,13 +1819,8 @@ string ofFilePath::getCurrentWorkingDirectory(){ } //------------------------------------------------------------------------------------------------------------ -// 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); -//} +// FIXME: deprecate when possible. helper function more complex than actual solution 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(); } @@ -1892,8 +1876,7 @@ string ofFilePath::getUserHomeDir(){ #endif } -// MARK: - near future -//of::filesystem::path ofFilePath::makeRelative(const of::filesystem::path & from, const of::filesystem::path & to){ +// FIXME: - deprecate 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 ); @@ -1913,8 +1896,6 @@ std::string ofFilePath::makeRelative(const of::filesystem::path & from, const of ret /= *itrTo; } } - -// return ret; return ret.string(); } From 15d7d91d7ca6b8f0eb020abd105a41288e51f2c1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 18:01:46 -0300 Subject: [PATCH 24/49] cout::endl fix --- libs/openFrameworks/utils/ofFileUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 296994b745b..4d33246df9c 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1345,7 +1345,7 @@ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, of::filesystem::remove_all(path); } else { - ofLogError("ofDirectory") << "moveTo(): destination folder exists, overwrite = false " << endl; + ofLogError("ofDirectory") << "moveTo(): destination folder exists, overwrite = false " << std::endl; return false; } } @@ -1353,7 +1353,7 @@ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, try { of::filesystem::rename(old, path); } catch (of::filesystem::filesystem_error const& ex) { - ofLogError("ofDirectory") << "moveTo(): can't rename folder " << ex.code().message() << endl; + ofLogError("ofDirectory") << "moveTo(): can't rename folder " << ex.code().message() << std::endl; return false; } myDir = path; From fdba45bae3443612f91384d0ac66eb1b88bd929d Mon Sep 17 00:00:00 2001 From: Dimitre Date: Wed, 15 Mar 2023 20:24:14 -0300 Subject: [PATCH 25/49] more cleanup --- libs/openFrameworks/utils/ofFileUtils.cpp | 50 ++++++++--------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 4d33246df9c..5930d167566 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1679,6 +1679,7 @@ vector::const_reverse_iterator ofDirectory::rend() const{ //------------------------------------------------------------------------------------------------------------ +// FIXME: - Deprecate string ofFilePath::addLeadingSlash(const of::filesystem::path& _path){ auto path = _path.string(); auto sep = of::filesystem::path("/").make_preferred(); @@ -1691,12 +1692,10 @@ string ofFilePath::addLeadingSlash(const of::filesystem::path& _path){ } //------------------------------------------------------------------------------------------------------------ -// MARK: - Remove this function after FS transition +// FIXME: - Deprecate std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ #if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS 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 = of::filesystem::path(_path).make_preferred(); @@ -1706,21 +1705,19 @@ std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ path = (path / sep); } } -// return path; return path.string(); #endif } //------------------------------------------------------------------------------------------------------------ +// FIXME: - Deprecate string ofFilePath::getFileExt(const of::filesystem::path& filename){ return ofFile(filename,ofFile::Reference).getExtension(); } //------------------------------------------------------------------------------------------------------------ -// FIXME: remove const and copy -// MARK: - near future -// of::filesystem::path ofFilePath::removeExt(const of::filesystem::path& _filename){ +// FIXME: Deprecate std::string ofFilePath::removeExt(const of::filesystem::path& _filename){ auto filename = _filename; // return filename.replace_extension(); @@ -1728,6 +1725,7 @@ std::string ofFilePath::removeExt(const of::filesystem::path& _filename){ } //------------------------------------------------------------------------------------------------------------ +// FIXME: Deprecate 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 "\" @@ -1750,7 +1748,7 @@ string ofFilePath::getPathForDirectory(const of::filesystem::path& path){ } //------------------------------------------------------------------------------------------------------------ -// FIXME: convert to of::filesystem::path +// FIXME: Deprecate string ofFilePath::removeTrailingSlash(const of::filesystem::path& _path){ auto path = _path.string(); if(path.length() > 0 && (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')){ @@ -1761,7 +1759,7 @@ string ofFilePath::removeTrailingSlash(const of::filesystem::path& _path){ //------------------------------------------------------------------------------------------------------------ -// FIXME: is this still useful? if yes convert to of::filesystem::path +// FIXME: Deprecate string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRelativeToData){ auto filePath = _filePath; @@ -1774,13 +1772,13 @@ string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRela } //------------------------------------------------------------------------------------------------------------ -// FIXME: is this still useful? +// FIXME: Deprecate string ofFilePath::getBaseName(const of::filesystem::path& filePath){ return ofFile(filePath,ofFile::Reference).getBaseName(); } //------------------------------------------------------------------------------------------------------------ -// FIXME: - near future +// FIXME: Is this useful? if not deprecate std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ auto fp = _filePath; if(bRelativeToData){ @@ -1795,7 +1793,7 @@ bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, } //------------------------------------------------------------------------------------------------------------ -// FIXME: - near future +// FIXME: Is this useful? if not deprecate std::string ofFilePath::getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData){ if(bRelativeToData){ return ofToDataPath(path, true); @@ -1809,17 +1807,19 @@ std::string ofFilePath::getAbsolutePath(const of::filesystem::path& path, bool b } //------------------------------------------------------------------------------------------------------------ +// FIXME: Deprecate bool ofFilePath::isAbsolute(const of::filesystem::path& path){ return of::filesystem::path(path).is_absolute(); } //------------------------------------------------------------------------------------------------------------ +// FIXME: Deprecate string ofFilePath::getCurrentWorkingDirectory(){ return of::filesystem::current_path().string(); } //------------------------------------------------------------------------------------------------------------ -// FIXME: deprecate when possible. helper function more complex than actual solution +// FIXME: Deprecate helper function more complex than actual solution std::string ofFilePath::join(const of::filesystem::path& path1, const of::filesystem::path& path2){ return (path1 / path2).string(); } @@ -1856,6 +1856,7 @@ string ofFilePath::getCurrentExePath(){ } //------------------------------------------------------------------------------------------------------------ +// Can be changed to be unneeded in near future of::filesystem::path ofFilePath::getCurrentExeDir(){ auto exePath = of::filesystem::path(getCurrentExePath()); return exePath.parent_path(); @@ -1876,27 +1877,10 @@ string ofFilePath::getUserHomeDir(){ #endif } +//-------------------------------------------------- // FIXME: - deprecate 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( 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( of::filesystem::path::const_iterator fromEnd( pathFrom.end() ); itrFrom != fromEnd; ++itrFrom ){ - if( (*itrFrom) != "." ){ - ret /= ".."; - } - } - // Now navigate down the directory branch - for( ; itrTo != pathTo.end() ; ++itrTo ){ - if( itrTo->string() != "."){ - ret /= *itrTo; - } - } - return ret.string(); + return of::filesystem::relative (to, from).string(); } //-------------------------------------------------- @@ -1926,7 +1910,6 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ //-------------------------------------------------- std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ - of::filesystem::path outPath { path }; if (path.is_absolute()) { if (makeAbsolute) { @@ -1955,5 +1938,4 @@ std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ // } // } //#endif - } From b5e8112b3914f3f86279644ac64c9bdbbaf0098f Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 17 Apr 2023 11:25:05 -0300 Subject: [PATCH 26/49] getCurrentExePathFS, fs namespace --- apps/projectGenerator | 2 +- libs/openFrameworks/utils/ofFileUtils.cpp | 354 +++++++++++----------- libs/openFrameworks/utils/ofFileUtils.h | 1 + 3 files changed, 182 insertions(+), 175 deletions(-) diff --git a/apps/projectGenerator b/apps/projectGenerator index 9fe7054b390..007fe56c2a9 160000 --- a/apps/projectGenerator +++ b/apps/projectGenerator @@ -1 +1 @@ -Subproject commit 9fe7054b390829381241581cbc3874ed6d5aafbf +Subproject commit 007fe56c2a90c946e2e4e2851f72ce07fbfc0500 diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 5930d167566..94ad917bbf4 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -22,16 +22,18 @@ using std::istream; using std::ostream; using std::ios; +namespace fs = of::filesystem; + namespace{ bool enableDataPath = true; //-------------------------------------------------- - of::filesystem::path defaultDataPath(){ + fs::path defaultDataPath(){ #if defined TARGET_OSX // three levels up because is a directory with path App.app/Contents/MacOS/App - of::filesystem::path data = ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() / "data"; - if (!of::filesystem::is_directory(data)) { + fs::path data { ofFilePath::getCurrentExeDir().parent_path().parent_path().parent_path() / "data" }; + if (!fs::is_directory(data)) { // bundle data folder inside app = one level up : MacOS/../Resources/data data = ofFilePath::getCurrentExeDir().parent_path() / "Resources/data"; } @@ -40,21 +42,21 @@ namespace{ #elif defined TARGET_ANDROID return { "sdcard/" }; #else - return (ofFilePath::getCurrentExeDir() / "data"); + return ofFilePath::getCurrentExeDir() / "data"; #endif } //-------------------------------------------------- - of::filesystem::path & defaultWorkingDirectory(){ - static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDir()); + fs::path & defaultWorkingDirectory(){ + static auto * defaultWorkingDirectory = new fs::path(ofFilePath::getCurrentExeDir()); return * defaultWorkingDirectory; } //-------------------------------------------------- - of::filesystem::path & dataPathRoot(){ - static auto * dataPathRoot = new of::filesystem::path(defaultDataPath()); + fs::path & dataPathRoot(){ + static auto * dataPathRoot = new fs::path(defaultDataPath()); // This is the most important change in the way OF handles paths. - of::filesystem::current_path(*dataPathRoot); + fs::current_path(*dataPathRoot); return *dataPathRoot; } } @@ -452,13 +454,13 @@ istream & operator>>(istream & istr, ofBuffer & buf){ } //-------------------------------------------------- -ofBuffer ofBufferFromFile(const of::filesystem::path & path, bool binary){ +ofBuffer ofBufferFromFile(const fs::path & path, bool binary){ ofFile f(path,ofFile::ReadOnly, binary); return ofBuffer(f); } //-------------------------------------------------- -bool ofBufferToFile(const of::filesystem::path & path, const ofBuffer& buffer, bool binary){ +bool ofBufferToFile(const fs::path & path, const ofBuffer& buffer, bool binary){ ofFile f(path, ofFile::WriteOnly, binary); return buffer.writeTo(f); } @@ -475,7 +477,7 @@ ofFile::ofFile() ,binary(true){ } -ofFile::ofFile(const of::filesystem::path & path, Mode mode, bool binary) +ofFile::ofFile(const fs::path & path, Mode mode, bool binary) :mode(mode) ,binary(true){ open(path, mode, binary); @@ -557,14 +559,14 @@ bool ofFile::openStream(Mode _mode, bool _binary){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ +bool ofFile::open(const fs::path & _path, Mode _mode, bool binary){ close(); myFile = ofToDataPath(_path); return openStream(_mode, binary); } //------------------------------------------------------------------------------------------------------------ -bool ofFile::openFromCWD(const of::filesystem::path & _path, Mode _mode, bool binary){ +bool ofFile::openFromCWD(const fs::path & _path, Mode _mode, bool binary){ close(); myFile = _path; return openStream(_mode, binary); @@ -590,7 +592,7 @@ bool ofFile::isWriteMode(){ //------------------------------------------------------------------------------------------------------------- void ofFile::close(){ - myFile = of::filesystem::path(); + myFile = fs::path(); if(mode!=Reference) fstream::close(); } @@ -600,7 +602,7 @@ bool ofFile::create(){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::create(const of::filesystem::path & path){ +bool ofFile::create(const fs::path & path){ bool success = false; auto oldmode = this->mode; @@ -617,7 +619,7 @@ bool ofFile::create(const of::filesystem::path & path){ //------------------------------------------------------------------------------------------------------------ ofBuffer ofFile::readToBuffer(){ - if(myFile.string().empty() || !of::filesystem::exists(myFile)){ + if(myFile.string().empty() || !fs::exists(myFile)){ return ofBuffer(); } @@ -645,12 +647,12 @@ bool ofFile::exists() const { if(path().empty()){ return false; } - return of::filesystem::exists(myFile); + return fs::exists(myFile); } //------------------------------------------------------------------------------------------------------------ // MARK: - near future -//of::filesystem::path ofFile::path() const { +//fs::path ofFile::path() const { //return myFile; std::string ofFile::path() const { return myFile.string(); @@ -679,21 +681,21 @@ string ofFile::getBaseName() const { //------------------------------------------------------------------------------------------------------------ // MARK: - near future -//of::filesystem::path ofFile::getEnclosingDirectory() const { +//fs::path ofFile::getEnclosingDirectory() const { std::string ofFile::getEnclosingDirectory() const { return ofFilePath::getEnclosingDirectory(path()); } //------------------------------------------------------------------------------------------------------------ // MARK: - near future -//of::filesystem::path ofFile::getAbsolutePath() const { +//fs::path ofFile::getAbsolutePath() const { std::string ofFile::getAbsolutePath() const { return ofFilePath::getAbsolutePath(path()); } //------------------------------------------------------------------------------------------------------------ bool ofFile::canRead() const { - auto perm = of::filesystem::status(myFile).permissions(); + auto perm = fs::status(myFile).permissions(); #ifdef TARGET_WIN32 DWORD attr = GetFileAttributes(myFile.native().c_str()); if (attr == INVALID_FILE_ATTRIBUTES) @@ -706,19 +708,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 & of::filesystem::perms::owner_read) != of::filesystem::perms::none; + return (perm & fs::perms::owner_read) != fs::perms::none; }else if (getegid() == info.st_gid){ - return (perm & of::filesystem::perms::group_read) != of::filesystem::perms::none; + return (perm & fs::perms::group_read) != fs::perms::none; }else{ - return (perm & of::filesystem::perms::others_read) != of::filesystem::perms::none; + return (perm & fs::perms::others_read) != fs::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & of::filesystem::perms::owner_read; + return perm & fs::perms::owner_read; }else if (getegid() == info.st_gid){ - return perm & of::filesystem::perms::group_read; + return perm & fs::perms::group_read; }else{ - return perm & of::filesystem::perms::others_read; + return perm & fs::perms::others_read; } #endif #endif @@ -726,7 +728,7 @@ bool ofFile::canRead() const { //------------------------------------------------------------------------------------------------------------ bool ofFile::canWrite() const { - auto perm = of::filesystem::status(myFile).permissions(); + auto perm = fs::status(myFile).permissions(); #ifdef TARGET_WIN32 DWORD attr = GetFileAttributes(myFile.native().c_str()); if (attr == INVALID_FILE_ATTRIBUTES){ @@ -739,19 +741,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 & of::filesystem::perms::owner_write) != of::filesystem::perms::none; + return (perm & fs::perms::owner_write) != fs::perms::none; }else if (getegid() == info.st_gid){ - return (perm & of::filesystem::perms::group_write) != of::filesystem::perms::none; + return (perm & fs::perms::group_write) != fs::perms::none; }else{ - return (perm & of::filesystem::perms::others_write) != of::filesystem::perms::none; + return (perm & fs::perms::others_write) != fs::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & of::filesystem::owner_write; + return perm & fs::owner_write; }else if (getegid() == info.st_gid){ - return perm & of::filesystem::group_write; + return perm & fs::group_write; }else{ - return perm & of::filesystem::others_write; + return perm & fs::others_write; } #endif #endif @@ -759,7 +761,7 @@ bool ofFile::canWrite() const { //------------------------------------------------------------------------------------------------------------ bool ofFile::canExecute() const { - auto perm = of::filesystem::status(myFile).permissions(); + auto perm = fs::status(myFile).permissions(); #ifdef TARGET_WIN32 return getExtension() == "exe"; #else @@ -767,36 +769,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 & of::filesystem::perms::owner_exec) != of::filesystem::perms::none; + return (perm & fs::perms::owner_exec) != fs::perms::none; }else if (getegid() == info.st_gid){ - return (perm & of::filesystem::perms::group_exec) != of::filesystem::perms::none; + return (perm & fs::perms::group_exec) != fs::perms::none; }else{ - return (perm & of::filesystem::perms::others_exec) != of::filesystem::perms::none; + return (perm & fs::perms::others_exec) != fs::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & of::filesystem::owner_exe; + return perm & fs::owner_exe; }else if (getegid() == info.st_gid){ - return perm & of::filesystem::group_exe; + return perm & fs::group_exe; }else{ - return perm & of::filesystem::others_exe; + return perm & fs::others_exe; } #endif #endif } //------------------------------------------------------------------------------------------------------------ bool ofFile::isFile() const { - return of::filesystem::is_regular_file(myFile); + return fs::is_regular_file(myFile); } //------------------------------------------------------------------------------------------------------------ bool ofFile::isLink() const { - return of::filesystem::is_symlink(myFile); + return fs::is_symlink(myFile); } //------------------------------------------------------------------------------------------------------------ bool ofFile::isDirectory() const { - return of::filesystem::is_directory(myFile); + return fs::is_directory(myFile); } //------------------------------------------------------------------------------------------------------------ @@ -805,9 +807,9 @@ bool ofFile::isDevice() const { return false; #else #if OF_USING_STD_FS - return of::filesystem::is_block_file(of::filesystem::status(myFile)); + return fs::is_block_file(fs::status(myFile)); #else - return of::filesystem::status(myFile).type() == of::filesystem::block_file; + return fs::status(myFile).type() == fs::block_file; #endif #endif } @@ -826,19 +828,19 @@ void ofFile::setWriteable(bool flag){ try{ #if !OF_USING_STD_FS || (OF_USING_STD_FS && OF_USE_EXPERIMENTAL_FS) if(flag){ - of::filesystem::permissions(myFile,of::filesystem::perms::owner_write | of::filesystem::perms::add_perms); + fs::permissions(myFile,fs::perms::owner_write | fs::perms::add_perms); }else{ - of::filesystem::permissions(myFile,of::filesystem::perms::owner_write | of::filesystem::perms::remove_perms); + fs::permissions(myFile,fs::perms::owner_write | fs::perms::remove_perms); } #else if(flag){ - of::filesystem::permissions(myFile, - of::filesystem::perms::owner_write, - of::filesystem::perm_options::add); + fs::permissions(myFile, + fs::perms::owner_write, + fs::perm_options::add); }else{ - of::filesystem::permissions(myFile, - of::filesystem::perms::owner_write, - of::filesystem::perm_options::remove); + fs::permissions(myFile, + fs::perms::owner_write, + fs::perm_options::remove); } #endif }catch(std::exception & e){ @@ -857,19 +859,19 @@ void ofFile::setReadable(bool flag){ try{ #if !OF_USING_STD_FS || (OF_USING_STD_FS && OF_USE_EXPERIMENTAL_FS) if(flag){ - of::filesystem::permissions(myFile,of::filesystem::perms::owner_read | of::filesystem::perms::add_perms); + fs::permissions(myFile,fs::perms::owner_read | fs::perms::add_perms); }else{ - of::filesystem::permissions(myFile,of::filesystem::perms::owner_read | of::filesystem::perms::remove_perms); + fs::permissions(myFile,fs::perms::owner_read | fs::perms::remove_perms); } #else if(flag){ - of::filesystem::permissions(myFile, - of::filesystem::perms::owner_read, - of::filesystem::perm_options::add); + fs::permissions(myFile, + fs::perms::owner_read, + fs::perm_options::add); }else{ - of::filesystem::permissions(myFile, - of::filesystem::perms::owner_read, - of::filesystem::perm_options::remove); + fs::permissions(myFile, + fs::perms::owner_read, + fs::perm_options::remove); } #endif }catch(std::exception & e){ @@ -883,26 +885,26 @@ void ofFile::setExecutable(bool flag){ #if OF_USING_STD_FS # if OF_USE_EXPERIMENTAL_FS if(flag){ - of::filesystem::permissions(myFile, of::filesystem::perms::owner_exec | of::filesystem::perms::add_perms); + fs::permissions(myFile, fs::perms::owner_exec | fs::perms::add_perms); } else{ - of::filesystem::permissions(myFile, of::filesystem::perms::owner_exec | of::filesystem::perms::remove_perms); + fs::permissions(myFile, fs::perms::owner_exec | fs::perms::remove_perms); } # else if(flag){ - of::filesystem::permissions(myFile, - of::filesystem::perms::owner_exec, - of::filesystem::perm_options::add); + fs::permissions(myFile, + fs::perms::owner_exec, + fs::perm_options::add); } else{ - of::filesystem::permissions(myFile, - of::filesystem::perms::owner_exec, - of::filesystem::perm_options::remove); + fs::permissions(myFile, + fs::perms::owner_exec, + fs::perm_options::remove); } # endif #else if(flag){ - of::filesystem::permissions(myFile, of::filesystem::perms::owner_exe | of::filesystem::perms::add_perms); + fs::permissions(myFile, fs::perms::owner_exe | fs::perms::add_perms); } else{ - of::filesystem::permissions(myFile, of::filesystem::perms::owner_exe | of::filesystem::perms::remove_perms); + fs::permissions(myFile, fs::perms::owner_exe | fs::perms::remove_perms); } #endif }catch(std::exception & e){ @@ -911,7 +913,7 @@ void ofFile::setExecutable(bool flag){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::copyTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite) const{ +bool ofFile::copyTo(const fs::path& _path, bool bRelativeToData, bool overwrite) const{ auto path = _path; if(path.empty()){ @@ -958,7 +960,7 @@ bool ofFile::copyTo(const of::filesystem::path& _path, bool bRelativeToData, boo if(!destDir.exists()){ ofFilePath::createEnclosingDirectory(path, false); } - of::filesystem::copy_file(myFile,path); + fs::copy_file(myFile,path); }catch(std::exception & except){ ofLogError("ofFile") << "copyTo(): unable to copy \"" << path << "\": " << except.what(); return false; @@ -968,7 +970,7 @@ bool ofFile::copyTo(const of::filesystem::path& _path, bool bRelativeToData, boo } //------------------------------------------------------------------------------------------------------------ -bool ofFile::moveTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite){ +bool ofFile::moveTo(const fs::path& _path, bool bRelativeToData, bool overwrite){ auto path = _path; if(path.empty()){ @@ -1011,7 +1013,7 @@ bool ofFile::moveTo(const of::filesystem::path& _path, bool bRelativeToData, boo if(!destDir.exists()){ ofFilePath::createEnclosingDirectory(path,false); } - of::filesystem::rename(myFile,path); + fs::rename(myFile,path); myFile = path; if(mode != ofFile::Reference){ changeMode(mode, binary); @@ -1026,7 +1028,7 @@ bool ofFile::moveTo(const of::filesystem::path& _path, bool bRelativeToData, boo } //------------------------------------------------------------------------------------------------------------ -bool ofFile::renameTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ +bool ofFile::renameTo(const fs::path& path, bool bRelativeToData, bool overwrite){ return moveTo(path,bRelativeToData,overwrite); } @@ -1046,9 +1048,9 @@ bool ofFile::remove(bool recursive){ open(path(),Reference,binary); } if(recursive){ - of::filesystem::remove_all(myFile); + fs::remove_all(myFile); }else{ - of::filesystem::remove(myFile); + fs::remove(myFile); } }catch(std::exception & except){ ofLogError("ofFile") << "remove(): unable to remove \"" << myFile << "\": " << except.what(); @@ -1061,7 +1063,7 @@ bool ofFile::remove(bool recursive){ //------------------------------------------------------------------------------------------------------------ uint64_t ofFile::getSize() const { try{ - return of::filesystem::file_size(myFile); + return fs::file_size(myFile); }catch(std::exception & except){ ofLogError("ofFile") << "getSize(): unable to get size of \"" << myFile << "\": " << except.what(); return 0; @@ -1102,7 +1104,7 @@ bool ofFile::operator>=(const ofFile & file) const { // ofFile Static Methods //------------------------------------------------------------------------------------------------------------ -bool ofFile::copyFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ +bool ofFile::copyFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool bRelativeToData, bool overwrite){ ofFile tmp; if( bRelativeToData ){ tmp.open(pathSrc,ofFile::Reference); @@ -1114,7 +1116,7 @@ bool ofFile::copyFromTo(const of::filesystem::path& pathSrc, const of::filesyste //be careful with slashes here - appending a slash when moving a folder will causes mad headaches //------------------------------------------------------------------------------------------------------------ -bool ofFile::moveFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ +bool ofFile::moveFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool bRelativeToData, bool overwrite){ ofFile tmp; if( bRelativeToData ){ tmp.open(pathSrc,ofFile::Reference); @@ -1125,7 +1127,7 @@ bool ofFile::moveFromTo(const of::filesystem::path& pathSrc, const of::filesyste } //------------------------------------------------------------------------------------------------------------ -bool ofFile::doesFileExist(const of::filesystem::path& _fPath, bool bRelativeToData){ +bool ofFile::doesFileExist(const fs::path& _fPath, bool bRelativeToData){ ofFile tmp; if(bRelativeToData){ tmp.open(_fPath,ofFile::Reference); @@ -1136,7 +1138,7 @@ bool ofFile::doesFileExist(const of::filesystem::path& _fPath, bool bRelativeToD } //------------------------------------------------------------------------------------------------------------ -bool ofFile::removeFile(const of::filesystem::path& _path, bool bRelativeToData){ +bool ofFile::removeFile(const fs::path& _path, bool bRelativeToData){ ofFile tmp; if(bRelativeToData){ tmp.open(_path,ofFile::Reference); @@ -1159,27 +1161,27 @@ ofDirectory::ofDirectory(){ } //------------------------------------------------------------------------------------------------------------ -ofDirectory::ofDirectory(const of::filesystem::path & path){ +ofDirectory::ofDirectory(const fs::path & path){ showHidden = false; open(path); } //------------------------------------------------------------------------------------------------------------ -void ofDirectory::open(const of::filesystem::path & path){ +void ofDirectory::open(const fs::path & path){ files.clear(); - myDir = of::filesystem::path(ofToDataPath(path)).lexically_normal(); + myDir = fs::path(ofToDataPath(path)).lexically_normal(); } //------------------------------------------------------------------------------------------------------------ -void ofDirectory::openFromCWD(const of::filesystem::path & path){ +void ofDirectory::openFromCWD(const fs::path & path){ originalDirectory = ofFilePath::getPathForDirectory(path); files.clear(); - myDir = of::filesystem::path(originalDirectory); + myDir = fs::path(originalDirectory); } //------------------------------------------------------------------------------------------------------------ void ofDirectory::close(){ - myDir = of::filesystem::path(); + myDir = fs::path(); } //------------------------------------------------------------------------------------------------------------ @@ -1188,9 +1190,9 @@ bool ofDirectory::create(bool recursive){ if(!myDir.empty()){ try{ if(recursive){ - of::filesystem::create_directories(myDir); + fs::create_directories(myDir); }else{ - of::filesystem::create_directory(myDir); + fs::create_directory(myDir); } } catch(std::exception & except){ @@ -1204,12 +1206,12 @@ bool ofDirectory::create(bool recursive){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::exists() const { - return (myDir == "" || of::filesystem::exists(myDir)); + return (myDir == "" || fs::exists(myDir)); } //------------------------------------------------------------------------------------------------------------ // MARK: - near future -//of::filesystem::path ofDirectory::path() const { +//fs::path ofDirectory::path() const { // return myDir; std::string ofDirectory::path() const { return myDir.string(); @@ -1217,18 +1219,18 @@ std::string ofDirectory::path() const { //------------------------------------------------------------------------------------------------------------ // MARK: - near future -//of::filesystem::path ofDirectory::getAbsolutePath() const { +//fs::path ofDirectory::getAbsolutePath() const { // try{ -// return of::filesystem::canonical(of::filesystem::absolute(myDir)); +// return fs::canonical(fs::absolute(myDir)); // }catch(...){ -// return of::filesystem::absolute(myDir); +// return fs::absolute(myDir); // } //} std::string ofDirectory::getAbsolutePath() const { try{ - return of::filesystem::canonical(of::filesystem::absolute(myDir)).string(); + return fs::canonical(fs::absolute(myDir)).string(); }catch(...){ - return of::filesystem::absolute(myDir).string(); + return fs::absolute(myDir).string(); } } @@ -1280,22 +1282,22 @@ void ofDirectory::setShowHidden(bool showHidden){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::isDirectory() const { - return of::filesystem::is_directory(myDir); + return fs::is_directory(myDir); } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::copyTo(const fs::path& _path, bool bRelativeToData, bool overwrite){ auto path = _path; if(myDir.string().empty()){ ofLogError("ofDirectory") << "copyTo(): source path is empty"; return false; } - if(!of::filesystem::exists(myDir)){ + if(!fs::exists(myDir)){ ofLogError("ofDirectory") << "copyTo(): source directory does not exist"; return false; } - if(!of::filesystem::is_directory(myDir)){ + if(!fs::is_directory(myDir)){ ofLogError("ofDirectory") << "copyTo(): source path is not a directory"; return false; } @@ -1319,10 +1321,10 @@ bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData dir.create(true); // Iterate through the source directory - 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)){ + for(fs::directory_iterator file(myDir); file != fs::directory_iterator(); ++file){ + auto currentPath = fs::absolute(file->path()); + auto dst = fs::path(path) / currentPath.filename(); + if(fs::is_directory(currentPath)){ ofDirectory current(currentPath); // Found directory: Recursion if(!current.copyTo(dst,false,overwrite)){ @@ -1339,20 +1341,20 @@ bool ofDirectory::copyTo(const of::filesystem::path& _path, bool bRelativeToData } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ - if (of::filesystem::exists(path)) { +bool ofDirectory::moveTo(const fs::path& path, bool bRelativeToData, bool overwrite){ + if (fs::exists(path)) { if (overwrite) { - of::filesystem::remove_all(path); + fs::remove_all(path); } else { ofLogError("ofDirectory") << "moveTo(): destination folder exists, overwrite = false " << std::endl; return false; } } - const of::filesystem::path & old = myDir; + const fs::path & old = myDir; try { - of::filesystem::rename(old, path); - } catch (of::filesystem::filesystem_error const& ex) { + fs::rename(old, path); + } catch (fs::filesystem_error const& ex) { ofLogError("ofDirectory") << "moveTo(): can't rename folder " << ex.code().message() << std::endl; return false; } @@ -1361,21 +1363,21 @@ bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::renameTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::renameTo(const fs::path& path, bool bRelativeToData, bool overwrite){ return moveTo(path, bRelativeToData, overwrite); } //------------------------------------------------------------------------------------------------------------ bool ofDirectory::remove(bool recursive){ - if(path().empty() || !of::filesystem::exists(myDir)){ + if(path().empty() || !fs::exists(myDir)){ return false; } try{ if(recursive){ - of::filesystem::remove_all(of::filesystem::canonical(myDir)); + fs::remove_all(fs::canonical(myDir)); }else{ - of::filesystem::remove(of::filesystem::canonical(myDir)); + fs::remove(fs::canonical(myDir)); } }catch(std::exception & except){ ofLogError("ofDirectory") << "remove(): unable to remove file/directory: " << except.what(); @@ -1394,7 +1396,7 @@ void ofDirectory::allowExt(const std::string& extension){ } //------------------------------------------------------------------------------------------------------------ -std::size_t ofDirectory::listDir(const of::filesystem::path & directory){ +std::size_t ofDirectory::listDir(const fs::path & directory){ open(directory); return listDir(); } @@ -1406,14 +1408,14 @@ std::size_t ofDirectory::listDir(){ ofLogError("ofDirectory") << "listDir(): directory path is empty"; return 0; } - if(!of::filesystem::exists(myDir)){ + if(!fs::exists(myDir)){ ofLogError("ofDirectory") << "listDir:() source directory does not exist: \"" << myDir << "\""; return 0; } - 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){ + fs::directory_iterator end_iter; + if ( fs::exists(myDir) && fs::is_directory(myDir)){ + for( fs::directory_iterator dir_iter(myDir) ; dir_iter != end_iter ; ++dir_iter){ files.emplace_back(dir_iter->path().string(), ofFile::Reference); } }else{ @@ -1501,8 +1503,8 @@ static bool natural(const ofFile& a, const ofFile& b) { //------------------------------------------------------------------------------------------------------------ static bool byDate(const ofFile& a, const ofFile& b) { - auto ta = of::filesystem::last_write_time(a); - auto tb = of::filesystem::last_write_time(b); + auto ta = fs::last_write_time(a); + auto tb = fs::last_write_time(b); return ta < tb; } @@ -1545,7 +1547,7 @@ int ofDirectory::numFiles(){ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::removeDirectory(const of::filesystem::path& _path, bool deleteIfNotEmpty, bool bRelativeToData){ +bool ofDirectory::removeDirectory(const fs::path& _path, bool deleteIfNotEmpty, bool bRelativeToData){ auto path = _path; ofFile dirToRemove; @@ -1559,14 +1561,14 @@ bool ofDirectory::removeDirectory(const of::filesystem::path& _path, bool delete } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::createDirectory(const of::filesystem::path& _dirPath, bool bRelativeToData, bool recursive){ +bool ofDirectory::createDirectory(const fs::path& _dirPath, bool bRelativeToData, bool recursive){ auto dirPath = _dirPath; if(bRelativeToData){ dirPath = ofToDataPath(dirPath); } - // on OSX,of::filesystem::create_directories seems to return false *if* the path has folders that already exist + // on OSX,fs::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: @@ -1577,9 +1579,9 @@ bool ofDirectory::createDirectory(const of::filesystem::path& _dirPath, bool bRe bool success = false; try{ if(!recursive){ - success = of::filesystem::create_directory(dirPath); + success = fs::create_directory(dirPath); }else{ - success = of::filesystem::create_directories(dirPath); + success = fs::create_directories(dirPath); } } catch(std::exception & except){ ofLogError("ofDirectory") << "createDirectory(): couldn't create directory \"" << dirPath << "\": " << except.what(); @@ -1593,13 +1595,13 @@ bool ofDirectory::createDirectory(const of::filesystem::path& _dirPath, bool bRe } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::doesDirectoryExist(const of::filesystem::path& _dirPath, bool bRelativeToData){ +bool ofDirectory::doesDirectoryExist(const fs::path& _dirPath, bool bRelativeToData){ auto dirPath = _dirPath; try { if (bRelativeToData) { dirPath = ofToDataPath(dirPath); } - return of::filesystem::exists(dirPath) && of::filesystem::is_directory(dirPath); + return fs::exists(dirPath) && fs::is_directory(dirPath); } catch (std::exception & except) { ofLogError("ofDirectory") << "doesDirectoryExist(): couldn't find directory \"" << dirPath << "\": " << except.what() << std::endl; @@ -1608,14 +1610,14 @@ bool ofDirectory::doesDirectoryExist(const of::filesystem::path& _dirPath, bool } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::isDirectoryEmpty(const of::filesystem::path& _dirPath, bool bRelativeToData){ +bool ofDirectory::isDirectoryEmpty(const fs::path& _dirPath, bool bRelativeToData){ auto dirPath = _dirPath; if(bRelativeToData){ dirPath = ofToDataPath(dirPath); } - if(!dirPath.empty() && of::filesystem::exists(dirPath) && of::filesystem::is_directory(dirPath)){ - return of::filesystem::directory_iterator(dirPath) == of::filesystem::directory_iterator(); + if(!dirPath.empty() && fs::exists(dirPath) && fs::is_directory(dirPath)){ + return fs::directory_iterator(dirPath) == fs::directory_iterator(); } return false; } @@ -1680,9 +1682,9 @@ vector::const_reverse_iterator ofDirectory::rend() const{ //------------------------------------------------------------------------------------------------------------ // FIXME: - Deprecate -string ofFilePath::addLeadingSlash(const of::filesystem::path& _path){ +string ofFilePath::addLeadingSlash(const fs::path& _path){ auto path = _path.string(); - auto sep = of::filesystem::path("/").make_preferred(); + auto sep = fs::path("/").make_preferred(); if(!path.empty()){ if(ofToString(path[0]) != sep.string()){ path = (sep / path).string(); @@ -1693,13 +1695,13 @@ string ofFilePath::addLeadingSlash(const of::filesystem::path& _path){ //------------------------------------------------------------------------------------------------------------ // FIXME: - Deprecate -std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ +std::string ofFilePath::addTrailingSlash(const fs::path & _path){ #if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS if(_path.string().empty()) return ""; - return (of::filesystem::path(_path).make_preferred() / "").string(); + return (fs::path(_path).make_preferred() / "").string(); #else - auto path = of::filesystem::path(_path).make_preferred(); - auto sep = of::filesystem::path("/").make_preferred(); + auto path = fs::path(_path).make_preferred(); + auto sep = fs::path("/").make_preferred(); if(!path.empty()){ if(ofToString(path.string().back()) != sep.string()){ path = (path / sep); @@ -1712,13 +1714,13 @@ std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ //------------------------------------------------------------------------------------------------------------ // FIXME: - Deprecate -string ofFilePath::getFileExt(const of::filesystem::path& filename){ +string ofFilePath::getFileExt(const fs::path& filename){ return ofFile(filename,ofFile::Reference).getExtension(); } //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -std::string ofFilePath::removeExt(const of::filesystem::path& _filename){ +std::string ofFilePath::removeExt(const fs::path& _filename){ auto filename = _filename; // return filename.replace_extension(); return filename.replace_extension().string(); @@ -1726,7 +1728,7 @@ std::string ofFilePath::removeExt(const of::filesystem::path& _filename){ //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -string ofFilePath::getPathForDirectory(const of::filesystem::path& path){ +string ofFilePath::getPathForDirectory(const fs::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 "/" @@ -1738,7 +1740,7 @@ string ofFilePath::getPathForDirectory(const of::filesystem::path& path){ if(path.string().empty()) return ""; return (path / "").string(); #else - auto sep = of::filesystem::path("/").make_preferred(); + auto sep = fs::path("/").make_preferred(); if(!path.empty() && ofToString(path.string().back())!=sep.string()){ return (path / sep).string(); }else{ @@ -1749,7 +1751,7 @@ string ofFilePath::getPathForDirectory(const of::filesystem::path& path){ //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -string ofFilePath::removeTrailingSlash(const of::filesystem::path& _path){ +string ofFilePath::removeTrailingSlash(const fs::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); @@ -1760,7 +1762,7 @@ string ofFilePath::removeTrailingSlash(const of::filesystem::path& _path){ //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRelativeToData){ +string ofFilePath::getFileName(const fs::path& _filePath, bool bRelativeToData){ auto filePath = _filePath; if(bRelativeToData){ @@ -1768,18 +1770,18 @@ string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRela } // FIXME: this is probably over complicated - return of::filesystem::path(filePath).filename().string(); + return fs::path(filePath).filename().string(); } //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -string ofFilePath::getBaseName(const of::filesystem::path& filePath){ +string ofFilePath::getBaseName(const fs::path& filePath){ return ofFile(filePath,ofFile::Reference).getBaseName(); } //------------------------------------------------------------------------------------------------------------ // FIXME: Is this useful? if not deprecate -std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ +std::string ofFilePath::getEnclosingDirectory(const fs::path & _filePath, bool bRelativeToData){ auto fp = _filePath; if(bRelativeToData){ fp = ofToDataPath(fp); @@ -1788,44 +1790,49 @@ std::string ofFilePath::getEnclosingDirectory(const of::filesystem::path & _file } //------------------------------------------------------------------------------------------------------------ -bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData, bool bRecursive) { +bool ofFilePath::createEnclosingDirectory(const fs::path& filePath, bool bRelativeToData, bool bRecursive) { return ofDirectory::createDirectory(ofFilePath::getEnclosingDirectory(filePath,bRelativeToData), bRelativeToData, bRecursive); } //------------------------------------------------------------------------------------------------------------ // FIXME: Is this useful? if not deprecate -std::string ofFilePath::getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData){ +std::string ofFilePath::getAbsolutePath(const fs::path& path, bool bRelativeToData){ if(bRelativeToData){ return ofToDataPath(path, true); }else{ try{ - return of::filesystem::canonical(of::filesystem::absolute(path)).string(); + return fs::canonical(fs::absolute(path)).string(); }catch(...){ - return of::filesystem::absolute(path).string(); + return fs::absolute(path).string(); } } } //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -bool ofFilePath::isAbsolute(const of::filesystem::path& path){ - return of::filesystem::path(path).is_absolute(); +bool ofFilePath::isAbsolute(const fs::path& path){ + return fs::path(path).is_absolute(); } //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate string ofFilePath::getCurrentWorkingDirectory(){ - return of::filesystem::current_path().string(); + return fs::current_path().string(); } //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate helper function more complex than actual solution -std::string ofFilePath::join(const of::filesystem::path& path1, const of::filesystem::path& path2){ +std::string ofFilePath::join(const fs::path& path1, const fs::path& path2){ return (path1 / path2).string(); } //------------------------------------------------------------------------------------------------------------ string ofFilePath::getCurrentExePath(){ + return getCurrentExePathFS().string(); +} + +//------------------------------------------------------------------------------------------------------------ +fs::path ofFilePath::getCurrentExePathFS(){ #if defined(TARGET_LINUX) || defined(TARGET_ANDROID) char buff[FILENAME_MAX]; ssize_t size = readlink("/proc/self/exe", buff, sizeof(buff) - 1); @@ -1844,12 +1851,12 @@ string ofFilePath::getCurrentExePath(){ } return path; #elif defined(TARGET_WIN32) - vector executablePath(MAX_PATH); + vector executablePath(MAX_PATH); DWORD result = ::GetModuleFileNameA(nullptr, &executablePath[0], static_cast(executablePath.size())); if(result == 0) { ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameA failed"; }else{ - return string(executablePath.begin(), executablePath.begin() + result); + return { executablePath.begin(), executablePath.begin() + result }; } #endif return ""; @@ -1857,9 +1864,8 @@ string ofFilePath::getCurrentExePath(){ //------------------------------------------------------------------------------------------------------------ // Can be changed to be unneeded in near future -of::filesystem::path ofFilePath::getCurrentExeDir(){ - auto exePath = of::filesystem::path(getCurrentExePath()); - return exePath.parent_path(); +fs::path ofFilePath::getCurrentExeDir(){ + return getCurrentExePathFS().parent_path(); } //------------------------------------------------------------------------------------------------------------ @@ -1879,8 +1885,8 @@ string ofFilePath::getUserHomeDir(){ //-------------------------------------------------- // FIXME: - deprecate -std::string ofFilePath::makeRelative(const of::filesystem::path & from, const of::filesystem::path & to){ - return of::filesystem::relative (to, from).string(); +std::string ofFilePath::makeRelative(const fs::path & from, const fs::path & to){ + return fs::relative (to, from).string(); } //-------------------------------------------------- @@ -1896,7 +1902,7 @@ void ofDisableDataPath(){ //-------------------------------------------------- bool ofRestoreWorkingDirectoryToDefault(){ try{ - of::filesystem::current_path(defaultWorkingDirectory()); + fs::current_path(defaultWorkingDirectory()); return true; }catch(...){ return false; @@ -1904,33 +1910,33 @@ bool ofRestoreWorkingDirectoryToDefault(){ } //-------------------------------------------------- -void ofSetDataPathRoot(const of::filesystem::path& newRoot){ +void ofSetDataPathRoot(const fs::path& newRoot){ dataPathRoot() = newRoot; } //-------------------------------------------------- -std::string ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ - of::filesystem::path outPath { path }; +std::string ofToDataPath(const fs::path & path, bool makeAbsolute){ + fs::path outPath { path }; if (path.is_absolute()) { if (makeAbsolute) { // nothing needed here. outPath is already path } else { - auto current = of::filesystem::current_path(); - outPath = of::filesystem::relative(path, current); + auto current = fs::current_path(); + outPath = fs::relative(path, current); } } else { if (makeAbsolute) { outPath = dataPathRoot() / path; } else { - auto current = of::filesystem::current_path(); - outPath = of::filesystem::relative(dataPathRoot() / path, current); + auto current = fs::current_path(); + outPath = fs::relative(dataPathRoot() / path, current); } } return outPath.string(); //// if our Current Working Directory has changed (e.g. file open dialog) //#ifdef TARGET_WIN32 -// if (defaultWorkingDirectory() != of::filesystem::current_path()) { +// if (defaultWorkingDirectory() != fs::current_path()) { // // change our cwd back to where it was on app load // bool ret = ofRestoreWorkingDirectoryToDefault(); // if(!ret){ diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 03514e7a65e..259522e85a7 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -429,6 +429,7 @@ class ofFilePath{ /// /// \returns current executable path static std::string getCurrentExePath(); + static of::filesystem::path getCurrentExePathFS(); /// Get the full path to the application's parent directory. /// From d0d04e2f584a3e2ac1c493a6120e421411b9831a Mon Sep 17 00:00:00 2001 From: Dimitre Date: Thu, 23 Nov 2023 15:51:23 -0300 Subject: [PATCH 27/49] update submodules --- apps/projectGenerator | 2 +- scripts/apothecary | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/projectGenerator b/apps/projectGenerator index 007fe56c2a9..63934b6f075 160000 --- a/apps/projectGenerator +++ b/apps/projectGenerator @@ -1 +1 @@ -Subproject commit 007fe56c2a90c946e2e4e2851f72ce07fbfc0500 +Subproject commit 63934b6f075d8c6462aae3776b8d4d07bbb5df9e diff --git a/scripts/apothecary b/scripts/apothecary index c25bef39d6b..135a5036a9d 160000 --- a/scripts/apothecary +++ b/scripts/apothecary @@ -1 +1 @@ -Subproject commit c25bef39d6b6ef9e2a02bc40a80d7cd9d773a3bc +Subproject commit 135a5036a9dfd5c1c6287624b083b4849ab1cd72 From 75e93afddfc73645428adf314ca9618fd5db0f8d Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 24 Nov 2023 00:32:46 -0300 Subject: [PATCH 28/49] fix perms --- libs/openFrameworks/utils/ofFileUtils.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index b593c7956f3..b63d3bd7fc1 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -706,7 +706,6 @@ bool ofFile::canRead() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = of::filesystem::status(myFile).permissions(); #if OF_USING_STD_FS if(geteuid() == info.st_uid){ return (perm & fs::perms::owner_read) != fs::perms::none; @@ -742,7 +741,6 @@ bool ofFile::canWrite() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = of::filesystem::status(myFile).permissions(); #if OF_USING_STD_FS if(geteuid() == info.st_uid){ return (perm & fs::perms::owner_write) != fs::perms::none; @@ -772,7 +770,6 @@ bool ofFile::canExecute() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = of::filesystem::status(myFile).permissions(); #if OF_USING_STD_FS if(geteuid() == info.st_uid){ return (perm & fs::perms::owner_exec) != fs::perms::none; From 4126b05ea054a5bf32ecf6d5845074f50e7aae46 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 1 Dec 2023 13:13:45 -0300 Subject: [PATCH 29/49] of::filesystem to fs --- libs/openFrameworks/utils/ofFileUtils.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 94267307d68..0f7ac5d9d96 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -26,13 +26,12 @@ namespace fs = of::filesystem; namespace{ bool enableDataPath = true; - - of::filesystem::path defaultDataPath(){ + fs::path defaultDataPath(){ #if defined TARGET_OSX try{ - return of::filesystem::canonical(ofFilePath::getCurrentExeDirFS() / of::filesystem::path("../../../data/")); + return of::filesystem::canonical(ofFilePath::getCurrentExeDirFS() / fs::path("../../../data/")); }catch(...){ - return (ofFilePath::getCurrentExeDirFS() / of::filesystem::path("../../../data/")); + return (ofFilePath::getCurrentExeDirFS() / fs::path("../../../data/")); } #elif defined TARGET_ANDROID return string("sdcard/"); @@ -40,14 +39,14 @@ namespace{ try{ return of::filesystem::canonical(ofFilePath::join(ofFilePath::getCurrentExeDirFS(), "data/")).make_preferred(); }catch(...){ - return (ofFilePath::getCurrentExeDirFS() / of::filesystem::path("data/")); + return (ofFilePath::getCurrentExeDirFS() / fs::path("data/")); } #endif } //-------------------------------------------------- - of::filesystem::path & defaultWorkingDirectory(){ - static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDirFS()); + fs::path & defaultWorkingDirectory(){ + static auto * defaultWorkingDirectory = new fs::path(ofFilePath::getCurrentExeDirFS()); return * defaultWorkingDirectory; } @@ -1506,7 +1505,7 @@ static bool natural(const ofFile& a, const ofFile& b) { //------------------------------------------------------------------------------------------------------------ struct StringSort{ - of::filesystem::path path; + fs::path path; string basename; int nameInt; string stringInt; @@ -1575,7 +1574,7 @@ void ofDirectory::sort(const SortMode & mode){ files.clear(); files.reserve(sort.size()); for( auto & s : sort ){ - files.emplace_back( myDir / of::filesystem::path(s), ofFile::Reference); + files.emplace_back( myDir / fs::path(s), ofFile::Reference); } }else if(mode == ofDirectory::SORT_BY_DATE){ sortByDate(); @@ -1771,7 +1770,7 @@ std::string ofFilePath::addTrailingSlash(const fs::path & _path){ //------------------------------------------------------------------------------------------------------------ -// FIXME: - start using of::filesystem::path.extension() +// FIXME: - start using fs::path.extension() string ofFilePath::getFileExt(const fs::path& filename){ return ofFile(filename,ofFile::Reference).getExtension(); } @@ -1924,8 +1923,8 @@ fs::path ofFilePath::getCurrentExeDirFS(){ //------------------------------------------------------------------------------------------------------------ std::string ofFilePath::getCurrentExeDir(){ - // std::string sep = of::filesystem::path::preferred_separator; - return getCurrentExeDirFS().string() + of::filesystem::path("/").make_preferred().string(); + // std::string sep = fs::path::preferred_separator; + return getCurrentExeDirFS().string() + fs::path("/").make_preferred().string(); } //------------------------------------------------------------------------------------------------------------ From 155894e80c5c8fc6991840603d335f9e6a21b019 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 1 Dec 2023 13:20:53 -0300 Subject: [PATCH 30/49] fix --- libs/openFrameworks/utils/ofFileUtils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 64ca1da8a79..78ada73d29d 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -430,7 +430,6 @@ class ofFilePath { /// \returns current executable path static of::filesystem::path getCurrentExePathFS(); static std::string getCurrentExePath(); - static of::filesystem::path getCurrentExePathFS(); /// Get the full path to the application's parent directory. /// From 14a471174ac6ce47ffd9ce5052c1ec3b97e048f1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 1 Dec 2023 13:27:44 -0300 Subject: [PATCH 31/49] up --- libs/openFrameworks/utils/ofFileUtils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 78ada73d29d..f30e057aaf6 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -313,7 +313,7 @@ class ofFilePath { /// /// \param path directory path /// \returns path + slash - static std::string 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". @@ -430,7 +430,7 @@ class ofFilePath { /// \returns current executable path static of::filesystem::path getCurrentExePathFS(); static std::string getCurrentExePath(); - + /// Get the full path to the application's parent directory. /// /// Windows & Linux: the application's parent directory From 919656c0855d1004e0435c648791784dfeff88a3 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 4 Dec 2023 22:16:34 -0300 Subject: [PATCH 32/49] revert some --- libs/openFrameworks/utils/ofFileUtils.h | 6 +++++- tests/utils/fileUtils/src/main.cpp | 14 +++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index f30e057aaf6..36685ae809a 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -1,6 +1,6 @@ #pragma once -// FIXME: constants deprecated only +// FIXME: Deprecated and FS #include "ofConstants.h" #include @@ -313,6 +313,8 @@ class ofFilePath { /// /// \param path directory path /// \returns path + slash + // 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), @@ -1229,6 +1231,8 @@ 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(). +// 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. diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index a849ec78a0a..ba2948db87d 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -118,8 +118,6 @@ class ofApp: public ofxUnitTestsApp{ ofxTest(ofDirectory("d1").canExecute(),"ofDirectory::canExecute"); } -// std::exit(0); - ofDirectory("noreaddir").create(); ofDirectory("noreaddir").setWriteable(false); ofxTest(ofDirectory("noreaddir").canRead(),"ofDirectory::canRead readonly"); @@ -139,9 +137,6 @@ class ofApp: public ofxUnitTestsApp{ ofxTest(ofFile("d5/f1").isFile(),"ofDirectory::moveTo f1 exists"); ofxTest(ofFile("d5/d3/f2").isFile(),"ofDirectory::moveTo f2 exists"); - - std::exit(0); - ofxTest(ofDirectory("d5").renameTo("d4"),"ofDirectory::renameTo"); ofxTest(ofDirectory("d4").isDirectory(),"ofDirectory::renameTo dir exists"); ofxTest(ofDirectory("d4/d3").isDirectory(),"ofDirectory::renameTo recursive dir exists"); @@ -209,16 +204,13 @@ class ofApp: public ofxUnitTestsApp{ ofLogNotice() << "tests #4299"; ofxTestEq(of::filesystem::path(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); if(ofGetTargetPlatform()==OF_TARGET_OSX){ - ofxTestEq(ofToDataPath("",false),"../../../data","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false),"../../../data/","ofToDataPath relative"); }else if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ - ofxTestEq(ofToDataPath("",false),"data","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false),"data\\","ofToDataPath relative"); }else{ - ofxTestEq(ofToDataPath("",false),"data","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false),"data/","ofToDataPath relative"); } - std::exit(0); - - //======================================================================== ofLogNotice() << ""; From 902f0ca1e7b6c76145926051ed2870a1033cca6f Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 4 Dec 2023 22:27:26 -0300 Subject: [PATCH 33/49] revert commit --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 0f7ac5d9d96..92926cb81a8 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1441,7 +1441,7 @@ std::size_t ofDirectory::listDir(){ for(int i = 0; i < (int)size(); i++){ ofLogVerbose() << "\t" << getName(i); } - ofLogVerbose() << "listed " << size() << " files in \"" << originalDirectory << "\""; + ofLogVerbose() << "listed " << size() << " files in \"" << originalDirectory.string() << "\""; } return size(); From 76e84bc2ad5bdfbc5d43a6f5585064e763510fbe Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 4 Dec 2023 22:30:36 -0300 Subject: [PATCH 34/49] revert --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 92926cb81a8..0f7ac5d9d96 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1441,7 +1441,7 @@ std::size_t ofDirectory::listDir(){ for(int i = 0; i < (int)size(); i++){ ofLogVerbose() << "\t" << getName(i); } - ofLogVerbose() << "listed " << size() << " files in \"" << originalDirectory.string() << "\""; + ofLogVerbose() << "listed " << size() << " files in \"" << originalDirectory << "\""; } return size(); From 36090e69f6677007077aa7a0368c31da0d76f670 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 7 Jan 2024 14:21:07 -0300 Subject: [PATCH 35/49] fix conflicts --- libs/openFrameworks/utils/ofFileUtils.cpp | 3 --- libs/openFrameworks/utils/ofFileUtils.h | 4 ---- 2 files changed, 7 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 6d4955c76ed..05ac4a58c73 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -708,7 +708,6 @@ bool ofFile::canRead() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = fs::status(myFile).permissions(); #if OF_USING_STD_FS if(geteuid() == info.st_uid){ return (perm & fs::perms::owner_read) != fs::perms::none; @@ -744,7 +743,6 @@ bool ofFile::canWrite() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = fs::status(myFile).permissions(); #if OF_USING_STD_FS if(geteuid() == info.st_uid){ return (perm & fs::perms::owner_write) != fs::perms::none; @@ -774,7 +772,6 @@ bool ofFile::canExecute() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = fs::status(myFile).permissions(); #if OF_USING_STD_FS if(geteuid() == info.st_uid){ return (perm & fs::perms::owner_exec) != fs::perms::none; diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 4d2af22751a..c7096ff4116 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -1,10 +1,6 @@ #pragma once -<<<<<<< HEAD -// FIXME: Deprecated and FS -======= // MARK: ofConstants FS ->>>>>>> master #include "ofConstants.h" #include From 8561228115f815bbdcad180ddc730fdfa716aa05 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 7 Jan 2024 14:53:08 -0300 Subject: [PATCH 36/49] update tests --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- tests/utils/fileUtils/bin/data/.gitkeep | 1 - tests/utils/fileUtils/src/main.cpp | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 tests/utils/fileUtils/bin/data/.gitkeep diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 05ac4a58c73..ffa1baba485 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -56,7 +56,7 @@ namespace{ fs::path & dataPathRoot() { static auto * dataPathRoot = new fs::path(defaultDataPath()); // This is the most important change in the way OF handles paths. - fs::current_path(*dataPathRoot); +// fs::current_path(*dataPathRoot); return *dataPathRoot; } } diff --git a/tests/utils/fileUtils/bin/data/.gitkeep b/tests/utils/fileUtils/bin/data/.gitkeep deleted file mode 100644 index 8b137891791..00000000000 --- a/tests/utils/fileUtils/bin/data/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index ba2948db87d..fe151fcb299 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -203,6 +203,9 @@ class ofApp: public ofxUnitTestsApp{ ofLogNotice() << ""; ofLogNotice() << "tests #4299"; ofxTestEq(of::filesystem::path(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); + + std::cout << ofToDataPath("",false) << std::endl; + if(ofGetTargetPlatform()==OF_TARGET_OSX){ ofxTestEq(ofToDataPath("",false),"../../../data/","ofToDataPath relative"); }else if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ @@ -283,8 +286,8 @@ class ofApp: public ofxUnitTestsApp{ #include "ofAppRunner.h" //======================================================================== int main( ){ - initial_cwd = of::filesystem::current_path(); ofInit(); + initial_cwd = of::filesystem::current_path(); auto window = std::make_shared(); auto app = std::make_shared(); ofRunApp(window, app); From b0f6e88debb105690ab6d33d85bb118532f4bd13 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 11 May 2024 10:05:58 -0300 Subject: [PATCH 37/49] up --- libs/openFrameworks/utils/ofFileUtils.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index ffa1baba485..a2a390bf4da 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -22,15 +22,20 @@ using std::istream; using std::ostream; using std::ios; +using std::cout; +using std::endl; + namespace fs = of::filesystem; -namespace{ +namespace { bool enableDataPath = true; //-------------------------------------------------- fs::path defaultDataPath(){ + cout << "fs::path defaultDataPath()" << endl; #if defined TARGET_OSX try { + cout << "xx" << fs::canonical(ofFilePath::getCurrentExeDirFS() / "../../../data/") << endl; return fs::canonical(ofFilePath::getCurrentExeDirFS() / "../../../data/"); } catch(...) { return ofFilePath::getCurrentExeDirFS() / "../../../data/"; @@ -56,7 +61,7 @@ namespace{ fs::path & dataPathRoot() { static auto * dataPathRoot = new fs::path(defaultDataPath()); // This is the most important change in the way OF handles paths. -// fs::current_path(*dataPathRoot); + fs::current_path(*dataPathRoot); return *dataPathRoot; } } From 2a4ac9da25695de02cf4a46c29fe9b2f1a062c48 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 11 May 2024 10:19:12 -0300 Subject: [PATCH 38/49] group / endgroup in run_tests --- scripts/ci/osx/run_tests.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/ci/osx/run_tests.sh b/scripts/ci/osx/run_tests.sh index 36256a47fdd..2b9aaf5b5a7 100755 --- a/scripts/ci/osx/run_tests.sh +++ b/scripts/ci/osx/run_tests.sh @@ -5,24 +5,27 @@ ROOT=${TRAVIS_BUILD_DIR:-"$( cd "$(dirname "$0")/../../.." ; pwd -P )"} trap 'for f in ~/Library/Logs/DiagnosticReports/*; do cat $f; done' 11 -echo "**** Building emptyExample ****" +echo "##[group] **** Building emptyExample ****" cd $ROOT cp scripts/templates/osx/Makefile examples/templates/emptyExample/ cp scripts/templates/osx/config.make examples/templates/emptyExample/ cd examples/templates/emptyExample/ make -j Debug +echo "##[endgroup]" -echo "**** Building allAddonsExample ****" +echo "##[group]**** Building allAddonsExample ****" cd $ROOT cp scripts/templates/osx/Makefile examples/templates/allAddonsExample/ cp scripts/templates/osx/config.make examples/templates/allAddonsExample/ cd examples/templates/allAddonsExample/ make -j Debug +echo "##[endgroup]" -echo "**** Running unit tests ****" +echo "##[group]**** Running unit tests ****" cd $ROOT/tests for group in *; do if [ -d $group ]; then + echo "##[group] $group" for test in $group/*; do if [ -d $test ]; then cd $test @@ -37,5 +40,7 @@ for group in *; do cd $ROOT/tests fi done + echo "##[endgroup]" fi done +echo "##[endgroup]" \ No newline at end of file From c7e933f17ca86a3a44bc2437dad4a463bea8efa1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 11 May 2024 10:22:52 -0300 Subject: [PATCH 39/49] group --- scripts/ci/osx/run_tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/ci/osx/run_tests.sh b/scripts/ci/osx/run_tests.sh index 2b9aaf5b5a7..010bc6aa43e 100755 --- a/scripts/ci/osx/run_tests.sh +++ b/scripts/ci/osx/run_tests.sh @@ -1,7 +1,6 @@ #!/bin/bash -set -ev +#set -ev ROOT=${TRAVIS_BUILD_DIR:-"$( cd "$(dirname "$0")/../../.." ; pwd -P )"} -# source $ROOT/scripts/ci/ccache.sh trap 'for f in ~/Library/Logs/DiagnosticReports/*; do cat $f; done' 11 From 5f038a8f8cc6219506160fe819218a8107d2b821 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 11 May 2024 21:34:48 -0300 Subject: [PATCH 40/49] try to fix --- libs/openFrameworks/utils/ofFileUtils.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index a2a390bf4da..99682419288 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1916,13 +1916,27 @@ fs::path ofFilePath::getCurrentExePathFS(){ } return path; #elif defined(TARGET_WIN32) - vector executablePath(MAX_PATH); - DWORD result = ::GetModuleFileNameA(nullptr, &executablePath[0], static_cast(executablePath.size())); + + wchar_t filename[MAX_PATH]; + DWORD result = ::GetModuleFileName( + nullptr, // retrieve path of current process .EXE + filename, + _countof(filename) + ); if (result == 0) { + // Error ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameA failed"; - }else{ + } else { return { executablePath.begin(), executablePath.begin() + result }; } + + // vector executablePath(MAX_PATH); + // DWORD result = ::GetModuleFileNameA(nullptr, &executablePath[0], static_cast(executablePath.size())); + // if (result == 0) { + // ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameA failed"; + // }else{ + // return { executablePath.begin(), executablePath.begin() + result }; + // } #endif return ""; } From b73badfbab320a56aa2a6911ac7ec680e226d2a6 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 11 May 2024 21:37:53 -0300 Subject: [PATCH 41/49] ok --- libs/openFrameworks/utils/ofFileUtils.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 99682419288..182900faab5 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -32,10 +32,9 @@ namespace { //-------------------------------------------------- fs::path defaultDataPath(){ - cout << "fs::path defaultDataPath()" << endl; #if defined TARGET_OSX try { - cout << "xx" << fs::canonical(ofFilePath::getCurrentExeDirFS() / "../../../data/") << endl; +// cout << "xx" << fs::canonical(ofFilePath::getCurrentExeDirFS() / "../../../data/") << endl; return fs::canonical(ofFilePath::getCurrentExeDirFS() / "../../../data/"); } catch(...) { return ofFilePath::getCurrentExeDirFS() / "../../../data/"; From 83a0d3f7b090d17c7c443b54e6090bf737571d95 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 2 Sep 2024 12:14:19 -0300 Subject: [PATCH 42/49] more conflicts fix --- libs/openFrameworks/utils/ofFileUtils.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 3847d7b4471..aa2d173d8d6 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1889,10 +1889,7 @@ fs::path ofFilePath::getCurrentExePath(){ } return path; #elif defined(TARGET_WIN32) -<<<<<<< HEAD -======= ->>>>>>> master wchar_t filename[MAX_PATH]; DWORD result = ::GetModuleFileName( nullptr, // retrieve path of current process .EXE @@ -1901,7 +1898,6 @@ fs::path ofFilePath::getCurrentExePath(){ ); if (result == 0) { // Error -<<<<<<< HEAD ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameA failed"; } else { return { executablePath.begin(), executablePath.begin() + result }; @@ -1914,11 +1910,6 @@ fs::path ofFilePath::getCurrentExePath(){ // }else{ // return { executablePath.begin(), executablePath.begin() + result }; // } -======= - ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileName failed"; - } - return filename; ->>>>>>> master #endif return {}; } From 9a8e9953714b3ee20085afbe5697ef6547b9b4d1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 2 Sep 2024 13:01:36 -0300 Subject: [PATCH 43/49] up --- libs/openFrameworks/utils/ofFileUtils.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index aa2d173d8d6..9854823ace7 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1889,12 +1889,11 @@ fs::path ofFilePath::getCurrentExePath(){ } return path; #elif defined(TARGET_WIN32) - - wchar_t filename[MAX_PATH]; - DWORD result = ::GetModuleFileName( - nullptr, // retrieve path of current process .EXE - filename, - _countof(filename) + vector executablePath(MAX_PATH); + DWORD result = ::GetModuleFileNameW( + nullptr, + executablePath, + _countof(executablePath) ); if (result == 0) { // Error @@ -1903,13 +1902,6 @@ fs::path ofFilePath::getCurrentExePath(){ return { executablePath.begin(), executablePath.begin() + result }; } - // vector executablePath(MAX_PATH); - // DWORD result = ::GetModuleFileNameA(nullptr, &executablePath[0], static_cast(executablePath.size())); - // if (result == 0) { - // ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameA failed"; - // }else{ - // return { executablePath.begin(), executablePath.begin() + result }; - // } #endif return {}; } From 9192592fbfbd3f662fb52aadf9a366091d67bbad Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 2 Sep 2024 13:15:13 -0300 Subject: [PATCH 44/49] up win --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 9854823ace7..f603e4fdcc2 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1893,7 +1893,7 @@ fs::path ofFilePath::getCurrentExePath(){ DWORD result = ::GetModuleFileNameW( nullptr, executablePath, - _countof(executablePath) + static_cast(MAX_PATH) ); if (result == 0) { // Error From e27babdab8423197cabdce5cfbafc7489b123936 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 2 Sep 2024 13:47:09 -0300 Subject: [PATCH 45/49] more --- libs/openFrameworks/utils/ofFileUtils.cpp | 35 +++++++++++++++-------- libs/openFrameworks/utils/ofFileUtils.h | 1 - tests/addons/ofxOsc/src/main.cpp | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index f603e4fdcc2..a5d7730993c 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -35,16 +35,18 @@ namespace { #if defined TARGET_OSX try { return fs::canonical(ofFilePath::getCurrentExeDir() / "../../../data/"); - } catch(...) { + } catch(fs::filesystem_error & e) { + ofLogWarning("ofFileUtils") << "defaultDataPath 1 " << e.what(); return ofFilePath::getCurrentExeDir() / "../../../data/"; } #elif defined TARGET_ANDROID return string("sdcard/"); #else try { - return fs::canonical(ofFilePath::getCurrentExeDir() / "data/").make_preferred(); - } catch(...) { - return (ofFilePath::getCurrentExeDir() / "data/"); + return fs::canonical(ofFilePath::getCurrentExeDir() / "data").make_preferred(); + } catch(fs::filesystem_error & e) { + ofLogWarning("ofFileUtils") << "defaultDataPath 2 " << e.what(); + return (ofFilePath::getCurrentExeDir() / "data"); } #endif } @@ -59,7 +61,11 @@ namespace { fs::path & dataPathRoot() { static auto * dataPathRoot = new fs::path(defaultDataPath()); // This is the most important change in the way OF handles paths. - fs::current_path(*dataPathRoot); + try { + fs::current_path(*dataPathRoot); + } catch(fs::filesystem_error & e) { + ofLogError("ofFileUtils") << "dataPathRoot " << e.what(); + } return *dataPathRoot; } } @@ -1223,7 +1229,8 @@ std::string ofDirectory::path() const { fs::path ofDirectory::getAbsolutePath() const { try { return fs::canonical(fs::absolute(myDir)); - } catch(...) { + } catch(fs::filesystem_error & e) { + ofLogWarning("ofFileUtils") << "ofDirectory::getAbsolutePath " << e.what(); return fs::absolute(myDir); } } @@ -1845,7 +1852,8 @@ fs::path ofFilePath::getAbsolutePath(const fs::path & path, bool bRelativeToData }else{ try{ return fs::canonical(fs::absolute(path)); - }catch(...){ + } catch(fs::filesystem_error & e) { + ofLogWarning("ofFileUtils") << "getAbsolutePath " << e.what(); return fs::absolute(path); } } @@ -1889,7 +1897,8 @@ fs::path ofFilePath::getCurrentExePath(){ } return path; #elif defined(TARGET_WIN32) - vector executablePath(MAX_PATH); +// vector executablePath(MAX_PATH); + wchar_t executablePath[MAX_PATH]; DWORD result = ::GetModuleFileNameW( nullptr, executablePath, @@ -1897,9 +1906,10 @@ fs::path ofFilePath::getCurrentExePath(){ ); if (result == 0) { // Error - ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameA failed"; + ofLogError("ofFilePath") << "getCurrentExePath(): couldn't get path, GetModuleFileNameW failed"; } else { - return { executablePath.begin(), executablePath.begin() + result }; +// return { executablePath.begin(), executablePath.begin() + result }; + return { executablePath }; } #endif @@ -1909,7 +1919,7 @@ fs::path ofFilePath::getCurrentExePath(){ //------------------------------------------------------------------------------------------------------------ fs::path ofFilePath::getCurrentExeDir(){ - return ofFilePath::getCurrentExePath().parent_path() / ""; + return ofFilePath::getCurrentExePath().parent_path(); } @@ -1949,7 +1959,8 @@ bool ofRestoreWorkingDirectoryToDefault(){ try{ fs::current_path(defaultWorkingDirectory()); return true; - }catch(...){ + } catch(fs::filesystem_error & e) { + ofLogWarning("ofFileUtils") << "ofRestoreWorkingDirectoryToDefault " << e.what(); return false; } } diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 3808c2025e9..381679d6856 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -439,7 +439,6 @@ class ofFilePath { /// /// \returns current executable directory static of::filesystem::path getCurrentExeDir(); -// static std::string getCurrentExeDir(); /// Get the absolute path to the user's home directory. /// diff --git a/tests/addons/ofxOsc/src/main.cpp b/tests/addons/ofxOsc/src/main.cpp index 2fd45934af5..d41451b1cad 100644 --- a/tests/addons/ofxOsc/src/main.cpp +++ b/tests/addons/ofxOsc/src/main.cpp @@ -15,7 +15,7 @@ class ofApp: public ofxUnitTestsApp { std::string str { "/string" }; ofxOscMessage m_str {str}; - ofxTest(m_str.getAddress() == "/string","ofxOscMessage{std::string"); + ofxTest(m_str.getAddress() == "/string","ofxOscMessage{std::string}"); std::string & strref = str; ofxOscMessage m_strref {strref}; From cb018251c3b213fff57fd62a55287e7dee474167 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 2 Sep 2024 15:29:47 -0300 Subject: [PATCH 46/49] update tests --- libs/openFrameworks/utils/ofFileUtils.cpp | 6 +- libs/openFrameworks/utils/ofFileUtils.h | 2 +- tests/utils/fileUtils/src/main.cpp | 88 +++++++++++++---------- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index a5d7730993c..e4ddff3ffcd 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -64,7 +64,7 @@ namespace { try { fs::current_path(*dataPathRoot); } catch(fs::filesystem_error & e) { - ofLogError("ofFileUtils") << "dataPathRoot " << e.what(); + ofLogError("ofFileUtils") << "dataPathRoot\n" << e.what(); } return *dataPathRoot; } @@ -1866,8 +1866,8 @@ bool ofFilePath::isAbsolute(const fs::path& path){ //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate -string ofFilePath::getCurrentWorkingDirectory(){ - return ofPathToString(fs::current_path()); +fs::path ofFilePath::getCurrentWorkingDirectory(){ + return fs::current_path(); } //------------------------------------------------------------------------------------------------------------ diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 381679d6856..cb6149c0f43 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -413,7 +413,7 @@ class ofFilePath { /// \warning This location *may* change if you or a library calls the cd() /// std C function. /// \returns current working directory - static std::string getCurrentWorkingDirectory(); + static of::filesystem::path getCurrentWorkingDirectory(); /// Create a single path by joining path1 & path2 using a slash, /// ie. "/hello/world" + "foo/bar" -> "/hello/world/foo/bar". diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index 66bff82fac6..dcec1a054e7 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -2,21 +2,23 @@ #include "ofUtils.h" #include "ofxUnitTests.h" -of::filesystem::path initial_cwd; +namespace fs = of::filesystem; +fs::path initial_cwd; class ofApp: public ofxUnitTestsApp{ void run(){ ofDirectory dir("."); dir.create(true); dir.exists(); - for(auto f: dir){ - f.setWriteable(true); - if(f.isDirectory()){ - ofDirectory(f.path()).remove(true); - }else{ - f.remove(); - } - } + for(auto f: dir){ + f.setWriteable(true); + if(f.isDirectory()){ + std::cout << "will remove " << f.path() << std::endl; + ofDirectory(f.path()).remove(true); + }else{ + f.remove(); + } + } ofxTest(ofDirectory(".").getFiles().empty(),"removing old tests files","other tests will fail too"); @@ -202,16 +204,15 @@ class ofApp: public ofxUnitTestsApp{ //======================================================================== ofLogNotice() << ""; ofLogNotice() << "tests #4299"; - ofxTestEq(of::filesystem::path(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); + ofxTestEq(fs::canonical(ofFilePath::getCurrentWorkingDirectory()), initial_cwd, "ofFilePath::getCurrentWorkingDirectory()"); - std::cout << ofToDataPath("",false) << std::endl; if(ofGetTargetPlatform()==OF_TARGET_OSX){ - ofxTestEq(ofToDataPath("",false),"../../../data/","ofToDataPath relative"); + ofxTestEq(ofToDataPath("", false), ".", "ofToDataPath relative"); }else if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ - ofxTestEq(ofToDataPath("",false),"data\\","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false), ".", "ofToDataPath relative"); }else{ - ofxTestEq(ofToDataPath("",false),"data/","ofToDataPath relative"); + ofxTestEq(ofToDataPath("",false), ".", "ofToDataPath relative"); } @@ -233,22 +234,22 @@ class ofApp: public ofxUnitTestsApp{ } - //======================================================================== - ofLogNotice() << ""; - ofLogNotice() << "tests #4598"; - ofxTestEq(ofPathToString(ofToDataPath("")).back(), of::filesystem::path::preferred_separator, "ofToDataPath with empty string shouldn't crash"); + // //======================================================================== + // ofLogNotice() << ""; + // ofLogNotice() << "tests #4598"; + // ofxTestEq(ofPathToString(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"), "data/a.txt","#4563 test1"); - ofxTestEq(ofToDataPath("data.txt"), "data/data.txt", "#4563 test2"); - ofxTestEq(ofToDataPath(""), "data/", "#4563 test3"); + ofxTestEq(ofToDataPath("a.txt"), "a.txt","#4563 test1"); + ofxTestEq(ofToDataPath("data.txt"), "data.txt", "#4563 test2"); + ofxTestEq(ofToDataPath(""), "", "#4563 test3"); #elif defined(TARGET_OSX) - ofxTestEq(ofToDataPath("a.txt"), "../../../data/a.txt","#4563 test1"); - ofxTestEq(ofToDataPath("data.txt"), "../../../data/data.txt", "#4563 test2"); - ofxTestEq(ofToDataPath(""), "../../../data/", "#4563 test3"); + ofxTestEq(ofToDataPath("a.txt"), "a.txt","#4563 test1"); + ofxTestEq(ofToDataPath("data.txt"), "data.txt", "#4563 test2"); + ofxTestEq(ofToDataPath(""), ".", "#4563 test3"); #endif @@ -265,19 +266,29 @@ class ofApp: public ofxUnitTestsApp{ } //======================================================================== - ofLogNotice() << "#4564"; - dir.remove(true); - if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ - ofDirectory currentVideoDirectory(ofToDataPath("..\\..\\..\\video", true)); - 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(); - std::string pathEnd("data/../../../video/"); - ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); - } +// ofLogNotice() << "#4564"; + // no, this removes the data folder completely +//// dir.remove(true); +// if(ofGetTargetPlatform()==OF_TARGET_WINVS || ofGetTargetPlatform()==OF_TARGET_MINGW){ +// ofDirectory currentVideoDirectory(ofToDataPath("..\\..\\..\\video", true)); +// auto path = currentVideoDirectory.path(); +// std::string pathEnd("data\\..\\..\\..\\video\\"); +// ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); +// }else{ +// using std::cout; +// using std::endl; +// +// std::cout << 1 << std::endl; +// ofDirectory currentVideoDirectory(ofToDataPath("../../../video", true)); +// std::cout << 2 << std::endl; +// auto path = ofPathToString(currentVideoDirectory.path()); +// cout << path << endl; +// std::cout << 3 << std::endl; +// std::string pathEnd("data/../../../video/"); +// std::cout << 4 << std::endl; +// ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); +// std::cout << 5 << std::endl; +// } } }; @@ -288,8 +299,9 @@ class ofApp: public ofxUnitTestsApp{ int main( ){ ofInit(); initial_cwd = of::filesystem::current_path(); +// std::cout << "initial_cwd " << initial_cwd << std::endl; auto window = std::make_shared(); auto app = std::make_shared(); ofRunApp(window, app); return ofRunMainLoop(); -} \ No newline at end of file +} From 7b5245678d94a1e9873858b8d7abe93bb86ee5df Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 2 Sep 2024 15:41:29 -0300 Subject: [PATCH 47/49] gitkeep data folder tests --- tests/utils/fileUtils/bin/data/.gitkeep | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/utils/fileUtils/bin/data/.gitkeep diff --git a/tests/utils/fileUtils/bin/data/.gitkeep b/tests/utils/fileUtils/bin/data/.gitkeep new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/utils/fileUtils/bin/data/.gitkeep @@ -0,0 +1 @@ + From 6659794dbb077581e4c1dfaf69c0146e0431e70c Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 9 Dec 2024 16:12:44 -0300 Subject: [PATCH 48/49] merge master --- apps/projectGenerator | 2 +- scripts/apothecary | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/projectGenerator b/apps/projectGenerator index a59f24da613..0d4e7c3c7cd 160000 --- a/apps/projectGenerator +++ b/apps/projectGenerator @@ -1 +1 @@ -Subproject commit a59f24da613b6094cd22cdd15d5748eb221f9c1f +Subproject commit 0d4e7c3c7cd5ad48eae0ba4189887680bc9f847a diff --git a/scripts/apothecary b/scripts/apothecary index 7d5a6d85683..b8b8325f8d0 160000 --- a/scripts/apothecary +++ b/scripts/apothecary @@ -1 +1 @@ -Subproject commit 7d5a6d856838d02224464d57ef19bd17609d4e50 +Subproject commit b8b8325f8d060e5474248cb6c5c6bd24a6698307 From 3678022033cb5401832e0d9123e35359f13aa253 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 3 May 2025 11:27:39 -0300 Subject: [PATCH 49/49] merge master --- apps/projectGenerator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/projectGenerator b/apps/projectGenerator index 74afcd48555..bb6456ef735 160000 --- a/apps/projectGenerator +++ b/apps/projectGenerator @@ -1 +1 @@ -Subproject commit 74afcd48555ba9b3d0c430b2853ddad306a89b63 +Subproject commit bb6456ef735e16816e10ffea8fe44e70f0b7af0c