From 43b994017a560a2fa97894ebfe121375d6614b6f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 3 Feb 2008 18:53:40 +0000 Subject: basic client console --- src/filesystem/Makefile.am | 4 ++-- src/filesystem/file.cc | 6 ++++++ src/filesystem/file.h | 6 ++++++ src/filesystem/filesystem.cc | 4 ++-- src/filesystem/vfile.cc | 24 ++++++++++++++++++++++++ src/filesystem/vfile.h | 31 +++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/filesystem/vfile.cc create mode 100644 src/filesystem/vfile.h (limited to 'src/filesystem') diff --git a/src/filesystem/Makefile.am b/src/filesystem/Makefile.am index a490cd3..65540f1 100644 --- a/src/filesystem/Makefile.am +++ b/src/filesystem/Makefile.am @@ -1,9 +1,9 @@ METASOURCES = AUTO -libfilesystem_la_SOURCES = file.cc filesystem.cc inifile.cc path.cc +libfilesystem_la_SOURCES = file.cc filesystem.cc inifile.cc path.cc vfile.cc libfilesystem_la_LDFLAGS = -avoid-version -no-undefined libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la noinst_LTLIBRARIES = libfilesystem.la -noinst_HEADERS = file.h filesystem.h inifile.h path.h +noinst_HEADERS = file.h filesystem.h inifile.h path.h vfile.h INCLUDES = -I$(top_srcdir)/src diff --git a/src/filesystem/file.cc b/src/filesystem/file.cc index cd6ae1b..1203d5a 100644 --- a/src/filesystem/file.cc +++ b/src/filesystem/file.cc @@ -17,6 +17,8 @@ File::~File() {} void File::open(const char * filename, ios_base::openmode mode) { file_name.assign(filename); std::string fn; + + real_name.clear(); // if moddir is set, try the mods subdir first if (moddir.size()) { @@ -26,6 +28,7 @@ void File::open(const char * filename, ios_base::openmode mode) { fn.append(filename); std::ifstream::open(fn.c_str(), mode); if (this->is_open()) { + real_name = fn; con_debug << "File opened " << fn << std::endl; return; } @@ -36,6 +39,7 @@ void File::open(const char * filename, ios_base::openmode mode) { std::ifstream::open(fn.c_str(), mode); if (this->is_open()) { con_debug << "File opened " << fn << std::endl; + real_name = fn; return; } } @@ -47,6 +51,7 @@ void File::open(const char * filename, ios_base::openmode mode) { std::ifstream::open(fn.c_str(), mode); if (this->is_open()) { con_debug << "File opened " << fn << std::endl; + real_name = fn; return; } @@ -60,6 +65,7 @@ void File::open(const char * filename, ios_base::openmode mode) { con_warn << "Could not open " << filename << std::endl; } else { con_debug << "File opened " << fn << std::endl; + real_name = fn; } } diff --git a/src/filesystem/file.h b/src/filesystem/file.h index aaafd01..ba392de 100644 --- a/src/filesystem/file.h +++ b/src/filesystem/file.h @@ -26,9 +26,15 @@ public: inline std::string name() { return file_name; } + + /// current full path + inline std::string path() { + return real_name; + } private: std::string file_name; + std::string real_name; } ; // class File diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index b720198..5d3ed40 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -14,7 +14,7 @@ std::string filesystem::basedir = ""; std::string filesystem::moddir = ""; void filesystem::init() { - con_debug << "Initializing filesystem..." << std::endl; + con_print << "Initializing filesystem..." << std::endl; // FIXME datadir should by set by ./configure and read from config.h @@ -33,6 +33,6 @@ void filesystem::init() { } void filesystem::shutdown() { - con_debug << "Shutting down filesystem..." << std::endl; + con_print << "Shutting down filesystem..." << std::endl; } diff --git a/src/filesystem/vfile.cc b/src/filesystem/vfile.cc new file mode 100644 index 0000000..9fcb2b3 --- /dev/null +++ b/src/filesystem/vfile.cc @@ -0,0 +1,24 @@ +/* + filesystem/vfile.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/vfile.h" + +namespace filesystem +{ + +std::string VFile::find(const char *filename) +{ + return std::string(); +} + + +bool VFile::exists(const char *filename) +{ + return (find(filename).size() == 0); +} + +} diff --git a/src/filesystem/vfile.h b/src/filesystem/vfile.h new file mode 100644 index 0000000..a64dbc6 --- /dev/null +++ b/src/filesystem/vfile.h @@ -0,0 +1,31 @@ +/* + filesystem/vfile.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_FILESYSTEM_VFILE_H__ +#define __INCLUDED_FILESYSTEM_VFILE_H__ + +// project headers +#include "filesystem/filesystem.h" + +namespace filesystem { + +/// a file in the virtual file system +class VFile { + +public: + /// search the path for a file in the virtual + /** If the file can not be found in any of the data directories, + * an empty string will be returned + */ + static std::string find(const char *filename); + + /// returns true if a file exists in the virtual filesystem + static bool exists(const char *filename); +}; + +} + +#endif //__INCLUDED_FILESYSTEM_VFILE_H__ -- cgit v1.2.3