@@ -25,29 +25,27 @@ namespace{
2525 bool enableDataPath = true ;
2626
2727 // --------------------------------------------------
28- // MARK: - near future
29- // of::filesystem::path defaultDataPath(){
30- std::string defaultDataPath (){
28+ of::filesystem::path defaultDataPath (){
3129 #if defined TARGET_OSX
3230 try {
33- return of::filesystem::canonical (ofFilePath::getCurrentExeDir () / of::filesystem::path (" ../../../data/" )). string ( );
31+ return of::filesystem::canonical (ofFilePath::getCurrentExeDirFS () / of::filesystem::path (" ../../../data/" ));
3432 }catch (...){
35- return (ofFilePath::getCurrentExeDir () / of::filesystem::path (" ../../../data/" )). string ( );
33+ return (ofFilePath::getCurrentExeDirFS () / of::filesystem::path (" ../../../data/" ));
3634 }
3735 #elif defined TARGET_ANDROID
3836 return string (" sdcard/" );
3937 #else
4038 try {
41- return of::filesystem::canonical (ofFilePath::join (ofFilePath::getCurrentExeDir (), " data/" )).make_preferred (). string ();
39+ return of::filesystem::canonical (ofFilePath::join (ofFilePath::getCurrentExeDirFS (), " data/" )).make_preferred ();
4240 }catch (...){
43- return (ofFilePath::getCurrentExeDir () / of::filesystem::path (" data/" )). string ( );
41+ return (ofFilePath::getCurrentExeDirFS () / of::filesystem::path (" data/" ));
4442 }
4543 #endif
4644 }
4745
4846 // --------------------------------------------------
4947 of::filesystem::path & defaultWorkingDirectory (){
50- static auto * defaultWorkingDirectory = new of::filesystem::path (ofFilePath::getCurrentExeDir ());
48+ static auto * defaultWorkingDirectory = new of::filesystem::path (ofFilePath::getCurrentExeDirFS ());
5149 return * defaultWorkingDirectory;
5250 }
5351
@@ -1399,10 +1397,9 @@ std::size_t ofDirectory::listDir(){
13991397 return 0 ;
14001398 }
14011399
1402- of::filesystem::directory_iterator end_iter;
14031400 if ( of::filesystem::exists (myDir) && of::filesystem::is_directory (myDir)){
1404- for ( of::filesystem::directory_iterator dir_iter ( myDir) ; dir_iter != end_iter ; ++dir_iter) {
1405- files.emplace_back (dir_iter-> path (). string (), ofFile::Reference);
1401+ for ( const auto & f : of::filesystem::directory_iterator{ myDir }) {
1402+ files.emplace_back (f. path (), ofFile::Reference);
14061403 }
14071404 }else {
14081405 ofLogError (" ofDirectory" ) << " listDir:() source directory does not exist: " << myDir ;
@@ -1723,7 +1720,8 @@ vector<ofFile>::const_reverse_iterator ofDirectory::rend() const{
17231720
17241721
17251722// ------------------------------------------------------------------------------------------------------------
1726- string ofFilePath::addLeadingSlash (const of::filesystem::path& _path){
1723+ // FIXME: - re-avail
1724+ string ofFilePath::addLeadingSlash (const of::filesystem::path & _path){
17271725 auto path = _path.string ();
17281726 auto sep = of::filesystem::path (" /" ).make_preferred ();
17291727 if (!path.empty ()){
@@ -1735,13 +1733,10 @@ string ofFilePath::addLeadingSlash(const of::filesystem::path& _path){
17351733}
17361734
17371735// ------------------------------------------------------------------------------------------------------------
1738- // MARK: - near future
1739- // of::filesystem::path ofFilePath::addTrailingSlash(const of::filesystem::path & _path){
1736+ // FIXME: - re-avail
17401737std::string ofFilePath::addTrailingSlash (const of::filesystem::path & _path){
17411738#if OF_USING_STD_FS && !OF_USE_EXPERIMENTAL_FS
1742- if (_path.string ().empty ()) return " " ;
1743- // FIXME: Remove .string() here and following
1744- // return (of::filesystem::path(_path).make_preferred() / "");
1739+ if (_path.empty ()) return " " ;
17451740 return (of::filesystem::path (_path).make_preferred () / " " ).string ();
17461741#else
17471742 auto path = of::filesystem::path (_path).make_preferred ();
@@ -1751,29 +1746,26 @@ std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){
17511746 path = (path / sep);
17521747 }
17531748 }
1754- // return path;
17551749 return path.string ();
17561750#endif
17571751}
17581752
17591753
17601754// ------------------------------------------------------------------------------------------------------------
1761- string ofFilePath::getFileExt (const of::filesystem::path& filename){
1755+ // FIXME: - start using of::filesystem::path.extension()
1756+ string ofFilePath::getFileExt (const of::filesystem::path & filename){
17621757 return ofFile (filename,ofFile::Reference).getExtension ();
17631758}
17641759
17651760// ------------------------------------------------------------------------------------------------------------
1766- // FIXME: remove const and copy
1767- // MARK: - near future
1768- // of::filesystem::path ofFilePath::removeExt(const of::filesystem::path& _filename){
1769- std::string ofFilePath::removeExt (const of::filesystem::path& _filename){
1761+ // FIXME: - suggest replace_extension instead
1762+ std::string ofFilePath::removeExt (const of::filesystem::path & _filename){
17701763 auto filename = _filename;
1771- // return filename.replace_extension();
17721764 return filename.replace_extension ().string ();
17731765}
17741766
17751767// ------------------------------------------------------------------------------------------------------------
1776- string ofFilePath::getPathForDirectory (const of::filesystem::path& path){
1768+ string ofFilePath::getPathForDirectory (const of::filesystem::path & path){
17771769 // if a trailing slash is missing from a path, this will clean it up
17781770 // if it's a windows-style "\" path it will add a "\"
17791771 // if it's a unix-style "/" path it will add a "/"
@@ -1795,8 +1787,8 @@ string ofFilePath::getPathForDirectory(const of::filesystem::path& path){
17951787}
17961788
17971789// ------------------------------------------------------------------------------------------------------------
1798- // FIXME: convert to of::filesystem::path
1799- string ofFilePath::removeTrailingSlash (const of::filesystem::path& _path){
1790+ // FIXME: - re-avail
1791+ string ofFilePath::removeTrailingSlash (const of::filesystem::path & _path){
18001792 auto path = _path.string ();
18011793 if (path.length () > 0 && (path[path.length () - 1 ] == ' /' || path[path.length () - 1 ] == ' \\ ' )){
18021794 path = path.substr (0 , path.length () - 1 );
@@ -1806,7 +1798,7 @@ string ofFilePath::removeTrailingSlash(const of::filesystem::path& _path){
18061798
18071799
18081800// ------------------------------------------------------------------------------------------------------------
1809- // FIXME: is this still useful? if yes convert to of::filesystem::path
1801+ // FIXME: - re-avail
18101802string ofFilePath::getFileName (const of::filesystem::path& _filePath, bool bRelativeToData){
18111803 auto filePath = _filePath;
18121804
@@ -1819,9 +1811,9 @@ string ofFilePath::getFileName(const of::filesystem::path& _filePath, bool bRela
18191811}
18201812
18211813// ------------------------------------------------------------------------------------------------------------
1822- string ofFilePath::getBaseName ( const of::filesystem::path& filePath){
1823- // FIXME: is this still useful?
1824- return ofFile ( filePath,ofFile::Reference). getBaseName ();
1814+ // FIXME: - suggest using stem() instead
1815+ string ofFilePath::getBaseName ( const of::filesystem::path & filePath){
1816+ return filePath. stem (). string ();
18251817}
18261818
18271819// ------------------------------------------------------------------------------------------------------------
@@ -1879,7 +1871,7 @@ std::string ofFilePath::join(const of::filesystem::path& path1, const of::filesy
18791871}
18801872
18811873// ------------------------------------------------------------------------------------------------------------
1882- string ofFilePath::getCurrentExePath (){
1874+ of::filesystem::path ofFilePath::getCurrentExePathFS (){
18831875 #if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
18841876 char buff[FILENAME_MAX];
18851877 ssize_t size = readlink (" /proc/self/exe" , buff, sizeof (buff) - 1 );
@@ -1900,20 +1892,30 @@ string ofFilePath::getCurrentExePath(){
19001892 #elif defined(TARGET_WIN32)
19011893 vector<char > executablePath (MAX_PATH);
19021894 DWORD result = ::GetModuleFileNameA (nullptr , &executablePath[0 ], static_cast <DWORD>(executablePath.size ()));
1903- if (result == 0 ) {
1895+ if (result == 0 ) {
19041896 ofLogError (" ofFilePath" ) << " getCurrentExePath(): couldn't get path, GetModuleFileNameA failed" ;
1905- }else {
1897+ } else {
19061898 return string (executablePath.begin (), executablePath.begin () + result);
19071899 }
19081900 #endif
19091901 return " " ;
19101902}
19111903
19121904// ------------------------------------------------------------------------------------------------------------
1913- // MARK: - near future
1914- // of::filesystem::path ofFilePath::getCurrentExeDir(){
1905+ std::string ofFilePath::getCurrentExePath (){
1906+ return getCurrentExePathFS ().string ();
1907+ }
1908+
1909+ // ------------------------------------------------------------------------------------------------------------
1910+ of::filesystem::path ofFilePath::getCurrentExeDirFS (){
1911+ return ofFilePath::getCurrentExePathFS ().parent_path ();
1912+ }
1913+
1914+ // ------------------------------------------------------------------------------------------------------------
19151915std::string ofFilePath::getCurrentExeDir (){
1916- return ofFilePath::getEnclosingDirectory (ofFilePath::getCurrentExePath (), false );
1916+
1917+ // std::string sep = of::filesystem::path::preferred_separator;
1918+ return getCurrentExeDirFS ().string () + of::filesystem::path (" /" ).make_preferred ().string ();
19171919}
19181920
19191921// ------------------------------------------------------------------------------------------------------------
0 commit comments