@@ -29,24 +29,24 @@ namespace{
2929 fs::path defaultDataPath (){
3030 #if defined TARGET_OSX
3131 try {
32- return fs::canonical (ofFilePath::getCurrentExeDir () / " ../../../data/" );
32+ return fs::canonical (ofFilePath::getCurrentExeDirFS () / " ../../../data/" );
3333 } catch (...) {
34- return ofFilePath::getCurrentExeDir () / " ../../../data/" ;
34+ return ofFilePath::getCurrentExeDirFS () / " ../../../data/" ;
3535 }
3636 #elif defined TARGET_ANDROID
3737 return string (" sdcard/" );
3838 #else
3939 try {
40- return fs::canonical (ofFilePath::getCurrentExeDir () / " data/" ).make_preferred ();
40+ return fs::canonical (ofFilePath::getCurrentExeDirFS () / " data/" ).make_preferred ();
4141 } catch (...) {
42- return (ofFilePath::getCurrentExeDir () / " data/" );
42+ return (ofFilePath::getCurrentExeDirFS () / " data/" );
4343 }
4444 #endif
4545 }
4646
4747 // --------------------------------------------------
4848 fs::path & defaultWorkingDirectory () {
49- static auto * defaultWorkingDirectory = new fs::path (ofFilePath::getCurrentExeDir ());
49+ static auto * defaultWorkingDirectory = new fs::path (ofFilePath::getCurrentExeDirFS ());
5050 return * defaultWorkingDirectory;
5151 }
5252
@@ -558,7 +558,7 @@ bool ofFile::openStream(Mode _mode, bool _binary){
558558// ------------------------------------------------------------------------------------------------------------
559559bool ofFile::open (const fs::path & _path, Mode _mode, bool binary){
560560 close ();
561- myFile = ofToDataPath (_path);
561+ myFile = ofToDataPathFS (_path);
562562 return openStream (_mode, binary);
563563}
564564
@@ -648,10 +648,15 @@ bool ofFile::exists() const {
648648}
649649
650650// ------------------------------------------------------------------------------------------------------------
651- fs::path ofFile::path () const {
651+ fs::path ofFile::pathFS () const {
652652 return myFile;
653653}
654654
655+ // ------------------------------------------------------------------------------------------------------------
656+ std::string ofFile::path () const {
657+ return ofPathToString (pathFS ());
658+ }
659+
655660// ------------------------------------------------------------------------------------------------------------
656661// FIXME: Deprecate
657662string ofFile::getExtension () const {
@@ -675,12 +680,14 @@ string ofFile::getBaseName() const {
675680}
676681
677682// ------------------------------------------------------------------------------------------------------------
678- fs::path ofFile::getEnclosingDirectory () const {
683+ // MARK: - near future FS
684+ std::string ofFile::getEnclosingDirectory () const {
679685 return ofFilePath::getEnclosingDirectory (path ());
680686}
681687
682688// ------------------------------------------------------------------------------------------------------------
683- fs::path ofFile::getAbsolutePath () const {
689+ // MARK: - near future FS
690+ std::string ofFile::getAbsolutePath () const {
684691 return ofFilePath::getAbsolutePath (path ());
685692}
686693
@@ -921,7 +928,7 @@ bool ofFile::copyTo(const fs::path & _path, bool bRelativeToData, bool overwrite
921928
922929 // bRelativeToData is handled here for the destination path - so we pass false to static functions below
923930 if (bRelativeToData){
924- path = ofToDataPath (path);
931+ path = ofToDataPathFS (path);
925932 }
926933
927934 if (ofFile::doesFileExist (path, false )){
@@ -971,7 +978,7 @@ bool ofFile::moveTo(const fs::path& _path, bool bRelativeToData, bool overwrite)
971978 }
972979
973980 if (bRelativeToData){
974- path = ofToDataPath (path);
981+ path = ofToDataPathFS (path);
975982 }
976983 if (ofFile::doesFileExist (path, false )){
977984
@@ -1157,14 +1164,14 @@ ofDirectory::ofDirectory(const fs::path & path){
11571164
11581165// ------------------------------------------------------------------------------------------------------------
11591166void ofDirectory::open (const fs::path & path){
1160- originalDirectory = ofFilePath::getPathForDirectory (path);
1167+ originalDirectory = ofFilePath::getPathForDirectoryFS (path);
11611168 files.clear ();
1162- myDir = ofToDataPath (originalDirectory);
1169+ myDir = ofToDataPathFS (originalDirectory);
11631170}
11641171
11651172// ------------------------------------------------------------------------------------------------------------
11661173void ofDirectory::openFromCWD (const fs::path & path){
1167- originalDirectory = ofFilePath::getPathForDirectory (path);
1174+ originalDirectory = ofFilePath::getPathForDirectoryFS (path);
11681175 files.clear ();
11691176 myDir = originalDirectory;
11701177}
@@ -1206,14 +1213,20 @@ std::string ofDirectory::path() const {
12061213}
12071214
12081215// ------------------------------------------------------------------------------------------------------------
1209- fs::path ofDirectory::getAbsolutePath () const {
1216+ fs::path ofDirectory::getAbsolutePathFS () const {
12101217 try {
12111218 return fs::canonical (fs::absolute (myDir));
12121219 } catch (...) {
12131220 return fs::absolute (myDir);
12141221 }
12151222}
12161223
1224+ // MARK: - near future FS
1225+ // ------------------------------------------------------------------------------------------------------------
1226+ std::string ofDirectory::getAbsolutePath () const {
1227+ return ofPathToString (ofDirectory::getAbsolutePathFS ());
1228+ }
1229+
12171230// ------------------------------------------------------------------------------------------------------------
12181231bool ofDirectory::canRead () const {
12191232 return ofFile (myDir,ofFile::Reference).canRead ();
@@ -1283,7 +1296,7 @@ bool ofDirectory::copyTo(const fs::path & _path, bool bRelativeToData, bool over
12831296 }
12841297
12851298 if (bRelativeToData){
1286- path = ofToDataPath (path, bRelativeToData);
1299+ path = ofToDataPathFS (path, bRelativeToData);
12871300 }
12881301
12891302 if (ofDirectory::doesDirectoryExist (path, false )){
@@ -1587,7 +1600,7 @@ bool ofDirectory::createDirectory(const fs::path& _dirPath, bool bRelativeToData
15871600 auto dirPath = _dirPath;
15881601
15891602 if (bRelativeToData){
1590- dirPath = ofToDataPath (dirPath);
1603+ dirPath = ofToDataPathFS (dirPath);
15911604 }
15921605
15931606 // on OSX,fs::create_directories seems to return false *if* the path has folders that already exist
@@ -1621,7 +1634,7 @@ bool ofDirectory::doesDirectoryExist(const fs::path& _dirPath, bool bRelativeToD
16211634 auto dirPath = _dirPath;
16221635 try {
16231636 if (bRelativeToData) {
1624- dirPath = ofToDataPath (dirPath);
1637+ dirPath = ofToDataPathFS (dirPath);
16251638 }
16261639 return fs::exists (dirPath) && fs::is_directory (dirPath);
16271640 }
@@ -1635,7 +1648,7 @@ bool ofDirectory::doesDirectoryExist(const fs::path& _dirPath, bool bRelativeToD
16351648bool ofDirectory::isDirectoryEmpty (const fs::path& _dirPath, bool bRelativeToData){
16361649 auto dirPath = _dirPath;
16371650 if (bRelativeToData){
1638- dirPath = ofToDataPath (dirPath);
1651+ dirPath = ofToDataPathFS (dirPath);
16391652 }
16401653
16411654 if (!dirPath.empty () && fs::exists (dirPath) && fs::is_directory (dirPath)){
@@ -1750,7 +1763,7 @@ std::string ofFilePath::removeExt(const fs::path & _filename){
17501763}
17511764
17521765// ------------------------------------------------------------------------------------------------------------
1753- fs::path ofFilePath::getPathForDirectory (const fs::path & path){
1766+ fs::path ofFilePath::getPathForDirectoryFS (const fs::path & path){
17541767 // if a trailing slash is missing from a path, this will clean it up
17551768 // if it's a windows-style "\" path it will add a "\"
17561769 // if it's a unix-style "/" path it will add a "/"
@@ -1769,11 +1782,18 @@ fs::path ofFilePath::getPathForDirectory(const fs::path & path){
17691782}
17701783
17711784
1785+ // ------------------------------------------------------------------------------------------------------------
1786+ // FIXME: Deprecate this seems over complicated and not useful anymore, using filesystem
1787+ string ofFilePath::getPathForDirectory (const fs::path & path){
1788+ return ofPathToString (ofFilePath::getPathForDirectoryFS (path));
1789+ }
1790+
1791+
17721792// ------------------------------------------------------------------------------------------------------------
17731793// FIXME: - re-avail
17741794string ofFilePath::removeTrailingSlash (const fs::path & _path){
17751795 auto path = ofPathToString (_path);
1776- if (! path.empty () && (path[path.length () - 1 ] == ' /' || path[path.length () - 1 ] == ' \\ ' )){
1796+ if (path.length () > 0 && (path[path.length () - 1 ] == ' /' || path[path.length () - 1 ] == ' \\ ' )){
17771797 path = path.substr (0 , path.length () - 1 );
17781798 }
17791799 return path;
@@ -1797,7 +1817,9 @@ string ofFilePath::getBaseName(const fs::path & filePath){
17971817}
17981818
17991819// ------------------------------------------------------------------------------------------------------------
1800- fs::path ofFilePath::getEnclosingDirectory (const fs::path & _filePath, bool bRelativeToData){
1820+ // MARK: - near future FS
1821+ // fs::path ofFilePath::getEnclosingDirectoryFS(const fs::path & _filePath, bool bRelativeToData){
1822+ std::string ofFilePath::getEnclosingDirectory (const fs::path & _filePath, bool bRelativeToData){
18011823 auto fp = _filePath;
18021824 if (bRelativeToData){
18031825 fp = ofToDataPath (fp);
@@ -1811,7 +1833,8 @@ bool ofFilePath::createEnclosingDirectory(const fs::path& filePath, bool bRelati
18111833}
18121834
18131835// ------------------------------------------------------------------------------------------------------------
1814- fs::path ofFilePath::getAbsolutePath (const fs::path & path, bool bRelativeToData){
1836+ // MARK: - near future FS
1837+ fs::path ofFilePath::getAbsolutePathFS (const fs::path & path, bool bRelativeToData){
18151838 if (bRelativeToData){
18161839 return ofToDataPath (path, true );
18171840 }else {
@@ -1823,6 +1846,11 @@ fs::path ofFilePath::getAbsolutePath(const fs::path & path, bool bRelativeToData
18231846 }
18241847}
18251848
1849+ // ------------------------------------------------------------------------------------------------------------
1850+ std::string ofFilePath::getAbsolutePath (const fs::path& path, bool bRelativeToData){
1851+ return ofPathToString (ofFilePath::getAbsolutePathFS (path, bRelativeToData));
1852+ }
1853+
18261854// ------------------------------------------------------------------------------------------------------------
18271855bool ofFilePath::isAbsolute (const fs::path& path){
18281856 return fs::path (path).is_absolute ();
@@ -1841,7 +1869,7 @@ std::string ofFilePath::join(const fs::path& path1, const fs::path& path2){
18411869}
18421870
18431871// ------------------------------------------------------------------------------------------------------------
1844- fs::path ofFilePath::getCurrentExePath (){
1872+ fs::path ofFilePath::getCurrentExePathFS (){
18451873 #if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
18461874 char buff[FILENAME_MAX];
18471875 ssize_t size = readlink (" /proc/self/exe" , buff, sizeof (buff) - 1 );
@@ -1860,27 +1888,31 @@ fs::path ofFilePath::getCurrentExePath(){
18601888 }
18611889 return path;
18621890 #elif defined(TARGET_WIN32)
1863- wchar_t filename[MAX_PATH];
1864- DWORD result = ::GetModuleFileName (
1865- nullptr , // retrieve path of current process .EXE
1866- filename,
1867- _countof (filename)
1868- );
1891+ vector<char > executablePath (MAX_PATH);
1892+ DWORD result = ::GetModuleFileNameA (nullptr , &executablePath[0 ], static_cast <DWORD>(executablePath.size ()));
18691893 if (result == 0 ) {
1870- // Error
1871- ofLogError (" ofFilePath" ) << " getCurrentExePath(): couldn't get path, GetModuleFileName failed" ;
1894+ ofLogError (" ofFilePath" ) << " getCurrentExePath(): couldn't get path, GetModuleFileNameA failed" ;
1895+ } else {
1896+ return string (executablePath.begin (), executablePath.begin () + result);
18721897 }
1873- return filename;
18741898 #endif
1875- return {} ;
1899+ return " " ;
18761900}
18771901
1902+ // ------------------------------------------------------------------------------------------------------------
1903+ std::string ofFilePath::getCurrentExePath (){
1904+ return ofPathToString (getCurrentExePathFS ());
1905+ }
18781906
18791907// ------------------------------------------------------------------------------------------------------------
1880- fs::path ofFilePath::getCurrentExeDir (){
1881- return ofFilePath::getCurrentExePath ().parent_path () / " " ;
1908+ fs::path ofFilePath::getCurrentExeDirFS (){
1909+ return ofFilePath::getCurrentExePathFS ().parent_path () / " " ;
18821910}
18831911
1912+ // ------------------------------------------------------------------------------------------------------------
1913+ std::string ofFilePath::getCurrentExeDir (){
1914+ return ofPathToString (getCurrentExeDirFS ());
1915+ }
18841916
18851917// ------------------------------------------------------------------------------------------------------------
18861918string ofFilePath::getUserHomeDir (){
@@ -1929,7 +1961,7 @@ void ofSetDataPathRoot(const fs::path& newRoot){
19291961}
19301962
19311963// --------------------------------------------------
1932- fs::path ofToDataPath (const fs::path & path, bool makeAbsolute){
1964+ fs::path ofToDataPathFS (const fs::path & path, bool makeAbsolute){
19331965 if (makeAbsolute && path.is_absolute ()) {
19341966 return path;
19351967 }
@@ -2019,6 +2051,10 @@ fs::path ofToDataPath(const fs::path & path, bool makeAbsolute){
20192051 }
20202052}
20212053
2054+ // --------------------------------------------------
2055+ std::string ofToDataPath (const fs::path & path, bool makeAbsolute){
2056+ return ofPathToString (ofToDataPathFS (path, makeAbsolute));
2057+ }
20222058
20232059// --------------------------------------------------
20242060// Function used internally in OF core. API can change later
0 commit comments