From 9cc32533d081731171cfd8380044b60cee6f0f10 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 23 Feb 2009 21:00:44 +0000 Subject: Search the location of the binary for the data/ directory --- src/filesystem/filesystem.cc | 20 ++++++++++++++++---- src/filesystem/filesystem.h | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/filesystem') diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index 11ece3c..d268ccc 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -45,8 +45,7 @@ SearchPath & searchpath() { return filesystem_searchpath; } - -void init(std::string const & basename, std::string const & modname) +void init(const std::string &binaryname, const std::string & basename, const std::string & modname) { con_print << "^BInitializing filesystem..." << std::endl; @@ -95,8 +94,21 @@ void init(std::string const & basename, std::string const & modname) filesystem_homedir += '/'; } #endif - - std::string current_datadir("data/"); + + // try the data/ subdirectory of the directory where the binary is located + std::string current_datadir(binaryname); + size_t i = current_datadir.size(); + while (--i && (current_datadir[i] != '/')) { + current_datadir.erase(i, 1); + } + current_datadir.append("data/"); + + // use the data/ subdirectory of the current working directory as a fallback + if (!sys::directory_exists(current_datadir)) { + current_datadir.assign("data/"); + } + + // the data dir set by the configure script std::string package_datadir(PACKAGE_DATADIR); std::string dir; diff --git a/src/filesystem/filesystem.h b/src/filesystem/filesystem.h index b0232f2..1bdacaa 100644 --- a/src/filesystem/filesystem.h +++ b/src/filesystem/filesystem.h @@ -24,7 +24,7 @@ typedef std::list SearchPath; SearchPath & searchpath(); /// initialize the filesystem subsystem -void init(std::string const & basename, std::string const & modname); +void init(const std::string &binaryname, const std::string & basename, const std::string & modname); /// shutdown the filesystem subsystem void shutdown(); -- cgit v1.2.3