Browse files

resolve deviations in cwd. keep relative paths

  • Loading branch information...
1 parent 1f5f91e commit 5accbf1ed2058663a0032d21aedc7009e8340764 @elliotwoods committed Aug 30, 2012
Showing with 23 additions and 6 deletions.
  1. +23 −6 libs/openFrameworks/utils/ofUtils.cpp
View
29 libs/openFrameworks/utils/ofUtils.cpp
@@ -204,18 +204,28 @@ 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
#ifndef TARGET_OF_IPHONE
@@ -232,6 +242,9 @@ void ofSetWorkingDirectoryToDefault(){
}
#endif
#endif
+
+ defaultWorkingDirectory() = getWorkingDir();
+ defaultWorkingDirectory().makeAbsolute();
}
//--------------------------------------------------
@@ -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();
}
//----------------------------------------

0 comments on commit 5accbf1

Please sign in to comment.