[Scummvm-git-logs] scummvm master -> b4fcc02c87c1fa4ab4a38ffb9998d4f263db89a9

sev- noreply at scummvm.org
Thu Feb 23 17:12:33 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
83cda889c1 COMMON: Issue warning instead of error dialogs for bad configuration file, return a bool value indicating success or fai
b4fcc02c87 BASE: Add option for the user to proceed with resetting configuration file or quitting ScummVM.


Commit: 83cda889c140d68d7f040cbbb01f00d44cd6b3ef
    https://github.com/scummvm/scummvm/commit/83cda889c140d68d7f040cbbb01f00d44cd6b3ef
Author: Attaullah Ansari (mdattaullahansari152 at gmial.com)
Date: 2023-02-23T18:12:27+01:00

Commit Message:
COMMON: Issue warning instead of error dialogs for bad configuration file, return a bool value indicating success or failure of loading.

Changed paths:
    common/config-manager.cpp
    common/config-manager.h


diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index d530fd8dd86..6f4af2f00c8 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -78,15 +78,16 @@ void ConfigManager::copyFrom(ConfigManager &source) {
 }
 
 
-void ConfigManager::loadDefaultConfigFile(const String &fallbackFilename) {
+bool ConfigManager::loadDefaultConfigFile(const String &fallbackFilename) {
 	// Open the default config file
 	assert(g_system);
 	SeekableReadStream *stream = g_system->createConfigReadStream();
 	_filename.clear(); // clear the filename to indicate that we are using the default config file
 
+	bool loadResult = false;
 	// ... load it, if available ...
 	if (stream) {
-		loadFromStream(*stream);
+		loadResult = loadFromStream(*stream);
 
 		// ... and close it again.
 		delete stream;
@@ -97,10 +98,12 @@ void ConfigManager::loadDefaultConfigFile(const String &fallbackFilename) {
 			debug("Default configuration file missing, creating a new one");
 
 		flushToDisk();
+		loadResult = true;
 	}
+	return loadResult;
 }
 
-void ConfigManager::loadConfigFile(const String &filename, const String &fallbackFilename) {
+bool ConfigManager::loadConfigFile(const String &filename, const String &fallbackFilename) {
 	_filename = filename;
 
 	FSNode node(filename);
@@ -110,8 +113,9 @@ void ConfigManager::loadConfigFile(const String &filename, const String &fallbac
 			debug("Creating configuration file: %s", filename.c_str());
 	} else {
 		debug("Using configuration file: %s", _filename.c_str());
-		loadFromStream(cfg_file);
+		return loadFromStream(cfg_file);
 	}
+	return true;
 }
 
 bool ConfigManager::loadFallbackConfigFile(const String &filename) {
@@ -166,7 +170,7 @@ void ConfigManager::addDomain(const String &domainName, const ConfigManager::Dom
 }
 
 
-void ConfigManager::loadFromStream(SeekableReadStream &stream) {
+bool ConfigManager::loadFromStream(SeekableReadStream &stream) {
 	String domainName;
 	String comment;
 	Domain domain;
@@ -213,10 +217,13 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
 			while (*p && (isAlnum(*p) || *p == '-' || *p == '_'))
 				p++;
 
-			if (*p == '\0')
-				error("Config file buggy: missing ] in line %d", lineno);
-			else if (*p != ']')
-				error("Config file buggy: Invalid character '%c' occurred in section name in line %d", *p, lineno);
+			if (*p == '\0') {
+				warning("Config file buggy: missing ] in line %d", lineno);
+				return false;
+			} else if (*p != ']') {
+				warning("Config file buggy: Invalid character '%c' occurred in section name in line %d", *p, lineno);
+				return false;
+			}
 
 			domainName = String(line.c_str() + 1, p);
 
@@ -237,13 +244,16 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
 
 			// If no domain has been set, this config file is invalid!
 			if (domainName.empty()) {
-				error("Config file buggy: Key/value pair found outside a domain in line %d", lineno);
+				warning("Config file buggy: Key/value pair found outside a domain in line %d", lineno);
+				return false;
 			}
 
 			// Split string at '=' into 'key' and 'value'. First, find the "=" delimeter.
 			const char *p = strchr(t, '=');
-			if (!p)
-				error("Config file buggy: Junk found in line %d: '%s'", lineno, t);
+			if (!p) {
+				warning("Config file buggy: Junk found in line %d: '%s'", lineno, t);
+				return false;
+			}
 
 			// Extract the key/value pair
 			String key(t, p);
@@ -263,6 +273,8 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
 	}
 
 	addDomain(domainName, domain); // Add the last domain found
+
+	return true;
 }
 
 void ConfigManager::flushToDisk() {
diff --git a/common/config-manager.h b/common/config-manager.h
index bc510e71bc5..04e7cad678e 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -125,8 +125,8 @@ public:
 	static char const *const kCloudDomain;
 #endif
 
-	void                     loadDefaultConfigFile(const String &fallbackFilename); /*!< Load the default configuration file. */
-	void                     loadConfigFile(const String &filename, const String &fallbackFilename); /*!< Load a specific configuration file. */
+	bool                     loadDefaultConfigFile(const String &fallbackFilename); /*!< Load the default configuration file. */
+	bool                     loadConfigFile(const String &filename, const String &fallbackFilename); /*!< Load a specific configuration file. */
 
 	/**
 	 * Retrieve the config domain with the given name.
@@ -223,7 +223,7 @@ private:
 	ConfigManager();
 
 	bool            loadFallbackConfigFile(const String &filename);
-	void			loadFromStream(SeekableReadStream &stream);
+	bool			loadFromStream(SeekableReadStream &stream);
 	void			addDomain(const String &domainName, const Domain &domain);
 	void			writeDomain(WriteStream &stream, const String &name, const Domain &domain);
 	void			renameDomain(const String &oldName, const String &newName, DomainMap &map);


Commit: b4fcc02c87c1fa4ab4a38ffb9998d4f263db89a9
    https://github.com/scummvm/scummvm/commit/b4fcc02c87c1fa4ab4a38ffb9998d4f263db89a9
Author: Attaullah Ansari (mdattaullahansari152 at gmial.com)
Date: 2023-02-23T18:12:27+01:00

Commit Message:
BASE: Add option for the user to proceed with resetting configuration file or quitting ScummVM.

Changed paths:
    base/main.cpp


diff --git a/base/main.cpp b/base/main.cpp
index 048cb6d4d6b..c85d26fc12a 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -511,10 +511,11 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
 	if (settings.contains("initial-cfg"))
 		initConfigFilename = settings["initial-cfg"];
 
+	bool configLoadStatus;
 	if (settings.contains("config")) {
-		ConfMan.loadConfigFile(settings["config"], initConfigFilename);
+		configLoadStatus = ConfMan.loadConfigFile(settings["config"], initConfigFilename);
 	} else {
-		ConfMan.loadDefaultConfigFile(initConfigFilename);
+		configLoadStatus = ConfMan.loadDefaultConfigFile(initConfigFilename);
 	}
 
 	// Update the config file
@@ -638,6 +639,11 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
 	}
 	setupGraphics(system);
 
+	if (!configLoadStatus) {
+		GUI::MessageDialog alert(_("Bad config file format. overwrite?"), _("Yes"), _("Cancel"));
+		if (alert.runModal() != GUI::kMessageOK)
+   			return 0;
+	}
 	// Init the different managers that are used by the engines.
 	// Do it here to prevent fragmentation later
 	system.getAudioCDManager();




More information about the Scummvm-git-logs mailing list