Skip to content

Commit

Permalink
Made wesnoth set data path to directory in which it's located...
Browse files Browse the repository at this point in the history
...if data/_main.cfg exists in it.
  • Loading branch information
loonycyborg committed Aug 24, 2008
1 parent 9a82cd7 commit 43431bc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#else /* !_WIN32 */
#include <unistd.h>
#include <dirent.h>
#include <libgen.h>
#endif /* !_WIN32 */

#ifdef __BEOS__
Expand Down Expand Up @@ -405,6 +406,20 @@ std::string get_cwd()
}
}

std::string get_exe_dir()
{
#ifndef _WIN32
char buf[1024];
size_t path_size = readlink("/proc/self/exe", buf, 1024);
if(path_size == -1)
return std::string();
buf[path_size] = 0;
return std::string(dirname(buf));
#else
return std::string();
#endif
}

bool create_directory_if_missing(const std::string& dirname)
{
if(is_directory(dirname)) {
Expand Down
1 change: 1 addition & 0 deletions src/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ std::string get_upload_dir();
const std::string& get_user_data_dir();

std::string get_cwd();
std::string get_exe_dir();

bool make_directory(const std::string& dirname);
bool delete_directory(const std::string& dirname);
Expand Down
7 changes: 7 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,13 @@ int main(int argc, char** argv)
} else {
std::cerr << "Wesnoth doesn't have the name wesnoth, so can't locate the server.\n";
}

std::string exe_dir = get_exe_dir();
if(!exe_dir.empty() && file_exists(exe_dir + "/data/_main.cfg")) {
std::cerr << "Found a data directory at " + exe_dir + ", setting path to it.\n";
game_config::path = exe_dir;
}

std::cerr << "Battle for Wesnoth v" << game_config::revision << '\n';
time_t t = time(NULL);
std::cerr << "Started on " << ctime(&t) << "\n";
Expand Down

0 comments on commit 43431bc

Please sign in to comment.