Expand '~' as user homedir shortcut when adding data directories

This matches the behavior used when searching for specific input files.
This commit is contained in:
Ray Speth 2018-09-21 16:17:01 -04:00
parent 4fe58661e1
commit ca8700fdd4

View file

@ -379,6 +379,17 @@ void Application::addDataDirectory(const std::string& dir)
}
string d = stripnonprint(dir);
// Expand "~/" to user's home directory, if possible
if (d.find("~/") == 0 || d.find("~\\") == 0) {
char* home = getenv("HOME"); // POSIX systems
if (!home) {
home = getenv("USERPROFILE"); // Windows systems
}
if (home) {
d = home + d.substr(1, npos);
}
}
// Remove any existing entry for this directory
auto iter = std::find(inputDirs.begin(), inputDirs.end(), d);
if (iter != inputDirs.end()) {