Skip to content

Commit

Permalink
Consider <exe loc or cwd>/../ as a candidate for data dir autodetection
Browse files Browse the repository at this point in the history
Makes it so <exe location>/../ (non-Windows) or <current working
dir>/../ (Windows) are also considered possible data directories if they
contain a data/_main.cfg file.

This is mostly intended to help people running cmake builds so they
don't have to type out .. in the Wesnoth command line every time or use
a hard link sitting on the data dir.

Notice that scons people already benefited from the simpler version of
this autodetection, which only considered <exe loc or cwd>/./ as a
candidate. This has been the case since version 1.5.4 (more
specifically, commit 43431bc). Because
of this, most of the code for this feature was already in place and I
only rearranged it to add some helpful annotations.
  • Loading branch information
irydacea committed Jul 4, 2014
1 parent ffbf683 commit ad58361
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog
Expand Up @@ -227,6 +227,9 @@ Version 1.13.0-dev:
* Fix an inefficient implementation of unit::invisible, in an effort to address slow performance problems:
http://forums.wesnoth.org/viewtopic.php?f=4&t=12139&start=180#p569931
(Also see gfgtdf's commits trying to optimize the minimap loop)
* Made it so <exe location>/../ (non-Windows) or <current working dir>/../
(Windows) are also considered possible data directories if they contain a
data/_main.cfg file, intended to help with cmake builds.

Version 1.11.11:
* Add-ons server:
Expand Down
27 changes: 22 additions & 5 deletions src/wesnoth.cpp
Expand Up @@ -791,11 +791,28 @@ int main(int argc, char** argv)
const time_t t = time(NULL);
std::cerr << "Started on " << ctime(&t) << "\n";

const std::string exe_dir = get_exe_dir();
if(!exe_dir.empty() && file_exists(exe_dir + "/data/_main.cfg")) {
std::cerr << "Automatically found a possible data directory at "
<< exe_dir << '\n';
game_config::path = exe_dir;
const std::string& exe_dir = get_exe_dir();
if(!exe_dir.empty()) {
// Try to autodetect the location of the game data dir. Note that
// the root of the source tree currently doubles as the data dir.
std::string auto_dir;

// scons leaves the resulting binaries at the root of the source
// tree by default.
if(file_exists(exe_dir + "/data/_main.cfg")) {
auto_dir = exe_dir;
}
// cmake encourages creating a subdir at the root of the source
// tree for the build, and the resulting binaries are found in it.
else if(file_exists(exe_dir + "/../data/_main.cfg")) {
auto_dir = normalize_path(exe_dir + "/..");
}

if(!auto_dir.empty()) {
std::cerr << "Automatically found a possible data directory at "
<< auto_dir << '\n';
game_config::path = auto_dir;
}
}

const int res = do_gameloop(argc,argv);
Expand Down

0 comments on commit ad58361

Please sign in to comment.