Skip to content

Commit

Permalink
updated comments of ofToDataPath
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwoods committed Aug 31, 2012
1 parent 75be75f commit bcb9b60
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libs/openFrameworks/utils/ofUtils.cpp
Expand Up @@ -258,40 +258,43 @@ string ofToDataPath(string path, bool makeAbsolute){
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());
}
// this could be performed here, or wherever we might think we accidentally change the cwd, e.g. after file dialogs on windows

Poco::Path const & dataPath(dataPathRoot());
Poco::Path inputPath(path);
Poco::Path outputPath;

// if path is already absolute, just return it
if (inputPath.isAbsolute()) {
return path;
}

// 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)
// if the path begins with the full contents of dataPathRoot then the data path has already been added
// we compare inputPath.toString() rather that the input var path to ensure common formatting against dataPath.toString()
string strippedDataPath = dataPath.toString();
// also, we strip the 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)
strippedDataPath.resize(strippedDataPath.length() - 1);

if (inputPath.toString().find(strippedDataPath) != 0) {
// inputPath doesn't contain data path already, so we add it
// inputPath doesn't contain data path already, so we build the output path as the inputPath relative to the dataPath
outputPath = dataPath;
outputPath.resolve(inputPath);
} else {
// inputPath does contain data path already, no need to change
// inputPath already contains data path, so no need to change
outputPath = inputPath;
}

// finally, if we do want an absolute path and we don't already have one
if (makeAbsolute) {
// then we perform it here
return outputPath.absolute().toString();
} else {
// or output the relative path
return outputPath.toString();
}
}
Expand Down

0 comments on commit bcb9b60

Please sign in to comment.