mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-18 07:53:12 +00:00
COMMON: Rename ConfigFile to INIFile.
This clears up that 'ConfigFile' is actually a class handling only INI-files.
This commit is contained in:
parent
6e5c308b91
commit
63750d6780
@ -24,7 +24,7 @@
|
||||
#define COMMON_CONFIG_MANAGER_H
|
||||
|
||||
#include "common/array.h"
|
||||
//#include "common/config-file.h"
|
||||
//#include "common/ini-file.h"
|
||||
#include "common/hashmap.h"
|
||||
#include "common/singleton.h"
|
||||
#include "common/str.h"
|
||||
|
@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/config-file.h"
|
||||
#include "common/ini-file.h"
|
||||
#include "common/file.h"
|
||||
#include "common/savefile.h"
|
||||
#include "common/system.h"
|
||||
@ -28,24 +28,24 @@
|
||||
|
||||
namespace Common {
|
||||
|
||||
bool ConfigFile::isValidName(const String &name) {
|
||||
bool INIFile::isValidName(const String &name) {
|
||||
const char *p = name.c_str();
|
||||
while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.'))
|
||||
p++;
|
||||
return *p == 0;
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile() {
|
||||
INIFile::INIFile() {
|
||||
}
|
||||
|
||||
ConfigFile::~ConfigFile() {
|
||||
INIFile::~INIFile() {
|
||||
}
|
||||
|
||||
void ConfigFile::clear() {
|
||||
void INIFile::clear() {
|
||||
_sections.clear();
|
||||
}
|
||||
|
||||
bool ConfigFile::loadFromFile(const String &filename) {
|
||||
bool INIFile::loadFromFile(const String &filename) {
|
||||
File file;
|
||||
if (file.open(filename))
|
||||
return loadFromStream(file);
|
||||
@ -53,7 +53,7 @@ bool ConfigFile::loadFromFile(const String &filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigFile::loadFromSaveFile(const char *filename) {
|
||||
bool INIFile::loadFromSaveFile(const char *filename) {
|
||||
assert(g_system);
|
||||
SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
||||
SeekableReadStream *loadFile;
|
||||
@ -67,7 +67,7 @@ bool ConfigFile::loadFromSaveFile(const char *filename) {
|
||||
return status;
|
||||
}
|
||||
|
||||
bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
||||
bool INIFile::loadFromStream(SeekableReadStream &stream) {
|
||||
Section section;
|
||||
KeyValue kv;
|
||||
String comment;
|
||||
@ -112,9 +112,9 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
||||
p++;
|
||||
|
||||
if (*p == '\0')
|
||||
error("ConfigFile::loadFromStream: missing ] in line %d", lineno);
|
||||
error("INIFile::loadFromStream: missing ] in line %d", lineno);
|
||||
else if (*p != ']')
|
||||
error("ConfigFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno);
|
||||
error("INIFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno);
|
||||
|
||||
// Previous section is finished now, store it.
|
||||
if (!section.name.empty())
|
||||
@ -140,7 +140,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
||||
|
||||
// If no section has been set, this config file is invalid!
|
||||
if (section.name.empty()) {
|
||||
error("ConfigFile::loadFromStream: Key/value pair found outside a section in line %d", lineno);
|
||||
error("INIFile::loadFromStream: Key/value pair found outside a section in line %d", lineno);
|
||||
}
|
||||
|
||||
// Split string at '=' into 'key' and 'value'. First, find the "=" delimeter.
|
||||
@ -173,7 +173,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
||||
return (!stream.err() || stream.eos());
|
||||
}
|
||||
|
||||
bool ConfigFile::saveToFile(const String &filename) {
|
||||
bool INIFile::saveToFile(const String &filename) {
|
||||
DumpFile file;
|
||||
if (file.open(filename))
|
||||
return saveToStream(file);
|
||||
@ -181,7 +181,7 @@ bool ConfigFile::saveToFile(const String &filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigFile::saveToSaveFile(const char *filename) {
|
||||
bool INIFile::saveToSaveFile(const char *filename) {
|
||||
assert(g_system);
|
||||
SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
||||
WriteStream *saveFile;
|
||||
@ -195,7 +195,7 @@ bool ConfigFile::saveToSaveFile(const char *filename) {
|
||||
return status;
|
||||
}
|
||||
|
||||
bool ConfigFile::saveToStream(WriteStream &stream) {
|
||||
bool INIFile::saveToStream(WriteStream &stream) {
|
||||
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
|
||||
// Write out the section comment, if any
|
||||
if (! i->comment.empty()) {
|
||||
@ -226,7 +226,7 @@ bool ConfigFile::saveToStream(WriteStream &stream) {
|
||||
return !stream.err();
|
||||
}
|
||||
|
||||
void ConfigFile::addSection(const String §ion) {
|
||||
void INIFile::addSection(const String §ion) {
|
||||
Section *s = getSection(section);
|
||||
if (s)
|
||||
return;
|
||||
@ -236,7 +236,7 @@ void ConfigFile::addSection(const String §ion) {
|
||||
_sections.push_back(newSection);
|
||||
}
|
||||
|
||||
void ConfigFile::removeSection(const String §ion) {
|
||||
void INIFile::removeSection(const String §ion) {
|
||||
assert(isValidName(section));
|
||||
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
|
||||
if (section.equalsIgnoreCase(i->name)) {
|
||||
@ -246,13 +246,13 @@ void ConfigFile::removeSection(const String §ion) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigFile::hasSection(const String §ion) const {
|
||||
bool INIFile::hasSection(const String §ion) const {
|
||||
assert(isValidName(section));
|
||||
const Section *s = getSection(section);
|
||||
return s != 0;
|
||||
}
|
||||
|
||||
void ConfigFile::renameSection(const String &oldName, const String &newName) {
|
||||
void INIFile::renameSection(const String &oldName, const String &newName) {
|
||||
assert(isValidName(oldName));
|
||||
assert(isValidName(newName));
|
||||
|
||||
@ -262,7 +262,7 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) {
|
||||
// HACK: For now we just print a warning, for more info see the TODO
|
||||
// below.
|
||||
if (ns)
|
||||
warning("ConfigFile::renameSection: Section name \"%s\" already used", newName.c_str());
|
||||
warning("INIFile::renameSection: Section name \"%s\" already used", newName.c_str());
|
||||
else
|
||||
os->name = newName;
|
||||
}
|
||||
@ -274,7 +274,7 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) {
|
||||
}
|
||||
|
||||
|
||||
bool ConfigFile::hasKey(const String &key, const String §ion) const {
|
||||
bool INIFile::hasKey(const String &key, const String §ion) const {
|
||||
assert(isValidName(key));
|
||||
assert(isValidName(section));
|
||||
|
||||
@ -284,7 +284,7 @@ bool ConfigFile::hasKey(const String &key, const String §ion) const {
|
||||
return s->hasKey(key);
|
||||
}
|
||||
|
||||
void ConfigFile::removeKey(const String &key, const String §ion) {
|
||||
void INIFile::removeKey(const String &key, const String §ion) {
|
||||
assert(isValidName(key));
|
||||
assert(isValidName(section));
|
||||
|
||||
@ -293,7 +293,7 @@ void ConfigFile::removeKey(const String &key, const String §ion) {
|
||||
s->removeKey(key);
|
||||
}
|
||||
|
||||
bool ConfigFile::getKey(const String &key, const String §ion, String &value) const {
|
||||
bool INIFile::getKey(const String &key, const String §ion, String &value) const {
|
||||
assert(isValidName(key));
|
||||
assert(isValidName(section));
|
||||
|
||||
@ -307,7 +307,7 @@ bool ConfigFile::getKey(const String &key, const String §ion, String &value)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfigFile::setKey(const String &key, const String §ion, const String &value) {
|
||||
void INIFile::setKey(const String &key, const String §ion, const String &value) {
|
||||
assert(isValidName(key));
|
||||
assert(isValidName(section));
|
||||
// TODO: Verify that value is valid, too. In particular, it shouldn't
|
||||
@ -329,13 +329,13 @@ void ConfigFile::setKey(const String &key, const String §ion, const String &
|
||||
}
|
||||
}
|
||||
|
||||
const ConfigFile::SectionKeyList ConfigFile::getKeys(const String §ion) const {
|
||||
const INIFile::SectionKeyList INIFile::getKeys(const String §ion) const {
|
||||
const Section *s = getSection(section);
|
||||
|
||||
return s->getKeys();
|
||||
}
|
||||
|
||||
ConfigFile::Section *ConfigFile::getSection(const String §ion) {
|
||||
INIFile::Section *INIFile::getSection(const String §ion) {
|
||||
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
|
||||
if (section.equalsIgnoreCase(i->name)) {
|
||||
return &(*i);
|
||||
@ -344,7 +344,7 @@ ConfigFile::Section *ConfigFile::getSection(const String §ion) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const ConfigFile::Section *ConfigFile::getSection(const String §ion) const {
|
||||
const INIFile::Section *INIFile::getSection(const String §ion) const {
|
||||
for (List<Section>::const_iterator i = _sections.begin(); i != _sections.end(); ++i) {
|
||||
if (section.equalsIgnoreCase(i->name)) {
|
||||
return &(*i);
|
||||
@ -353,11 +353,11 @@ const ConfigFile::Section *ConfigFile::getSection(const String §ion) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ConfigFile::Section::hasKey(const String &key) const {
|
||||
bool INIFile::Section::hasKey(const String &key) const {
|
||||
return getKey(key) != 0;
|
||||
}
|
||||
|
||||
const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const {
|
||||
const INIFile::KeyValue* INIFile::Section::getKey(const String &key) const {
|
||||
for (List<KeyValue>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
if (key.equalsIgnoreCase(i->key)) {
|
||||
return &(*i);
|
||||
@ -366,7 +366,7 @@ const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConfigFile::Section::setKey(const String &key, const String &value) {
|
||||
void INIFile::Section::setKey(const String &key, const String &value) {
|
||||
for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
if (key.equalsIgnoreCase(i->key)) {
|
||||
i->value = value;
|
||||
@ -380,7 +380,7 @@ void ConfigFile::Section::setKey(const String &key, const String &value) {
|
||||
keys.push_back(newKV);
|
||||
}
|
||||
|
||||
void ConfigFile::Section::removeKey(const String &key) {
|
||||
void INIFile::Section::removeKey(const String &key) {
|
||||
for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
if (key.equalsIgnoreCase(i->key)) {
|
||||
keys.erase(i);
|
@ -20,8 +20,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COMMON_CONFIG_FILE_H
|
||||
#define COMMON_CONFIG_FILE_H
|
||||
#ifndef COMMON_INI_FILE_H
|
||||
#define COMMON_INI_FILE_H
|
||||
|
||||
#include "common/hash-str.h"
|
||||
#include "common/list.h"
|
||||
@ -50,7 +50,7 @@ class WriteStream;
|
||||
* If you need fast access to the game config, use higher level APIs, like the
|
||||
* one provided by ConfigManager.
|
||||
*/
|
||||
class ConfigFile {
|
||||
class INIFile {
|
||||
public:
|
||||
struct KeyValue {
|
||||
String key;
|
||||
@ -60,12 +60,12 @@ public:
|
||||
|
||||
typedef List<KeyValue> SectionKeyList;
|
||||
|
||||
/** A section in a config file. I.e. corresponds to something like this:
|
||||
/** A section in a ini file. I.e. corresponds to something like this:
|
||||
* [mySection]
|
||||
* key=value
|
||||
*
|
||||
* Comments are also stored, to keep users happy who like editing their
|
||||
* config files manually.
|
||||
* ini files manually.
|
||||
*/
|
||||
struct Section {
|
||||
String name;
|
||||
@ -82,8 +82,8 @@ public:
|
||||
typedef List<Section> SectionList;
|
||||
|
||||
public:
|
||||
ConfigFile();
|
||||
~ConfigFile();
|
||||
INIFile();
|
||||
~INIFile();
|
||||
|
||||
// TODO: Maybe add a copy constructor etc.?
|
||||
|
||||
@ -95,7 +95,7 @@ public:
|
||||
*/
|
||||
static bool isValidName(const String &name);
|
||||
|
||||
/** Reset everything stored in this config file. */
|
||||
/** Reset everything stored in this ini file. */
|
||||
void clear();
|
||||
|
||||
bool loadFromFile(const String &filename);
|
@ -2,7 +2,6 @@ MODULE := common
|
||||
|
||||
MODULE_OBJS := \
|
||||
archive.o \
|
||||
config-file.o \
|
||||
config-manager.o \
|
||||
coroutines.o \
|
||||
dcl.o \
|
||||
@ -15,6 +14,7 @@ MODULE_OBJS := \
|
||||
gui_options.o \
|
||||
hashmap.o \
|
||||
iff_container.o \
|
||||
ini-file.o \
|
||||
installshield_cab.o \
|
||||
language.o \
|
||||
localization.o \
|
||||
|
@ -23,7 +23,7 @@
|
||||
#ifndef COMPOSER_H
|
||||
#define COMPOSER_H
|
||||
|
||||
#include "common/config-file.h"
|
||||
#include "common/ini-file.h"
|
||||
#include "common/random.h"
|
||||
#include "common/system.h"
|
||||
#include "common/debug.h"
|
||||
@ -174,7 +174,7 @@ private:
|
||||
Common::List<Sprite> _sprites;
|
||||
|
||||
uint _directoriesToStrip;
|
||||
Common::ConfigFile _bookIni;
|
||||
Common::INIFile _bookIni;
|
||||
Common::String _bookGroup;
|
||||
Common::List<Library> _libraries;
|
||||
Common::Array<PendingPageChange> _pendingPageChanges;
|
||||
|
@ -73,7 +73,7 @@ bool INIConfig::getConfig(const Common::String &file, Config &config) {
|
||||
}
|
||||
|
||||
bool INIConfig::openConfig(const Common::String &file, Config &config) {
|
||||
config.config = new Common::ConfigFile();
|
||||
config.config = new Common::INIFile();
|
||||
config.created = false;
|
||||
|
||||
if (!config.config->loadFromFile(file)) {
|
||||
@ -89,7 +89,7 @@ bool INIConfig::openConfig(const Common::String &file, Config &config) {
|
||||
}
|
||||
|
||||
bool INIConfig::createConfig(const Common::String &file, Config &config) {
|
||||
config.config = new Common::ConfigFile();
|
||||
config.config = new Common::INIFile();
|
||||
config.created = true;
|
||||
|
||||
_configs.setVal(file, config);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define GOB_INICONFIG_H
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/config-file.h"
|
||||
#include "common/ini-file.h"
|
||||
#include "common/hashmap.h"
|
||||
|
||||
namespace Gob {
|
||||
@ -43,7 +43,7 @@ public:
|
||||
|
||||
private:
|
||||
struct Config {
|
||||
Common::ConfigFile *config;
|
||||
Common::INIFile *config;
|
||||
bool created;
|
||||
};
|
||||
|
||||
|
@ -311,8 +311,8 @@ void MohawkEngine_LivingBooks::loadBookInfo(const Common::String &filename) {
|
||||
// - fDebugWindow (always 0?)
|
||||
|
||||
if (_bookInfoFile.hasSection("Globals")) {
|
||||
const Common::ConfigFile::SectionKeyList globals = _bookInfoFile.getKeys("Globals");
|
||||
for (Common::ConfigFile::SectionKeyList::const_iterator i = globals.begin(); i != globals.end(); i++) {
|
||||
const Common::INIFile::SectionKeyList globals = _bookInfoFile.getKeys("Globals");
|
||||
for (Common::INIFile::SectionKeyList::const_iterator i = globals.begin(); i != globals.end(); i++) {
|
||||
Common::String command = Common::String::format("%s = %s", i->key.c_str(), i->value.c_str());
|
||||
LBCode tempCode(this, 0);
|
||||
uint offset = tempCode.parseCode(command);
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "mohawk/livingbooks_graphics.h"
|
||||
#include "mohawk/sound.h"
|
||||
|
||||
#include "common/config-file.h"
|
||||
#include "common/ini-file.h"
|
||||
#include "common/rect.h"
|
||||
#include "common/queue.h"
|
||||
#include "common/random.h"
|
||||
@ -759,7 +759,7 @@ public:
|
||||
|
||||
private:
|
||||
LivingBooksConsole *_console;
|
||||
Common::ConfigFile _bookInfoFile;
|
||||
Common::INIFile _bookInfoFile;
|
||||
|
||||
Common::String getBookInfoFileName() const;
|
||||
void loadBookInfo(const Common::String &filename);
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
bool call(uint callId, const Common::Array<LBValue> ¶ms, LBValue &result);
|
||||
|
||||
protected:
|
||||
Common::ConfigFile _dataFile;
|
||||
Common::INIFile _dataFile;
|
||||
Common::String _curSection;
|
||||
|
||||
void open(const Common::String &filename);
|
||||
@ -77,8 +77,8 @@ bool LBXDataFile::call(uint callId, const Common::Array<LBValue> ¶ms, LBValu
|
||||
case kLBXDataFileGetSectionList:
|
||||
{
|
||||
Common::SharedPtr<LBList> list = Common::SharedPtr<LBList>(new LBList);
|
||||
Common::ConfigFile::SectionList sections = _dataFile.getSections();
|
||||
for (Common::List<Common::ConfigFile::Section>::const_iterator i = sections.begin(); i != sections.end(); ++i)
|
||||
Common::INIFile::SectionList sections = _dataFile.getSections();
|
||||
for (Common::List<Common::INIFile::Section>::const_iterator i = sections.begin(); i != sections.end(); ++i)
|
||||
list->array.push_back(LBValue(i->name));
|
||||
result = LBValue(list);
|
||||
}
|
||||
@ -103,8 +103,8 @@ bool LBXDataFile::call(uint callId, const Common::Array<LBValue> ¶ms, LBValu
|
||||
error("incorrect number of parameters (%d) to LBXDataFile::loadCurSectionVars", params.size());
|
||||
|
||||
{
|
||||
const Common::ConfigFile::SectionKeyList globals = _dataFile.getKeys(_curSection);
|
||||
for (Common::ConfigFile::SectionKeyList::const_iterator i = globals.begin(); i != globals.end(); i++) {
|
||||
const Common::INIFile::SectionKeyList globals = _dataFile.getKeys(_curSection);
|
||||
for (Common::INIFile::SectionKeyList::const_iterator i = globals.begin(); i != globals.end(); i++) {
|
||||
Common::String command = Common::String::format("%s = %s", i->key.c_str(), i->value.c_str());
|
||||
LBCode tempCode(_vm, 0);
|
||||
uint offset = tempCode.parseCode(command);
|
||||
|
@ -23,7 +23,7 @@
|
||||
#ifdef ENABLE_HE
|
||||
|
||||
#include "common/archive.h"
|
||||
#include "common/config-file.h"
|
||||
#include "common/ini-file.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/macresman.h"
|
||||
#include "common/savefile.h"
|
||||
@ -180,7 +180,7 @@ void ScummEngine_v80he::o80_readConfigFile() {
|
||||
}
|
||||
} else {
|
||||
// Normal Windows INI files
|
||||
Common::ConfigFile confFile;
|
||||
Common::INIFile confFile;
|
||||
if (!strcmp((char *)filename + r, "map.ini"))
|
||||
confFile.loadFromFile((const char *)filename + r);
|
||||
else
|
||||
@ -250,7 +250,7 @@ void ScummEngine_v80he::o80_writeConfigFile() {
|
||||
memcpy(section, "BluesTreasureHunt-Disc2\0", 24);
|
||||
}
|
||||
|
||||
Common::ConfigFile ConfFile;
|
||||
Common::INIFile ConfFile;
|
||||
ConfFile.loadFromSaveFile((const char *)filename + r);
|
||||
ConfFile.setKey((char *)option, (char *)section, (char *)string);
|
||||
ConfFile.saveToSaveFile((const char *)filename + r);
|
||||
|
@ -213,22 +213,22 @@ void TestbedConfigManager::parseConfigFile() {
|
||||
return;
|
||||
}
|
||||
_configFileInterface.loadFromStream(*rs);
|
||||
Common::ConfigFile::SectionList sections = _configFileInterface.getSections();
|
||||
Common::INIFile::SectionList sections = _configFileInterface.getSections();
|
||||
Testsuite *currTS = 0;
|
||||
|
||||
for (Common::ConfigFile::SectionList::const_iterator i = sections.begin(); i != sections.end(); i++) {
|
||||
for (Common::INIFile::SectionList::const_iterator i = sections.begin(); i != sections.end(); i++) {
|
||||
if (i->name.equalsIgnoreCase("Global")) {
|
||||
// Global params may be directly queried, ignore them
|
||||
} else {
|
||||
// A testsuite, process it.
|
||||
currTS = getTestsuiteByName(i->name);
|
||||
Common::ConfigFile::SectionKeyList kList = i->getKeys();
|
||||
Common::INIFile::SectionKeyList kList = i->getKeys();
|
||||
if (!currTS) {
|
||||
Testsuite::logPrintf("Warning! Error in config: Testsuite %s not found\n", i->name.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Common::ConfigFile::SectionKeyList::const_iterator j = kList.begin(); j != kList.end(); j++) {
|
||||
for (Common::INIFile::SectionKeyList::const_iterator j = kList.begin(); j != kList.end(); j++) {
|
||||
if (j->key.equalsIgnoreCase("this")) {
|
||||
currTS->enable(stringToBool(j->value));
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/config-file.h"
|
||||
#include "common/ini-file.h"
|
||||
#include "common/str-array.h"
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
@ -62,7 +62,7 @@ public:
|
||||
private:
|
||||
Common::Array<Testsuite *> &_testsuiteList;
|
||||
Common::String _configFileName;
|
||||
Common::ConfigFile _configFileInterface;
|
||||
Common::INIFile _configFileInterface;
|
||||
void parseConfigFile();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user