[Scummvm-cvs-logs] SF.net SVN: scummvm: [26016] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Mar 8 17:43:33 CET 2007


Revision: 26016
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26016&view=rev
Author:   fingolfin
Date:     2007-03-08 08:43:33 -0800 (Thu, 08 Mar 2007)

Log Message:
-----------
Changed ConfigManager to use class File instead of std C I/O to write the config file

Modified Paths:
--------------
    scummvm/trunk/common/config-manager.cpp
    scummvm/trunk/common/config-manager.h

Modified: scummvm/trunk/common/config-manager.cpp
===================================================================
--- scummvm/trunk/common/config-manager.cpp	2007-03-08 15:02:13 UTC (rev 26015)
+++ scummvm/trunk/common/config-manager.cpp	2007-03-08 16:43:33 UTC (rev 26016)
@@ -247,13 +247,13 @@
 
 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 @@
 			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 @@
 	// 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');
 }
 
 

Modified: scummvm/trunk/common/config-manager.h
===================================================================
--- scummvm/trunk/common/config-manager.h	2007-03-08 15:02:13 UTC (rev 26015)
+++ scummvm/trunk/common/config-manager.h	2007-03-08 16:43:33 UTC (rev 26016)
@@ -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 @@
 	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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list