From 97cbb7514135ec81803e746f0b549e9f95abbecc Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 21 Oct 2007 15:18:50 +0000 Subject: added basic file loader --- src/game/file.cc | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/game/file.cc (limited to 'src/game/file.cc') diff --git a/src/game/file.cc b/src/game/file.cc new file mode 100644 index 0000000..b819416 --- /dev/null +++ b/src/game/file.cc @@ -0,0 +1,61 @@ +/* file.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 "file.h" + +namespace game { + +void File::open(const char * filename, ios_base::openmode mode) +{ + std::string fn; + + // if moddir is set, try the mods subdir first + if (game::moddir.size() > 0) { + // try game::homedir+game::moddir + fn = homedir; + fn.append(moddir); + fn.append(filename); + std::ifstream::open(fn.c_str(), mode); + if (this->is_open()) { + std::cerr << "game::File opened " << fn << std::endl; + return; + } + + // try datadir + moddir + fn = game::datadir; + fn.append(game::moddir); + std::ifstream::open(fn.c_str(), mode); + if (this->is_open()) { + std::cerr << "game::File opened " << fn << std::endl; + return; + } + } + + // try game::homedir+game::basedir + fn = homedir; + fn.append(basedir); + fn.append(filename); + std::ifstream::open(fn.c_str(), mode); + if (this->is_open()) { + std::cerr << "game::File opened " << fn << std::endl; + return; + } + + // try game::datadir+game::basedir + fn = datadir; + fn.append(basedir); + fn.append(filename); + std::ifstream::open(fn.c_str(), mode); + + // FIXME console + if (!this->is_open()) { + std::cerr << "game::File could not open " << filename << std::endl; + } else { + std::cerr << "game::File opened " << fn << std::endl; + } +} + +} -- cgit v1.2.3