Skip to content

Commit

Permalink
fixed issue when input path to ofToDataPath already includes data path
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwoods committed Aug 31, 2012
1 parent 5accbf1 commit ad601f2
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions libs/openFrameworks/utils/ofUtils.cpp
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit ad601f2

Please sign in to comment.