Skip to content

Commit

Permalink
resolve deviations in cwd. keep relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwoods committed Aug 30, 2012
1 parent 1f5f91e commit 5accbf1
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions libs/openFrameworks/utils/ofUtils.cpp
Expand Up @@ -204,17 +204,27 @@ string defaultDataPath(){
#else
return string("data/");
#endif

}

//--------------------------------------------------
//use ofSetDataPathRoot() to override this
static Poco::Path & defaultWorkingDirectory(){
static Poco::Path defaultWorkingDirectory;
return defaultWorkingDirectory;
}

//--------------------------------------------------
static Poco::Path & dataPathRoot(){
static Poco::Path dataPathRoot(defaultDataPath());
dataPathRoot.makeAbsolute();
return dataPathRoot;
}

//--------------------------------------------------
Poco::Path getWorkingDir(){
char charWorkingDir[MAXPATHLEN];
getcwd(charWorkingDir, MAXPATHLEN);
return Poco::Path(charWorkingDir);
}

//--------------------------------------------------
void ofSetWorkingDirectoryToDefault(){
#ifdef TARGET_OSX
Expand All @@ -232,6 +242,9 @@ void ofSetWorkingDirectoryToDefault(){
}
#endif
#endif

defaultWorkingDirectory() = getWorkingDir();
defaultWorkingDirectory().makeAbsolute();
}

//--------------------------------------------------
Expand All @@ -244,14 +257,18 @@ string ofToDataPath(string path, bool makeAbsolute){
if (!enableDataPath)
return path;

if (defaultWorkingDirectory().toString() != getWorkingDir().toString()) {
chdir(defaultWorkingDirectory().toString().c_str());
}

Poco::Path inputPath(dataPathRoot());
inputPath.resolve(path);

if (makeAbsolute) {
inputPath.makeAbsolute();
return inputPath.absolute().toString();
} else {
return inputPath.toString();
}

return inputPath.toString();
}

//----------------------------------------
Expand Down

0 comments on commit 5accbf1

Please sign in to comment.