Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/filesystem/inifile.cc')
-rw-r--r--src/filesystem/inifile.cc59
1 files changed, 39 insertions, 20 deletions
diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc
index f04d116..c76e06a 100644
--- a/src/filesystem/inifile.cc
+++ b/src/filesystem/inifile.cc
@@ -5,17 +5,17 @@
*/
// project headers
+#include "filesystem/filesystem.h"
#include "filesystem/inifile.h"
-namespace filesystem
-{
+namespace filesystem {
IniFile::IniFile() {}
IniFile::~IniFile() {}
-void IniFile::open(const char * filename, std::ios_base::openmode mode)
-{
+void IniFile::open(std::string const & name) {
+
last_read_was_section = false;
last_read_was_key = false;
key_current = "";
@@ -23,22 +23,36 @@ void IniFile::open(const char * filename, std::ios_base::openmode mode)
section_current = "";
line_number = 0;
- File::open(filename, mode);
+ std::string inifile_name("ini/");
+ inifile_name.append(name);
+ inifile_name.append(".ini");
+
+ filesystem::File *f = filesystem::open(inifile_name.c_str());
+ if (!f) {
+ return;
+ }
+
+ 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";
+ return;
+ }
}
-bool IniFile::got_section() const
-{
+bool IniFile::got_section() const {
return last_read_was_section;
}
-bool IniFile::got_section(const char * sectionlabel) const
-{
+bool IniFile::got_section(const char * sectionlabel) const {
return (last_read_was_section && section_current == sectionlabel);
}
-IniFile & IniFile::getline()
-{
+bool IniFile::getline() {
char line[1024];
last_read_was_section = false;
@@ -46,8 +60,10 @@ IniFile & IniFile::getline()
key_current = "";
value_current = "";
- while ((*this)) {
- File::getline(line, 1024);
+ if (!inifile_ifs.is_open())
+ return false;
+
+ if (inifile_ifs.getline(line, 1024)) {
std::string s(line);
line_number++;
@@ -63,7 +79,7 @@ IniFile & IniFile::getline()
// condebug << "Inifile got section header " << s << std::endl;
section_current = s.substr(1, s.size()-2);
last_read_was_section = true;
- break;
+ return true;
} else {
// key=value pair
size_t found = s.find('=');
@@ -74,18 +90,17 @@ IniFile & IniFile::getline()
if (key_current.size() > 0) {
value_current = s.substr(found+1, s.size() - found - 1);
last_read_was_key = true;
- break;
+ return true;
}
}
}
- }
-
- return (*this);
+ return true;
+ } else
+ return false;
}
-bool IniFile::got_key_string(char * const keylabel, std::string & valuestring)
-{
+bool IniFile::got_key_string(char * const keylabel, std::string & valuestring) {
//condebug << "IniFile got_value_string " << keylabel << " " << last_read_was_key << std::endl;
if (last_read_was_key && key_current == keylabel) {
valuestring.assign(value_current);
@@ -95,6 +110,10 @@ bool IniFile::got_key_string(char * const keylabel, std::string & valuestring)
}
}
+void IniFile::close()
+{
+ inifile_ifs.close();
+}
} // namespace filesystem