diff options
author | Max Horn | 2007-03-08 16:43:33 +0000 |
---|---|---|
committer | Max Horn | 2007-03-08 16:43:33 +0000 |
commit | 33a4f8c378ed5868a4343114d47649d11cf75ac0 (patch) | |
tree | 8b170ab27795bdf2c0fc49c99df0eaeb8b94c733 | |
parent | f02802531eafff96871291f41d068fbfb8f24d6a (diff) | |
download | scummvm-rg350-33a4f8c378ed5868a4343114d47649d11cf75ac0.tar.gz scummvm-rg350-33a4f8c378ed5868a4343114d47649d11cf75ac0.tar.bz2 scummvm-rg350-33a4f8c378ed5868a4343114d47649d11cf75ac0.zip |
Changed ConfigManager to use class File instead of std C I/O to write the config file
svn-id: r26016
-rw-r--r-- | common/config-manager.cpp | 27 | ||||
-rw-r--r-- | common/config-manager.h | 5 |
2 files changed, 19 insertions, 13 deletions
diff --git a/common/config-manager.cpp b/common/config-manager.cpp index 05a1b22404..afe28a820c 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -247,13 +247,13 @@ void ConfigManager::loadFile(const String &filename) { void ConfigManager::flushToDisk() { #ifndef __DC__ - FILE *cfg_file; + File cfg_file; // TODO // if (!willwrite) // return; - if (!(cfg_file = fopen(_filename.c_str(), "w"))) { + if (!cfg_file.open(_filename, File::kFileWriteMode)) { warning("Unable to write configuration file: %s", _filename.c_str()); } else { @@ -278,13 +278,11 @@ void ConfigManager::flushToDisk() { if (!_domainSaveOrder.contains(d->_key)) writeDomain(cfg_file, d->_key, d->_value); } - - fclose(cfg_file); } #endif // !__DC__ } -void ConfigManager::writeDomain(FILE *file, const String &name, const Domain &domain) { +void ConfigManager::writeDomain(WriteStream &stream, const String &name, const Domain &domain) { if (domain.empty()) return; // Don't bother writing empty domains. @@ -293,26 +291,31 @@ void ConfigManager::writeDomain(FILE *file, const String &name, const Domain &do // Write domain comment (if any) comment = domain.getDomainComment(); if (!comment.empty()) - fprintf(file, "%s", comment.c_str()); + stream.writeString(comment); // Write domain start - fprintf(file, "[%s]\n", name.c_str()); + stream.writeByte('['); + stream.writeString(name); + stream.writeByte(']'); + stream.writeByte('\n'); // Write all key/value pairs in this domain, including comments Domain::const_iterator x; for (x = domain.begin(); x != domain.end(); ++x) { - const String &value = x->_value; - if (!value.empty()) { + if (!x->_value.empty()) { // Write comment (if any) if (domain.hasKVComment(x->_key)) { comment = domain.getKVComment(x->_key); - fprintf(file, "%s", comment.c_str()); + stream.writeString(comment); } // Write the key/value pair - fprintf(file, "%s=%s\n", x->_key.c_str(), value.c_str()); + stream.writeString(x->_key); + stream.writeByte('='); + stream.writeString(x->_value); + stream.writeByte('\n'); } } - fprintf(file, "\n"); + stream.writeByte('\n'); } diff --git a/common/config-manager.h b/common/config-manager.h index 364ca638ba..9561ce01c3 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -33,6 +33,9 @@ namespace Common { +class WriteStream; + + /** * The (singleton) configuration manager, used to query & set configuration * values using string keys. @@ -152,7 +155,7 @@ private: ConfigManager(); void loadFile(const String &filename); - void writeDomain(FILE *file, const String &name, const Domain &domain); + void writeDomain(WriteStream &stream, const String &name, const Domain &domain); Domain _transientDomain; DomainMap _gameDomains; |