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>2007-12-17 14:47:30 +0000
committerStijn Buys <ingar@osirion.org>2007-12-17 14:47:30 +0000
commit09f307b6cb4f7c69e5b0685acc0bdd18e9d57d40 (patch)
tree08c5c8e1e516413278db3817dd89749cc3dbdac3 /src
parent8f1e895de4986e3a953023b31840210c5555856e (diff)
home directory creation
Diffstat (limited to 'src')
-rw-r--r--src/common/path.cc40
-rw-r--r--src/common/path.h26
-rw-r--r--src/game/game.cc13
3 files changed, 76 insertions, 3 deletions
diff --git a/src/common/path.cc b/src/common/path.cc
new file mode 100644
index 0000000..d9fc332
--- /dev/null
+++ b/src/common/path.cc
@@ -0,0 +1,40 @@
+/*
+ common/path.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+// project headers
+#include "path.h"
+#include "console.h"
+
+#ifdef _WIN32
+#include <dlfcn.h>
+#else
+#include <sys/stat.h>
+#endif
+
+namespace common {
+
+void Path::create(std::string path)
+{
+ std::string tmp(path);
+ if (tmp[tmp.size()-1] == '/')
+ tmp = tmp.substr(0, tmp.size() - 1);
+
+#ifdef _WIN32
+ mkdir(tmp.c_str());
+#else
+ if (!mkdir(tmp.c_str(), 0777))
+ conwarn << "Could not create directory " << tmp << std::endl;
+ else
+ condebug << "Path created " << tmp << std::endl;
+#endif
+}
+
+bool Path::exists(std::string path)
+{
+ return false;
+}
+
+}
diff --git a/src/common/path.h b/src/common/path.h
new file mode 100644
index 0000000..43b07d2
--- /dev/null
+++ b/src/common/path.h
@@ -0,0 +1,26 @@
+/*
+ common/path.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_PATH_H__
+#define __INCLUDED_PATH_H__
+
+// C++ headers
+#include <string>
+#include <fstream>
+
+namespace common {
+
+/// a class to create directories
+class Path
+{
+public:
+ static bool exists(std::string path);
+ static void create(std::string path);
+}; // class Path
+
+} // namespace common
+
+#endif // __INCLUDED_PATH_H__
diff --git a/src/game/game.cc b/src/game/game.cc
index cbde6b0..cd80889 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -11,6 +11,7 @@
#include "common/console.h"
#include "common/inifile.h"
+#include "common/path.h"
#include "osirion.h"
@@ -35,6 +36,7 @@ std::vector<Sector*> sectors;
void init()
{
using common::File;
+ using common::Path;
using common::IniFile;
using common::Vector3f;
@@ -42,11 +44,16 @@ void init()
condebug << "Debug messages enabled" << std::endl;
// initialize game data locations
- // TODO create game::homedir if it doesn't exist
- File::datadir = "./data/";
- File::homedir = "~/.osirion/";
+ File::datadir = "./data/";
File::basedir = "base/";
File::moddir = "";
+
+ // FIXME win32
+ File::homedir = getenv("HOME");
+ File::homedir = File::homedir + "/.osirion/";
+ Path::create(File::homedir);
+ Path::create(File::homedir+File::basedir);
+ if (File::moddir.size()) Path::create(File::homedir+File::moddir);
// read game.ini
IniFile f;