Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed issue when input path to ofToDataPath already includes data path

  • Loading branch information...
commit ad601f299e39e47783ebc7c5bc3235ddae6d34cc 1 parent 5accbf1
@elliotwoods authored
Showing with 27 additions and 4 deletions.
  1. +27 −4 libs/openFrameworks/utils/ofUtils.cpp
View
31 libs/openFrameworks/utils/ofUtils.cpp
@@ -257,17 +257,40 @@ string ofToDataPath(string path, bool makeAbsolute){
if (!enableDataPath)
return path;
+ // if our Current Working Directory has changed (e.g. file open dialog)
+ // this could be performed here, or wherever we might think we accidentally change the cwd
if (defaultWorkingDirectory().toString() != getWorkingDir().toString()) {
+ // change our cwd back to where it was on app load
chdir(defaultWorkingDirectory().toString().c_str());
}
- Poco::Path inputPath(dataPathRoot());
- inputPath.resolve(path);
+ Poco::Path const & dataPath(dataPathRoot());
+ Poco::Path inputPath(path);
+ Poco::Path outputPath;
+
+ if (!inputPath.isAbsolute()) {
+ // 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
+ // we compare inputPath.toString() rather that the input var path ensure common formatting against dataPathRoot.toString() to
+
+ // strip 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)
+ string strippedDataPath = dataPath.toString();
+ strippedDataPath.resize(strippedDataPath.length() - 1);
+
+ if (inputPath.toString().find(strippedDataPath) != 0) {
+ // inputPath doesn't contain data path already, so we add it
+ outputPath = dataPath;
+ outputPath.resolve(inputPath);
+ } else {
+ // inputPath does contain data path already, no need to change
+ outputPath = inputPath;
+ }
+ }
if (makeAbsolute) {
- return inputPath.absolute().toString();
+ return outputPath.absolute().toString();
} else {
- return inputPath.toString();
+ return outputPath.toString();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.