/* filesystem/filesystem.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 "filesystem/filesystem.h" #include "filesystem/diskfile.h" #include "filesystem/file.h" #include "sys/sys.h" namespace filesystem { std::string datadir = ""; std::string homedir = ""; std::string basedir = ""; std::string moddir = ""; std::string writedir = ""; void init() { con_print << "Initializing filesystem..." << std::endl; // FIXME datadir should by set by ./configure and read from config.h // initialize game data locations datadir = "./data/"; basedir = "base/"; moddir = ""; // FIXME win32 #ifndef _WIN32 homedir = getenv("HOME"); homedir = homedir + "/.osirion/"; #else homedir = "./home/"; #endif sys::mkdir(homedir); sys::mkdir(homedir+basedir); writedir = homedir; if (moddir.size()) { writedir.append(moddir); } else writedir.append(basedir); sys::mkdir(writedir); con_print << " files are created in " << writedir << std::endl; } void shutdown() { con_print << "Shutting down filesystem..." << std::endl; } File *open(const char *filename) { // for now, File is always a DiskFile DiskFile *f = new DiskFile(); if (!f->open(filename)) { delete f; f = 0; return 0; } return f; } void close(File *file) { if (!file) return; file->close(); delete file; } }