Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/filesystem/filestream.cc9
-rw-r--r--src/filesystem/filestream.h8
-rw-r--r--src/filesystem/inifile.cc61
-rw-r--r--src/filesystem/inifile.h32
-rw-r--r--src/model/map.cc19
-rw-r--r--src/model/map.h4
6 files changed, 75 insertions, 58 deletions
diff --git a/src/filesystem/filestream.cc b/src/filesystem/filestream.cc
index 693d1c1..cfbaaec 100644
--- a/src/filesystem/filestream.cc
+++ b/src/filesystem/filestream.cc
@@ -44,9 +44,12 @@ void IFileStream::open(const char *name)
if (fstream_filename[i] == '/') fstream_filename[i] = '\\';
#endif
*/
- std::ifstream::open(fstream_filename.c_str());
- if (good())
- return;
+
+ if (sys::file_exists(fstream_filename)) {
+ std::ifstream::open(fstream_filename.c_str());
+ if (good())
+ return;
+ }
}
fstream_filename.clear();
diff --git a/src/filesystem/filestream.h b/src/filesystem/filestream.h
index 7dddda9..9739f38 100644
--- a/src/filesystem/filestream.h
+++ b/src/filesystem/filestream.h
@@ -18,7 +18,7 @@ namespace filesystem
class IFileStream : public std::ifstream
{
public:
- IFileStream(const char *name);
+ IFileStream(const char *name = 0);
IFileStream(const std::string &name);
@@ -27,10 +27,10 @@ public:
void open(const std::string &name);
/// name of the file in the virtual filesystem
- inline const std::string &name() { return fstream_name; }
+ inline const std::string &name() const { return fstream_name; }
- /// system filename
- inline const std::string &filename() { return fstream_filename; }
+ /// actual dilename
+ inline const std::string &filename() const { return fstream_filename; }
private:
std::string fstream_name;
diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc
index e83c08f..c6cc625 100644
--- a/src/filesystem/inifile.cc
+++ b/src/filesystem/inifile.cc
@@ -13,11 +13,37 @@
namespace filesystem {
-IniFile::IniFile() {}
+IniFile::IniFile(const char *ininame)
+{
+ if (ininame)
+ open(ininame);
+}
+
+IniFile::IniFile(const std::string & ininame)
+{
+ if (ininame.size())
+ open(ininame.c_str());
+}
+
+IniFile::~IniFile()
+{
+ if (inifile_stream.is_open())
+ inifile_stream.close();
+}
+
+bool IniFile::open(std::string const & ininame)
+{
+ return open(ininame.c_str());
+}
-IniFile::~IniFile() {}
+bool IniFile::open(const char *ininame)
+{
-bool IniFile::open(std::string const & name) {
+ if (!ininame)
+ return false;
+
+ if (inifile_stream.is_open())
+ return false;
last_read_was_section = false;
last_read_was_key = false;
@@ -26,26 +52,15 @@ bool IniFile::open(std::string const & name) {
section_current = "";
line_number = 0;
- inifile_name.assign("ini/");
- inifile_name.append(name);
+ std::string inifile_name("ini/");
+ inifile_name.append(ininame);
inifile_name.append(".ini");
-
- filesystem::File *f = filesystem::open(inifile_name.c_str());
- if (!f) {
- con_warn << "Could not open " << inifile_name << std::endl;
- return false;
- }
-
- std::string fn = f->path();
- fn.append(f->name());
- filesystem::close(f);
-
- inifile_ifs.open(fn.c_str());
- if (!inifile_ifs.is_open()) {
- con_warn << "Could not stream " << fn << "!\n";
+
+ inifile_stream.open(inifile_name);
+ if (!inifile_stream.good()) {
+ con_warn << "Could not open " << inifile_stream.name() << "!\n";
return false;
}
-
return true;
}
@@ -70,10 +85,10 @@ bool IniFile::getline() {
key_current = "";
value_current = "";
- if (!inifile_ifs.is_open())
+ if (!inifile_stream.is_open())
return false;
- if (inifile_ifs.getline(line, 1023)) {
+ if (inifile_stream.getline(line, 1023)) {
std::string s(line);
aux::trim(s);
line_number++;
@@ -266,7 +281,7 @@ void IniFile::unknown_section() const
void IniFile::close()
{
- inifile_ifs.close();
+ inifile_stream.close();
}
} // namespace filesystem
diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h
index f064bc7..09f6ebb 100644
--- a/src/filesystem/inifile.h
+++ b/src/filesystem/inifile.h
@@ -12,7 +12,7 @@
#include "math/vector3f.h"
#include "math/color.h"
-#include "filesystem/file.h"
+#include "filesystem/filestream.h"
namespace filesystem {
@@ -23,13 +23,17 @@ namespace filesystem {
*/
class IniFile {
public:
- IniFile();
+ IniFile(const char *ininame = 0);
+
+ IniFile(std::string const & ininame);
+
~IniFile();
- /// open the file for reading
- /** the filename will get the "ini/" prefix and ".ini" suffix
- */
- bool open(std::string const & name);
+ /// open an ini file for reading
+ bool open(std::string const & ininame);
+
+ /// open an ini file for reading
+ bool open(const char *ininame);
/// parse one line, returns false on end-of-file
bool getline();
@@ -93,10 +97,16 @@ public:
void unknown_section() const;
/// return true of the ini file is open for reading
- inline bool is_open() { return inifile_ifs.is_open(); }
+ inline bool is_open() const { return inifile_stream.is_open(); }
- /// current filename
- inline std::string const & name() const {return inifile_name; }
+ /// return true of the ini file is open for reading
+ inline bool good() const { return inifile_stream.good(); }
+
+ /// current name in the virtual filesystem
+ inline std::string const & name() const {return inifile_stream.name(); }
+
+ /// current actual filename
+ inline std::string const & filename() const { return inifile_stream.filename(); }
/// close the file
void close();
@@ -110,8 +120,8 @@ private:
bool last_read_was_section;
unsigned int line_number;
- std::ifstream inifile_ifs;
- std::string inifile_name;
+
+ IFileStream inifile_stream;
};
}
diff --git a/src/model/map.cc b/src/model/map.cc
index 9a1802f..45ae3fd 100644
--- a/src/model/map.cc
+++ b/src/model/map.cc
@@ -52,7 +52,7 @@ void Map::clear_materials()
map_materials.clear();
}
-bool Map::open(std::string const & name)
+bool Map::open(std::string const & mapname)
{
last_read_was_classname = false;
@@ -66,25 +66,14 @@ bool Map::open(std::string const & name)
clear_materials();
mapfile_name.assign("maps/");
- mapfile_name.append(name);
+ mapfile_name.append(mapname);
mapfile_name.append(".map");
- filesystem::File *f = filesystem::open(mapfile_name.c_str());
- if (!f) {
- con_warn << "Could not open " << mapfile_name << std::endl;
- return false;
- }
-
- std::string fn = f->path();
- fn.append(f->name());
- filesystem::close(f);
-
- mapfile_ifs.open(fn.c_str());
+ mapfile_ifs.open(mapfile_name);
if (!mapfile_ifs.is_open()) {
- con_warn << "Could not stream " << fn << "!\n";
+ con_warn << "Could not open " << mapfile_name << "!\n";
return false;
}
-
return true;
}
diff --git a/src/model/map.h b/src/model/map.h
index b46be7c..e38b9ec 100644
--- a/src/model/map.h
+++ b/src/model/map.h
@@ -7,13 +7,13 @@
#ifndef __INCLUDED_MODEL_MAP_H__
#define __INCLUDED_MODEL_MAP_H__
-#include <fstream>
#include <string>
#include <vector>
#include "model/model.h"
#include "model/plane.h"
#include "model/primitives.h"
+#include "filesystem/filestream.h"
namespace model
{
@@ -167,7 +167,7 @@ private:
unsigned int parse_level;
unsigned int line_number;
- std::ifstream mapfile_ifs;
+ filesystem::IFileStream mapfile_ifs;
std::string mapfile_name;
math::Vector3f class_maxbbox;