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