Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-02-23 21:00:44 +0000
committerStijn Buys <ingar@osirion.org>2009-02-23 21:00:44 +0000
commit9cc32533d081731171cfd8380044b60cee6f0f10 (patch)
tree918d4ebaf9ed6e56cb830a9e8908c403f2bb10c4 /src
parent22052f28695172a7c790f37aa827040c3bb2ec39 (diff)
Search the location of the binary for the data/ directory
Diffstat (limited to 'src')
-rw-r--r--src/core/application.cc2
-rw-r--r--src/filesystem/filesystem.cc20
-rw-r--r--src/filesystem/filesystem.h2
3 files changed, 18 insertions, 6 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index 248512e..4132c33 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -97,7 +97,7 @@ void Application::init(int count, char **arguments)
con_print << "^BInitializing core...\n";
con_debug << " debug messages enabled\n";
- filesystem::init("base", "");
+ filesystem::init(arguments[0], "base", "");
Loader::load("base");
CommandBuffer::init();
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<std::string> 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();