Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/filesystem/filesystem.cc')
-rw-r--r--src/filesystem/filesystem.cc145
1 files changed, 118 insertions, 27 deletions
diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc
index dd694ee..1cb13e9 100644
--- a/src/filesystem/filesystem.cc
+++ b/src/filesystem/filesystem.cc
@@ -5,6 +5,7 @@
*/
// project headers
+#include <list>
#include "filesystem/filesystem.h"
#include "filesystem/diskfile.h"
@@ -14,49 +15,139 @@
namespace filesystem
{
-std::string datadir = "";
-std::string homedir = "";
-std::string basedir = "";
-std::string moddir = "";
-std::string writedir = "";
+SearchPath filesystem_searchpath;
+std::string filesystem_basename;
+std::string filesystem_modname;
-void init()
+std::string filesystem_homedir;
+std::string filesystem_writedir;
+std::string filesystem_datadir;
+
+std::string const & writedir()
{
- con_print << "^BInitializing filesystem..." << std::endl;
+ return filesystem_writedir;
+}
- // initialize game data locations
- // FIXME datadir should by set by ./configure and read from config.h
- datadir = "./data/";
+std::string const & homedir()
+{
+ return filesystem_homedir;
+}
- // FIXME a local or remote game module must be able to set these
- basedir = "base/";
- moddir = "";
+SearchPath & searchpath()
+{
+ return filesystem_searchpath;
+}
+void init(std::string const & basename, std::string const & modname)
+{
+ con_print << "^BInitializing filesystem..." << std::endl;
+
+ // clear everything
+ filesystem_searchpath.clear();
+ filesystem_basename.assign(basename);
+ if (!filesystem_basename.size())
+ filesystem_basename.assign("base");
+
+ filesystem_modname.assign(modname);
#ifndef _WIN32
- homedir = getenv("HOME");
- homedir = homedir + "/.osirion/";
+ filesystem_homedir.assign(getenv("HOME"));
+ filesystem_homedir.append("/.osirion/");
#else
// FIXME win32
- homedir = "./home/";
+ filesystem_homedir.assign("./home/");
#endif
-
- sys::mkdir(homedir);
- sys::mkdir(homedir+basedir);
-
- writedir = homedir;
- if (moddir.size()) {
- writedir.append(moddir);
- } else
- writedir.append(basedir);
- sys::mkdir(writedir);
+ std::string current_datadir("data/");
+ std::string package_datadir(PACKAGE_DATADIR);
+ std::string dir;
- con_print << " files are created in " << writedir << std::endl;
+ // set writedir depending on modname and add home paths to the searchpath
+ filesystem_writedir.assign(filesystem_homedir);
+ if (filesystem_modname.size()) {
+ // append modname to writedir
+ filesystem_writedir.append(filesystem_modname);
+ filesystem_writedir += '/';
+ } else {
+ // append basename to writedir
+ filesystem_writedir.append(filesystem_basename);
+ filesystem_writedir += '/';
+ }
+
+ sys::mkdir(filesystem_homedir);
+ sys::mkdir(filesystem_writedir);
+
+
+ // modname search path
+ if (filesystem_modname.size()) {
+ // HOME/modname
+ dir.assign(filesystem_homedir + filesystem_modname);
+ if (sys::isdirectory(dir)) {
+ dir += '/';
+ filesystem_searchpath.push_back(dir);
+ }
+
+ // CURRENT/data/modname
+ dir.assign(current_datadir + filesystem_modname);
+ if (sys::isdirectory(dir)) {
+ dir += '/';
+ filesystem_searchpath.push_back(dir);
+ }
+
+ // PACKAGE_DATADIR/modname
+ std::string dir(package_datadir + '/' + filesystem_modname);
+ if (sys::isdirectory(dir)) {
+ dir += '/';
+ filesystem_searchpath.push_back(dir);
+ }
+ }
+
+ // basename search path
+ // HOME/basename
+ dir.assign(filesystem_homedir + filesystem_basename);
+ if (sys::isdirectory(dir)) {
+ dir += '/';
+ filesystem_searchpath.push_back(dir);
+ }
+
+ // PACKAGE_DATADIR/basename
+ dir.assign(package_datadir + '/' + filesystem_basename);
+ if (sys::isdirectory(dir)) {
+ dir += '/';
+ filesystem_searchpath.push_back(dir);
+ filesystem_datadir.assign(dir);
+ } else {
+ // CURRENT/data/basename
+ dir.assign(current_datadir + filesystem_basename);
+ if (sys::isdirectory(dir)) {
+ dir += '/';
+ filesystem_searchpath.push_back(dir);
+ filesystem_datadir.assign(dir);
+ } else {
+ con_warn << "data/" << basename << " not found!" << std::endl;
+ }
+ }
+
+ // print search path
+ for (SearchPath::iterator path = filesystem_searchpath.begin(); path != filesystem_searchpath.end(); ++path) {
+ con_print << " " << (*path) << std::endl;
+ }
+ con_print << " " << filesystem_searchpath.size() << " directories added to searchpath" << std::endl;
+
+ // create writedir
+ con_print << " files are created in " << filesystem_writedir << std::endl;
}
void shutdown()
{
con_print << "^BShutting down filesystem..." << std::endl;
+
+ filesystem_searchpath.clear();
+ filesystem_basename.clear();
+
+ filesystem_modname.clear();
+ filesystem_homedir.clear();
+
+ filesystem_writedir.clear();
}
File *open(const char *filename)