Skip to content

Commit

Permalink
Add the executable path as a data dir
Browse files Browse the repository at this point in the history
Fixes bug #242
  • Loading branch information
dscharrer committed Aug 4, 2012
1 parent ab2da3c commit 6784f9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -485,6 +485,9 @@ else()
if(NOT DEFINED CONFIG_DIR_PREFIXES)
set(CONFIG_DIR_PREFIXES "$XDG_CONFIG_HOME")
endif()
if(NOT DEFINED IGNORE_EXE_DIR)
set(IGNORE_EXE_DIR "/usr/bin:/usr/games:/usr/games/bin:/usr/local/bin:/usr/local/games:/usr/local/games/bin")
endif()
endif()

# Check that all required functionality is available.
Expand Down
2 changes: 2 additions & 0 deletions src/io/fs/PathConstants.h.in
Expand Up @@ -22,6 +22,8 @@ static str_t user_dir_prefixes = ARX_GET_STR("${USER_DIR_PREFIXES}");

static str_t config_dir_prefixes = ARX_GET_STR("${CONFIG_DIR_PREFIXES}");

static str_t ignore_exe_dir = ARX_GET_STR("${IGNORE_EXE_DIR}");

static str_t libexec_dir = ARX_GET_STR("${CMAKE_INSTALL_FULL_LIBEXECDIR}");

#undef ARX_GET_STR
Expand Down
18 changes: 18 additions & 0 deletions src/io/fs/SystemPaths.cpp
Expand Up @@ -198,6 +198,23 @@ std::vector<path> SystemPaths::getSearchPaths(bool filter) const {
}
}

// Search the executable directory
path exepath = getExecutablePath();
if(!exepath.empty()) {
path dir = canonical(exepath.parent());
bool ignored = false;
if(ignore_exe_dir) {
std::vector<path> ignored_dirs = fs::getSearchPaths(ignore_exe_dir);
ignored = (std::find(ignored_dirs.begin(), ignored_dirs.end(), dir)
!= ignored_dirs.end());
}
if(!ignored && addSearchPath(result, dir, filter)) {
LogDebug("got data dir from exe: " << exepath << " -> " << dir);
} else {
LogDebug("ignoring data dir from exe: " << exepath << " -> " << dir);
}
}

return result;
}

Expand Down Expand Up @@ -317,6 +334,7 @@ void SystemPaths::list(std::ostream & os, const std::string & forceUser,
os << forceData;
}
listDirectoriesFor(os, "DataDir", data_dir_prefixes, data_dir);
os << " - The directory containing the game executable\n";
os << "selected:";
if(data.empty()) {
os << " (none)\n";
Expand Down

0 comments on commit 6784f9b

Please sign in to comment.