[Scummvm-git-logs] scummvm master -> 4567eefaaac9036e34a48bc013873ccfbe2cf345
OMGPizzaGuy
48367439+OMGPizzaGuy at users.noreply.github.com
Thu Feb 4 01:46:51 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4567eefaaa ULTIMA8: Replace custom ini file handling with Common::INIFile
Commit: 4567eefaaac9036e34a48bc013873ccfbe2cf345
https://github.com/scummvm/scummvm/commit/4567eefaaac9036e34a48bc013873ccfbe2cf345
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2021-02-03T19:46:26-06:00
Commit Message:
ULTIMA8: Replace custom ini file handling with Common::INIFile
This change also removes the pathed keys in favor of distinct category and section variables.
Changed paths:
R engines/ultima/ultima8/conf/ini_file.cpp
R engines/ultima/ultima8/conf/ini_file.h
engines/ultima/module.mk
engines/ultima/ultima8/conf/config_file_manager.cpp
engines/ultima/ultima8/conf/config_file_manager.h
engines/ultima/ultima8/games/game_data.cpp
engines/ultima/ultima8/games/game_data.h
engines/ultima/ultima8/games/treasure_loader.cpp
engines/ultima/ultima8/graphics/fonts/font_shape_archive.cpp
engines/ultima/ultima8/graphics/type_flags.cpp
diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index 5a95e8e609..1a3f850cf4 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -393,7 +393,6 @@ MODULE_OBJS := \
ultima8/audio/speech_flex.o \
ultima8/audio/u8_music_process.o \
ultima8/conf/config_file_manager.o \
- ultima8/conf/ini_file.o \
ultima8/convert/convert_shape.o \
ultima8/convert/u8/convert_shape_u8.o \
ultima8/convert/crusader/convert_shape_crusader.o \
diff --git a/engines/ultima/ultima8/conf/config_file_manager.cpp b/engines/ultima/ultima8/conf/config_file_manager.cpp
index 468ade7cbd..00bebe7c84 100644
--- a/engines/ultima/ultima8/conf/config_file_manager.cpp
+++ b/engines/ultima/ultima8/conf/config_file_manager.cpp
@@ -22,6 +22,7 @@
#include "ultima/ultima8/misc/pent_include.h"
#include "ultima/ultima8/conf/config_file_manager.h"
+#include "ultima/ultima8/filesys/file_system.h"
namespace Ultima {
namespace Ultima8 {
@@ -43,113 +44,108 @@ ConfigFileManager::~ConfigFileManager() {
_configFileManager = nullptr;
}
-bool ConfigFileManager::readConfigFile(string fname, istring root) {
- INIFile *inifile = new INIFile();
- inifile->clear(root);
- if (!inifile->readConfigFile(fname)) {
- delete inifile;
+bool ConfigFileManager::readConfigFile(string fname, const istring &category) {
+ IDataSource *f = FileSystem::get_instance()->ReadFile(fname, true);
+ if (!f) return false;
+
+ ConfigFile *configFile = new ConfigFile();
+ configFile->_category = category;
+
+ if (!configFile->_iniFile.loadFromStream(*f)) {
+ delete configFile;
return false;
}
- _iniFiles.push_back(inifile);
+ _configFiles.push_back(configFile);
return true;
}
void ConfigFileManager::clear() {
- for (Std::vector<INIFile *>::iterator i = _iniFiles.begin();
- i != _iniFiles.end(); ++i) {
+ Std::vector<ConfigFile*>::iterator i;
+ for (i = _configFiles.begin(); i != _configFiles.end(); ++i) {
delete(*i);
}
- _iniFiles.clear();
+ _configFiles.clear();
}
-void ConfigFileManager::clearRoot(istring root) {
- Std::vector<INIFile *>::iterator i = _iniFiles.begin();
+void ConfigFileManager::clearRoot(const istring &category) {
+ Std::vector<ConfigFile *>::iterator i = _configFiles.begin();
- while (i != _iniFiles.end()) {
- if ((*i)->checkRoot(root)) {
+ while (i != _configFiles.end()) {
+ if ((*i)->_category == category) {
delete(*i);
- i = _iniFiles.erase(i);
+ i = _configFiles.erase(i);
} else {
++i;
}
}
}
-bool ConfigFileManager::exists(istring key) {
- return (findKeyINI(key) != nullptr);
-}
-
-bool ConfigFileManager::get(istring key, string &ret) {
- INIFile *ini = findKeyINI(key);
- if (!ini) return false;
+bool ConfigFileManager::get(const istring &category, const istring §ion, const istring &key, string &ret) {
+ Std::vector<ConfigFile*>::reverse_iterator i;
+ for (i = _configFiles.rbegin(); i != _configFiles.rend(); ++i) {
+ if ((*i)->_category == category) {
+ if ((*i)->_iniFile.getKey(key, section, ret)) {
+ return true;
+ }
+ }
+ }
- ini->value(key, ret);
- return true;
+ return false;
}
-bool ConfigFileManager::get(istring key, int &ret) {
- INIFile *ini = findKeyINI(key);
- if (!ini) return false;
+bool ConfigFileManager::get(const istring &category, const istring §ion, const istring &key, int &ret) {
+ string stringval;
+ if (!get(category, section, key, stringval))
+ return false;
- ini->value(key, ret);
+ ret = strtol(stringval.c_str(), 0, 0);
return true;
}
-bool ConfigFileManager::get(istring key, bool &ret) {
- INIFile *ini = findKeyINI(key);
- if (!ini) return false;
+bool ConfigFileManager::get(const istring &category, const istring §ion, const istring &key, bool &ret) {
+ string stringval;
+ if (!get(category, section, key, stringval))
+ return false;
- ini->value(key, ret);
+ ret = (stringval == "yes" || stringval == "true");
return true;
}
-Std::vector<istring> ConfigFileManager::listSections(istring root,
- bool longformat) {
+Std::vector<istring> ConfigFileManager::listSections(const istring &category) {
Std::vector<istring> sections;
-
- Std::set<istring> sectionset;
- Std::set<istring>::iterator iter;
-
- for (Std::vector<INIFile *>::iterator i = _iniFiles.begin();
- i != _iniFiles.end(); ++i) {
- if ((*i)->checkRoot(root)) {
- (*i)->listSections(sectionset, longformat);
+ Std::vector<ConfigFile*>::const_iterator i;
+
+ for ( i = _configFiles.begin(); i != _configFiles.end(); ++i) {
+ if ((*i)->_category == category) {
+ Common::INIFile::SectionList sectionList = (*i)->_iniFile.getSections();
+ Common::INIFile::SectionList::const_iterator j;
+ for (j = sectionList.begin(); j != sectionList.end(); ++j) {
+ sections.push_back(j->name);
+ }
}
}
- for (iter = sectionset.begin(); iter != sectionset.end(); ++iter) {
- sections.push_back(*iter);
- }
-
return sections;
}
-KeyMap ConfigFileManager::listKeyValues(istring section,
- bool longformat) {
+KeyMap ConfigFileManager::listKeyValues(const istring &category, const istring §ion) {
KeyMap values;
-
- for (Std::vector<INIFile *>::iterator i = _iniFiles.begin();
- i != _iniFiles.end(); ++i) {
- if ((*i)->checkRoot(section)) {
- (*i)->listKeyValues(values, section, longformat);
+ Std::vector<ConfigFile*>::const_iterator i;
+
+ for (i = _configFiles.begin(); i != _configFiles.end(); ++i) {
+ if ((*i)->_category == category) {
+ Common::INIFile::SectionKeyList keys = (*i)->_iniFile.getKeys(section);
+ Common::INIFile::SectionKeyList::const_iterator j;
+ for (j = keys.begin(); j != keys.end(); ++j) {
+ values[j->key] = j->value;
+ }
}
}
return values;
}
-
-INIFile *ConfigFileManager::findKeyINI(istring key) {
- for (Std::vector<INIFile *>::reverse_iterator i = _iniFiles.rbegin();
- i != _iniFiles.rend(); ++i) {
- if ((*i)->hasKey(key))
- return (*i);
- }
-
- return nullptr;
-}
-
} // End of namespace Ultima8
} // End of namespace Ultima
diff --git a/engines/ultima/ultima8/conf/config_file_manager.h b/engines/ultima/ultima8/conf/config_file_manager.h
index 503f18f8f4..7c51f72180 100644
--- a/engines/ultima/ultima8/conf/config_file_manager.h
+++ b/engines/ultima/ultima8/conf/config_file_manager.h
@@ -23,19 +23,26 @@
#ifndef ULTIMA8_CONF_CONFIGFILEMANAGER_H
#define ULTIMA8_CONF_CONFIGFILEMANAGER_H
+#include "common/ini-file.h"
#include "ultima/shared/std/string.h"
#include "ultima/ultima8/misc/istring.h"
#include "ultima/shared/std/containers.h"
-#include "ultima/ultima8/conf/ini_file.h"
namespace Ultima {
namespace Ultima8 {
+typedef Std::map<istring, Std::string, Common::IgnoreCase_Hash> KeyMap;
+
class ConfigFileManager {
public:
ConfigFileManager();
~ConfigFileManager();
+ struct ConfigFile {
+ istring _category;
+ Common::INIFile _iniFile;
+ };
+
static ConfigFileManager *get_instance() {
return _configFileManager;
}
@@ -45,42 +52,33 @@ public:
//! \param root The name of the root node in the file
//! \param readonly If true, don't write to this file's tree (or the file)
//! \return true if succesful
- bool readConfigFile(Std::string fname, istring root);
+ bool readConfigFile(Std::string fname, const istring &category);
//! clear everything
void clear();
//! clear everything in a root
- void clearRoot(istring root);
-
- //! does the key exist?
- bool exists(istring key);
+ void clearRoot(const istring &category);
//! get value
- bool get(istring key, Std::string &ret);
+ bool get(const istring &category, const istring §ion, const istring &key, Std::string &ret);
//! get value
- bool get(istring key, int &ret);
+ bool get(const istring &category, const istring §ion, const istring &key, int &ret);
//! get value
- bool get(istring, bool &ret);
+ bool get(const istring &category, const istring §ion, const istring &key, bool &ret);
//! list all sections
- //! \param root The config root to list all sections in
- //! \param longformat If true, return the full key name (including section)
+ //! \param category The config category to list all sections in
//! \return the sections. They have no guaranteed order.
- Std::vector<istring> listSections(istring root,
- bool longformat = false);
-
+ Std::vector<istring> listSections(const istring &category);
//! list all key-value pairs in the given section.
+ //! \param category The config category for the section to list
//! \param section The section to list
- //! \param longformat If true, return the full key name (including section)
//! \return the key-value pairs. They have no guaranteed order.
- KeyMap listKeyValues(istring section, bool longformat = false);
+ KeyMap listKeyValues(const istring &category, const istring §ion);
private:
-
- INIFile *findKeyINI(istring key);
-
- Std::vector<INIFile *> _iniFiles;
+ Std::vector<ConfigFile *> _configFiles;
static ConfigFileManager *_configFileManager;
};
diff --git a/engines/ultima/ultima8/conf/ini_file.cpp b/engines/ultima/ultima8/conf/ini_file.cpp
deleted file mode 100644
index fb68f28a08..0000000000
--- a/engines/ultima/ultima8/conf/ini_file.cpp
+++ /dev/null
@@ -1,491 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "ultima/ultima8/misc/pent_include.h"
-#include "ultima/ultima8/conf/ini_file.h"
-
-#include "ultima/ultima8/filesys/file_system.h"
-
-namespace Ultima {
-namespace Ultima8 {
-
-using Std::string;
-
-INIFile::INIFile()
- : _isFile(false), _readOnly(false) {
-
-}
-
-INIFile::INIFile(string fname, istring root)
- : _root(root), _isFile(false), _readOnly(false) {
- readConfigFile(fname);
-}
-
-INIFile::~INIFile() {
-}
-
-bool INIFile::Section::hasKey(istring key) {
- return (getKey(key) != nullptr);
-}
-
-INIFile::KeyValue *INIFile::Section::getKey(istring key) {
- Std::list<KeyValue>::iterator i;
- for (i = _keys.begin(); i != _keys.end(); ++i) {
- if (i->_key == key) {
- return &(*i);
- }
- }
- return nullptr;
-}
-
-void INIFile::Section::setKey(istring key, string value) {
- KeyValue *kv = getKey(key);
- if (kv) {
- kv->_value = value;
- return;
- }
-
- KeyValue newkey;
- newkey._key = key;
- newkey._value = value;
- newkey._comment = "";
- _keys.push_back(newkey);
-}
-
-void INIFile::Section::unsetKey(istring key) {
- Std::list<KeyValue>::iterator i;
- for (i = _keys.begin(); i != _keys.end(); ++i) {
- if (i->_key == key) {
- i = _keys.erase(i);
- }
- }
-}
-
-string INIFile::Section::dump() {
- string s = _comment;
- s += "[" + _name + "]\n";
- Std::list<KeyValue>::iterator i;
- for (i = _keys.begin(); i != _keys.end(); ++i) {
- s += i->_comment;
- s += i->_key + "=" + i->_value + "\n";
- }
-
- return s;
-}
-
-bool INIFile::readConfigFile(const string &fname) {
- IDataSource *f = FileSystem::get_instance()->ReadFile(fname, true);
- if (!f) return false;
-
- string sbuf, line;
- while (!f->eos()) {
- f->readline(line);
- string::size_type pos = line.findFirstOf("\n\r");
- if (pos != string::npos) {
- sbuf += line.substr(0, pos) + "\n";
- } else {
- sbuf += line + "\n";
- }
- }
-
- delete f;
-
- if (!readConfigString(sbuf))
- return false;
-
- _isFile = true; // readConfigString sets _isFile = false
- _filename = fname;
- return true;
-}
-
-
-static void rtrim(string &s) {
- string::size_type pos = s.findLastNotOf(" \t");
- if (pos != string::npos) {
- if (pos + 1 < s.size())
- s.erase(pos + 1);
- } else {
- s.clear();
- }
-}
-
-static void ltrim(string &s) {
- string::size_type pos = s.findFirstNotOf(" \t");
- if (pos != string::npos) {
- if (pos > 0)
- s.erase(0, pos - 1);
- } else {
- s.clear();
- }
-}
-
-
-// Large parts of the following function are borrowed from ScummVM's
-// config-manager.cpp, copyright (C) 2001-2004 The ScummVM project
-// http://www.scummvm.org/
-
-bool INIFile::readConfigString(string config) {
- _isFile = false;
-
- string line;
- string comment;
- unsigned int lineno = 0;
- Section section;
-
- while (!config.empty()) {
- lineno++;
-
- string::size_type pos = config.find('\n');
- if (pos != string::npos) {
- line = config.substr(0, pos);
- config.erase(0, pos + 1);
- } else {
- line = config;
- config.clear();
- }
-
- if (line.length() > 0 && line[0] == '#') {
- // Accumulate comments here. Once we encounter either the start
- // of a new section, or a key-value-pair, we associate the value
- // of the 'comment' variable with that entity.
- comment += line + "\n";
- } else if (line.length() > 0 && line[0] == '[') {
- // It's a new section which begins here.
- unsigned int p = 1;
-
- if (line[p] == ']') {
- perr << "Config file buggy: empty section name in line "
- << lineno << Std::endl;
- return false;
- }
-
- // Get the section name, and check whether it's valid (that
- // is, verify that it only consists of alphanumerics,
- // dashes, underscores and colons).
- while (p < line.size() && (Common::isAlnum(line[p]) || line[p] == '-' ||
- line[p] == '_' || line[p] == ':' || line[p] == ' '))
- p++;
-
- if (p >= line.size()) {
- perr << "Config file buggy: missing ] in line " << lineno
- << ": '" << line << "'" << Std::endl;
- return false;
- }
- if (line[p] != ']') {
- perr << "Config file buggy: Invalid character '" << line[p]
- << "' occured in section name in line " << lineno
- << Std::endl;
- return false;
- }
-
- if (!section._name.empty()) {
- // save previous section
- _sections.push_back(section);
- }
-
- section._keys.clear();
- section._name = line.substr(1, p - 1);
- section._comment = comment;
- comment.clear();
-
- } else {
- // Skip leading & trailing whitespaces
- rtrim(line);
- ltrim(line);
-
- // Skip empty lines
- if (line.empty())
- continue;
-
- // If no section has been set, this config file is invalid!
- if (section._name.empty()) {
- perr << "Config file buggy: Key/value pair found outside "
- << "a section in line " << lineno << Std::endl;
- return false;
- }
-
- // Split string at '=' into 'key' and 'value'.
- string::size_type p = line.find('=');
- if (p == string::npos || p == 0) {
- perr << "Config file buggy: Junk found in line " << lineno
- << ": '" << line << "'" << Std::endl;
- return false;
- }
-
- KeyValue v;
-
- string t = line.substr(0, p);
- rtrim(t);
- v._key = t;
-
- if (p + 1 < line.size())
- t = line.substr(p + 1);
- else
- t = "";
- ltrim(t);
- v._value = t;
-
- v._comment = comment;
- comment.clear();
-
-#if 0
- pout << "section: " << section._name << ", key: " << v._key
- << ", value: " << v._value << Std::endl;
-#endif
-
- section._keys.push_back(v);
- }
- }
-
- if (!section._name.empty()) {
- // save last section
- _sections.push_back(section);
- }
-
- return true;
-}
-
-void INIFile::clear(istring root) {
- _sections.clear();
- _root = root;
- _isFile = false;
- _readOnly = false;
- _filename = "";
-}
-
-string INIFile::dump() {
- string s;
-
- Std::list<Section>::iterator i;
- for (i = _sections.begin(); i != _sections.end(); ++i) {
- if (i != _sections.begin())
- s += "\n";
-
- s += i->dump();
- }
-
- return s;
-}
-
-void INIFile::write() {
- if (!_isFile || _readOnly)
- return;
-
- Common::WriteStream *f = FileSystem::get_instance()->WriteFile(_filename, true);
- if (!f) return;
-
- Std::string s = dump();
- const char *cstr = s.c_str();
- f->write(cstr, strlen(cstr));
-
- delete f;
-}
-
-bool INIFile::stripRoot(istring &key) {
- string::size_type pos = key.find('/');
- if (pos == istring::npos) return false;
-
- istring keyroot = key.substr(0, pos);
- if (keyroot != _root) return false;
-
- key.erase(0, pos + 1);
-
- return true;
-}
-
-INIFile::Section *INIFile::getSection(istring section) {
- Std::list<Section>::iterator i;
- for (i = _sections.begin(); i != _sections.end(); ++i) {
- if (i->_name == section) {
- return &(*i);
- }
- }
- return nullptr;
-}
-
-bool INIFile::splitKey(istring key, istring §ion, istring §ionkey) {
- // TODO: more sanity checks might be nice
-
- string::size_type pos = key.find('/');
- if (pos == istring::npos || pos + 1 >= key.size()) return false;
-
- section = key.substr(0, pos);
- sectionkey = key.substr(pos + 1);
-
- return true;
-}
-
-bool INIFile::hasSection(istring section) {
- if (!stripRoot(section)) return false;
-
- return (getSection(section) != nullptr);
-}
-
-bool INIFile::hasKey(istring key) {
- if (!stripRoot(key)) return false;
- istring s, k;
- splitKey(key, s, k);
-
- Section *section = getSection(s);
- if (!section) return false;
-
- return section->hasKey(k);
-}
-
-bool INIFile::checkRoot(istring key) {
- return (_root == key || stripRoot(key));
-}
-
-bool INIFile::value(istring key, string &ret) {
- if (!stripRoot(key)) return false;
- istring s, k;
- splitKey(key, s, k);
-
- Section *section = getSection(s);
- if (!section) return false;
-
- KeyValue *kv = section->getKey(k);
- if (!kv) return false;
-
- ret = kv->_value;
- return true;
-}
-
-bool INIFile::value(istring key, int &ret) {
- string stringval;
- bool found = value(key, stringval);
-
- if (!found) return false;
-
- ret = strtol(stringval.c_str(), 0, 0);
- return true;
-}
-
-bool INIFile::value(istring key, bool &ret) {
- istring stringval;
- bool found = value(key, stringval);
-
- if (!found) return false;
-
- ret = (stringval == "yes" || stringval == "true");
- return true;
-}
-
-void INIFile::set(istring key, string strValue) {
- if (!stripRoot(key)) return;
- istring s, k;
- splitKey(key, s, k);
-
- Section *section = getSection(s);
- if (!section) {
- Section newsec;
- newsec._name = s;
- newsec._comment = "";
- _sections.push_back(newsec);
- section = getSection(s);
- assert(section);
- }
-
- section->setKey(k, strValue);
-}
-
-void INIFile::set(istring key, const char *strValue) {
- string v = strValue;
- set(key, v);
-}
-
-void INIFile::set(istring key, int intValue) {
- char buf[32];
- snprintf(buf, 32, "%d", intValue);
- set(key, buf);
-}
-
-void INIFile::set(istring key, bool boolValue) {
- if (boolValue)
- set(key, "true");
- else
- set(key, "false");
-}
-
-void INIFile::unset(istring key) {
- if (!stripRoot(key)) return;
- istring s, k;
- splitKey(key, s, k);
-
- Section *section = getSection(s);
- if (section) {
- section->unsetKey(k);
- }
-}
-
-void INIFile::listKeys(Std::set<istring> &_keys, istring sectionName,
- bool longformat) {
- if (!stripRoot(sectionName)) return;
-
- const Section *section = getSection(sectionName);
- if (!section) return;
-
- Std::list<KeyValue>::const_iterator i;
- for (i = section->_keys.begin(); i != section->_keys.end(); ++i) {
- istring k;
- if (longformat)
- k = _root + "/" + section->_name + "/" + i->_key;
- else
- k = i->_key;
-
- _keys.insert(k);
- }
-}
-
-void INIFile::listSections(Std::set<istring> §ions, bool longformat) {
- Std::list<Section>::const_iterator i;
- for (i = _sections.begin(); i != _sections.end(); ++i) {
- istring s;
- if (longformat)
- s = _root + "/" + i->_name;
- else
- s = i->_name;
-
- sections.insert(s);
- }
-}
-
-void INIFile::listKeyValues(KeyMap &keyvalues, istring sectionName, bool longformat) {
- if (!stripRoot(sectionName)) return;
-
- Section *section = getSection(sectionName);
- if (!section) return;
-
- Std::list<KeyValue>::const_iterator i;
- for (i = section->_keys.begin(); i != section->_keys.end(); ++i) {
- istring k;
- if (longformat)
- k = _root + "/" + section->_name + "/" + i->_key;
- else
- k = i->_key;
-
- keyvalues[k] = i->_value;
- }
-}
-
-} // End of namespace Ultima8
-} // End of namespace Ultima
diff --git a/engines/ultima/ultima8/conf/ini_file.h b/engines/ultima/ultima8/conf/ini_file.h
deleted file mode 100644
index db2e268be3..0000000000
--- a/engines/ultima/ultima8/conf/ini_file.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ULTIMA8_CONF_INIFILE_H
-#define ULTIMA8_CONF_INIFILE_H
-
-#include "ultima/shared/std/containers.h"
-
-namespace Ultima {
-namespace Ultima8 {
-
-typedef Std::map<istring, Std::string, Common::IgnoreCase_Hash> KeyMap;
-
-class INIFile {
-public:
- INIFile();
- INIFile(Std::string fname, istring root);
- ~INIFile();
-
- bool readConfigFile(const Std::string &fname);
-
- //! read configuration from a string s. Lines must be separated by \n
- bool readConfigString(Std::string s);
-
- void clear(istring root);
-
- Std::string dump();
- void write();
-
- void setReadonly() {
- _readOnly = true;
- }
- bool isReadonly() const {
- return _readOnly;
- }
-
- bool hasSection(istring section);
- bool hasKey(istring key);
- bool checkRoot(istring key);
-
- // get value
- bool value(istring key, Std::string &ret);
- bool value(istring key, int &ret);
- bool value(istring key, bool &ret);
-
- // set value
- void set(istring key, Std::string strValue);
- void set(istring key, const char *strValue);
- void set(istring key, int intValue);
- void set(istring key, bool boolValue);
-
- // remove key
- void unset(istring key);
-
- void listKeys(Std::set<istring> &keys,
- istring section,
- bool longformat = false);
-
- void listSections(Std::set<istring> §ions,
- bool longformat = false);
-
- void listKeyValues(KeyMap &keyvalues,
- istring section,
- bool longformat = false);
-
-private:
- Std::string _filename;
- istring _root;
- bool _isFile;
- bool _readOnly;
-
- struct KeyValue {
- istring _key;
- Std::string _value;
- Std::string _comment;
- };
-
- struct Section {
- istring _name;
- Std::list<KeyValue> _keys;
- Std::string _comment;
-
- bool hasKey(istring key);
- KeyValue *getKey(istring key);
- void setKey(istring key, Std::string value);
- void unsetKey(istring key);
-
- Std::string dump();
- };
-
- Std::list<Section> _sections;
-
-
- bool stripRoot(istring &key);
- Section *getSection(istring section);
- bool splitKey(istring key, istring §ion,
- istring §ionkey);
-
-};
-
-} // End of namespace Ultima8
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/ultima8/games/game_data.cpp b/engines/ultima/ultima8/games/game_data.cpp
index ba1d197bd8..c667030a12 100644
--- a/engines/ultima/ultima8/games/game_data.cpp
+++ b/engines/ultima/ultima8/games/game_data.cpp
@@ -181,16 +181,12 @@ void GameData::loadTranslation() {
Std::string GameData::translate(const Std::string &text) {
// TODO: maybe cache these lookups? config calls may be expensive
-
ConfigFileManager *config = ConfigFileManager::get_instance();
- istring key = "language/text/" + text;
- if (!config->exists(key))
- return text;
-
Std::string trans;
- config->get(key, trans);
-
- return trans;
+ if (config->get("language", "text", text, trans)) {
+ return trans;
+ }
+ return text;
}
FrameID GameData::translate(FrameID f) {
@@ -199,10 +195,12 @@ FrameID GameData::translate(FrameID f) {
// TODO: allow translations to be in another shapeflex
ConfigFileManager *config = ConfigFileManager::get_instance();
- istring key = "language/";
+ istring category = "language";
+ istring section;
+
switch (f._flexId) {
case GUMPS:
- key += "gumps/";
+ section = "gumps";
break;
default:
return f;
@@ -211,12 +209,11 @@ FrameID GameData::translate(FrameID f) {
char buf[100];
sprintf(buf, "%d,%d", f._shapeNum, f._frameNum);
- key += buf;
- if (!config->exists(key))
- return f;
-
+ istring key = buf;
Std::string trans;
- config->get(key, trans);
+ if (!config->get(category, section, key, trans)) {
+ return f;
+ }
FrameID t;
t._flexId = f._flexId;
@@ -368,7 +365,7 @@ void GameData::loadU8Data() {
}
void GameData::setupFontOverrides() {
- setupTTFOverrides("game/fontoverride", false);
+ setupTTFOverrides("game", false);
if (_gameInfo->_language == GameInfo::GAMELANG_JAPANESE)
setupJPOverrides();
@@ -380,7 +377,7 @@ void GameData::setupJPOverrides() {
KeyMap jpkeyvals;
KeyMap::const_iterator iter;
- jpkeyvals = config->listKeyValues("language/jpfonts");
+ jpkeyvals = config->listKeyValues("language", "jpfonts");
for (iter = jpkeyvals.begin(); iter != jpkeyvals.end(); ++iter) {
int fontnum = atoi(iter->_key.c_str());
const Std::string &fontdesc = iter->_value;
@@ -403,10 +400,10 @@ void GameData::setupJPOverrides() {
bool overridefonts = ConfMan.getBool("overridefonts");
if (overridefonts)
- setupTTFOverrides("language/fontoverride", true);
+ setupTTFOverrides("language", true);
}
-void GameData::setupTTFOverrides(const char *configkey, bool SJIS) {
+void GameData::setupTTFOverrides(const char *category, bool SJIS) {
ConfigFileManager *config = ConfigFileManager::get_instance();
FontManager *fontmanager = FontManager::get_instance();
KeyMap ttfkeyvals;
@@ -415,7 +412,7 @@ void GameData::setupTTFOverrides(const char *configkey, bool SJIS) {
bool overridefonts = ConfMan.getBool("overridefonts");
if (!overridefonts) return;
- ttfkeyvals = config->listKeyValues(configkey);
+ ttfkeyvals = config->listKeyValues(category, "fontoverride");
for (iter = ttfkeyvals.begin(); iter != ttfkeyvals.end(); ++iter) {
int fontnum = atoi(iter->_key.c_str());
const Std::string &fontdesc = iter->_value;
diff --git a/engines/ultima/ultima8/games/game_data.h b/engines/ultima/ultima8/games/game_data.h
index 2d16051a46..24d60c1508 100644
--- a/engines/ultima/ultima8/games/game_data.h
+++ b/engines/ultima/ultima8/games/game_data.h
@@ -114,7 +114,7 @@ public:
};
private:
void loadTranslation();
- void setupTTFOverrides(const char *configkey, bool SJIS);
+ void setupTTFOverrides(const char *category, bool SJIS);
void setupJPOverrides();
RawArchive *_fixed;
diff --git a/engines/ultima/ultima8/games/treasure_loader.cpp b/engines/ultima/ultima8/games/treasure_loader.cpp
index ebcffbeefd..cbc2a1e8e6 100644
--- a/engines/ultima/ultima8/games/treasure_loader.cpp
+++ b/engines/ultima/ultima8/games/treasure_loader.cpp
@@ -40,7 +40,7 @@ void TreasureLoader::loadDefaults() {
KeyMap lootkeyvals;
// load default treasure types
- lootkeyvals = config->listKeyValues("game/treasure");
+ lootkeyvals = config->listKeyValues("game", "treasure");
KeyMap::const_iterator defaultiter;
for (defaultiter = lootkeyvals.begin();
defaultiter != lootkeyvals.end(); ++defaultiter) {
diff --git a/engines/ultima/ultima8/graphics/fonts/font_shape_archive.cpp b/engines/ultima/ultima8/graphics/fonts/font_shape_archive.cpp
index ad30ccefc3..6adca943a9 100644
--- a/engines/ultima/ultima8/graphics/fonts/font_shape_archive.cpp
+++ b/engines/ultima/ultima8/graphics/fonts/font_shape_archive.cpp
@@ -64,7 +64,7 @@ void FontShapeArchive::cache(uint32 shapenum) {
void FontShapeArchive::setHVLeads() {
ConfigFileManager *config = ConfigFileManager::get_instance();
- KeyMap leadkeyvals = config->listKeyValues("game/fontleads");
+ KeyMap leadkeyvals = config->listKeyValues("game", "fontleads");
KeyMap::const_iterator iter;
for (iter = leadkeyvals.begin(); iter != leadkeyvals.end(); ++iter) {
diff --git a/engines/ultima/ultima8/graphics/type_flags.cpp b/engines/ultima/ultima8/graphics/type_flags.cpp
index a704909ffa..3f77238831 100644
--- a/engines/ultima/ultima8/graphics/type_flags.cpp
+++ b/engines/ultima/ultima8/graphics/type_flags.cpp
@@ -177,83 +177,83 @@ void TypeFlags::loadWeaponInfo() {
// load weapons
Std::vector<istring> weaponkeys;
- weaponkeys = config->listSections("weapons", true);
+ istring category = "weapons";
+ weaponkeys = config->listSections(category);
for (Std::vector<istring>::const_iterator iter = weaponkeys.begin();
iter != weaponkeys.end(); ++iter) {
- const istring &k = *iter;
+ const istring §ion = *iter;
WeaponInfo *wi = new WeaponInfo;
int val = 0;
- // Slight hack.. get the name after the the /
- wi->_name = k.substr(k.findLastOf('/') + 1, Std::string::npos);
+ wi->_name = section;
- config->get(k + "/shape", val);
+ config->get(category, section, "shape", val);
wi->_shape = static_cast<uint32>(val);
- config->get(k + "/overlay", val);
+ config->get(category, section, "overlay", val);
wi->_overlayType = static_cast<uint8>(val);
- config->get(k + "/overlay_shape", val);
+ config->get(category, section, "overlay_shape", val);
wi->_overlayShape = static_cast<uint32>(val);
- config->get(k + "/damage_mod", val);
+ config->get(category, section, "damage_mod", val);
wi->_damageModifier = static_cast<uint8>(val);
- config->get(k + "/base_damage", val);
+ config->get(category, section, "base_damage", val);
wi->_baseDamage = static_cast<uint8>(val);
- if (config->get(k + "/attack_dex", val))
+ if (config->get(category, section, "attack_dex", val))
wi->_dexAttackBonus = static_cast<uint8>(val);
else
wi->_dexAttackBonus = 0;
- if (config->get(k + "/defend_dex", val))
+ if (config->get(category, section, "defend_dex", val))
wi->_dexDefendBonus = static_cast<uint8>(val);
else
wi->_dexDefendBonus = 0;
- if (config->get(k + "/armour", val))
+ if (config->get(category, section, "armour", val))
wi->_armourBonus = static_cast<uint8>(val);
else
wi->_armourBonus = 0;
- config->get(k + "/damage_type", val);
+ config->get(category, section, "damage_type", val);
wi->_damageType = static_cast<uint16>(val);
- if (config->get(k + "/treasure_chance", val))
+ if (config->get(category, section, "treasure_chance", val))
wi->_treasureChance = static_cast<uint16>(val);
else
wi->_treasureChance = 0;
// Crusader-specific fields:
- if (config->get(k + "/ammo_type", val))
+ if (config->get(category, section, "ammo_type", val))
wi->_ammoType = static_cast<uint16>(val);
else
wi->_ammoType = 0;
- if (config->get(k + "/ammo_shape", val))
+ if (config->get(category, section, "ammo_shape", val))
wi->_ammoShape = static_cast<uint16>(val);
else
wi->_ammoShape = 0;
- if (config->get(k + "/sound", val))
+ if (config->get(category, section, "sound", val))
wi->_sound = static_cast<uint16>(val);
else
wi->_sound = 0;
- if (config->get(k + "/display_frame", val))
+ if (config->get(category, section, "display_frame", val))
wi->_displayGumpFrame = static_cast<uint16>(val);
else
wi->_displayGumpFrame = 0;
- if (config->get(k + "/display_shape", val))
+ if (config->get(category, section, "display_shape", val))
wi->_displayGumpShape = static_cast<uint16>(val);
else
wi->_displayGumpShape = 3;
- if (config->get(k + "/small", val))
+ if (config->get(category, section, "small", val))
wi->_small = static_cast<uint8>(val);
else
wi->_small = 0;
@@ -282,15 +282,16 @@ void TypeFlags::loadArmourInfo() {
// load armour
Std::vector<istring> armourkeys;
- armourkeys = config->listSections("armour", true);
+ istring category = "armour";
+ armourkeys = config->listSections(category);
for (Std::vector<istring>::const_iterator iter = armourkeys.begin();
iter != armourkeys.end(); ++iter) {
- const istring &k = *iter;
+ const istring §ion = *iter;
ArmourInfo ai;
int val;
- config->get(k + "/shape", val);
+ config->get(category, section, "shape", val);
ai._shape = static_cast<uint32>(val);
assert(ai._shape < _shapeInfo.size());
@@ -309,20 +310,20 @@ void TypeFlags::loadArmourInfo() {
}
}
- config->get(k + "/frame", val);
+ config->get(category, section, "frame", val);
ai._frame = static_cast<uint32>(val);
assert(ai._frame < framecount);
- config->get(k + "/armour", val);
+ config->get(category, section, "armour", val);
ai._armourClass = static_cast<uint16>(val);
- if (config->get(k + "/type", val))
+ if (config->get(category, section, "type", val))
ai._defenseType = static_cast<uint16>(val);
else
ai._defenseType = 0;
- if (config->get(k + "/kick_bonus", val))
+ if (config->get(category, section, "kick_bonus", val))
ai._kickAttackBonus = static_cast<uint16>(val);
else
ai._kickAttackBonus = 0;
@@ -339,75 +340,76 @@ void TypeFlags::loadMonsterInfo() {
// load monsters
Std::vector<istring> monsterkeys;
- monsterkeys = config->listSections("monsters", true);
+ istring category = "monsters";
+ monsterkeys = config->listSections(category);
for (Std::vector<istring>::const_iterator iter = monsterkeys.begin();
iter != monsterkeys.end(); ++iter) {
- const istring k = *iter;
+ const istring section = *iter;
MonsterInfo *mi = new MonsterInfo;
int val;
- config->get(k + "/shape", val);
+ config->get(category, section, "shape", val);
mi->_shape = static_cast<uint32>(val);
- config->get(k + "/hp_min", val);
+ config->get(category, section, "hp_min", val);
mi->_minHp = static_cast<uint16>(val);
- config->get(k + "/hp_max", val);
+ config->get(category, section, "hp_max", val);
mi->_maxHp = static_cast<uint16>(val);
- config->get(k + "/dex_min", val);
+ config->get(category, section, "dex_min", val);
mi->_minDex = static_cast<uint16>(val);
- config->get(k + "/dex_max", val);
+ config->get(category, section, "dex_max", val);
mi->_maxDex = static_cast<uint16>(val);
- config->get(k + "/damage_min", val);
+ config->get(category, section, "damage_min", val);
mi->_minDmg = static_cast<uint16>(val);
- config->get(k + "/damage_max", val);
+ config->get(category, section, "damage_max", val);
mi->_maxDmg = static_cast<uint16>(val);
- config->get(k + "/armour", val);
+ config->get(category, section, "armour", val);
mi->_armourClass = static_cast<uint16>(val);
- config->get(k + "/alignment", val);
+ config->get(category, section, "alignment", val);
mi->_alignment = static_cast<uint8>(val);
- config->get(k + "/unk", val);
+ config->get(category, section, "unk", val);
mi->_unk = (val != 0);
- config->get(k + "/damage_type", val);
+ config->get(category, section, "damage_type", val);
mi->_damageType = static_cast<uint16>(val);
- config->get(k + "/defense_type", val);
+ config->get(category, section, "defense_type", val);
mi->_defenseType = static_cast<uint16>(val);
- if (config->get(k + "/resurrection", val))
+ if (config->get(category, section, "resurrection", val))
mi->_resurrection = (val != 0);
else
mi->_resurrection = false;
- if (config->get(k + "/ranged", val))
+ if (config->get(category, section, "ranged", val))
mi->_ranged = (val != 0);
else
mi->_ranged = false;
- if (config->get(k + "/shifter", val))
+ if (config->get(category, section, "shifter", val))
mi->_shifter = (val != 0);
else
mi->_shifter = false;
- if (config->get(k + "/explode", val))
+ if (config->get(category, section, "explode", val))
mi->_explode = val;
else
mi->_explode = 0;
Std::string treasure;
- if (config->get(k + "/treasure", treasure)) {
+ if (config->get(category, section, "treasure", treasure)) {
bool ok = treasureLoader.parse(treasure, mi->_treasure);
if (!ok) {
- perr << "failed to parse treasure info for monster '" << k
+ perr << "failed to parse treasure info for monster '" << section
<< "'" << Std::endl;
mi->_treasure.clear();
}
More information about the Scummvm-git-logs
mailing list