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

sev- noreply at scummvm.org
Wed Jan 11 13:46:46 UTC 2023


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

Summary:
3a07524b73 COMMON: Add initial config file option.
3d725a176d DOCS: Update command line arguments to include initial config option.
f71a2e5aaf NEWS: Add mention of --initial-cfg/-i option.  Fix typo.


Commit: 3a07524b7319ab02a591f4a8dfe2e38bb6ab9e7d
    https://github.com/scummvm/scummvm/commit/3a07524b7319ab02a591f4a8dfe2e38bb6ab9e7d
Author: elasota (ejlasota at gmail.com)
Date: 2023-01-11T14:46:39+01:00

Commit Message:
COMMON: Add initial config file option.

This allows an initial/default configuration file to be specified via the command line.  This allows a default settings file to be bundled and loaded even if it's installed to a read-only location, such as Program Files on Windows, and allows the written config file to be deleted without losing the custom defaults.

Changed paths:
    base/commandLine.cpp
    base/main.cpp
    common/config-manager.cpp
    common/config-manager.h


diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 772843abef1..20fd0fafe84 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -94,7 +94,8 @@ static const char HELP_STRING1[] =
 	"  --console                Enable the console window (default:enabled)\n"
 #endif
 	"\n"
-	"  -c, --config=CONFIG      Use alternate configuration file\n"
+	"  -c, --config=CONFIG      Use alternate configuration file path\n"
+	"  -i, --initial-cfg=CONFIG Load an initial configuration file if no configuration file has been saved yet\n"
 #if defined(SDL_BACKEND)
 	"  -l, --logfile=PATH       Use alternate path for log file\n"
 	"  --screenshotpath=PATH    Specify path where screenshot files are created\n"
@@ -633,6 +634,9 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
 			DO_OPTION('c', "config")
 			END_OPTION
 
+			DO_OPTION('i', "initial-cfg")
+			END_OPTION
+
 #if defined(SDL_BACKEND)
 			DO_OPTION('l', "logfile")
 			END_OPTION
@@ -1884,6 +1888,7 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo
 	// Finally, store the command line settings into the config manager.
 	static const char * const sessionSettings[] = {
 		"config",
+		"initial-cfg",
 		"fullscreen",
 		"gfx-mode",
 		"stretch-mode",
diff --git a/base/main.cpp b/base/main.cpp
index 18fcbacaf17..19534c84530 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -493,10 +493,14 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
 		command = autoCommand;
 
 	// Load the config file (possibly overridden via command line):
+	Common::String initConfigFilename;
+	if (settings.contains("initial-cfg"))
+		initConfigFilename = settings["initial-cfg"];
+
 	if (settings.contains("config")) {
-		ConfMan.loadConfigFile(settings["config"]);
+		ConfMan.loadConfigFile(settings["config"], initConfigFilename);
 	} else {
-		ConfMan.loadDefaultConfigFile();
+		ConfMan.loadDefaultConfigFile(initConfigFilename);
 	}
 
 	// Update the config file
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 9c637c856e4..d530fd8dd86 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -78,7 +78,7 @@ void ConfigManager::copyFrom(ConfigManager &source) {
 }
 
 
-void ConfigManager::loadDefaultConfigFile() {
+void ConfigManager::loadDefaultConfigFile(const String &fallbackFilename) {
 	// Open the default config file
 	assert(g_system);
 	SeekableReadStream *stream = g_system->createConfigReadStream();
@@ -92,26 +92,41 @@ void ConfigManager::loadDefaultConfigFile() {
 		delete stream;
 
 	} else {
-		// No config file -> create new one!
-		debug("Default configuration file missing, creating a new one");
+		// No config file -> try to load fallback, flush initial config to disk
+		if (!loadFallbackConfigFile(fallbackFilename))
+			debug("Default configuration file missing, creating a new one");
 
 		flushToDisk();
 	}
 }
 
-void ConfigManager::loadConfigFile(const String &filename) {
+void ConfigManager::loadConfigFile(const String &filename, const String &fallbackFilename) {
 	_filename = filename;
 
 	FSNode node(filename);
 	File cfg_file;
 	if (!cfg_file.open(node)) {
-		debug("Creating configuration file: %s", filename.c_str());
+		if (!loadFallbackConfigFile(fallbackFilename))
+			debug("Creating configuration file: %s", filename.c_str());
 	} else {
 		debug("Using configuration file: %s", _filename.c_str());
 		loadFromStream(cfg_file);
 	}
 }
 
+bool ConfigManager::loadFallbackConfigFile(const String &filename) {
+	if (filename.empty())
+		return false;
+
+	File fallbackFile;
+	if (!fallbackFile.open(FSNode(filename)))
+		return false;
+
+	debug("Using initial configuration file: %s", filename.c_str());
+	loadFromStream(fallbackFile);
+	return true;
+}
+
 /**
  * Add a ready-made domain based on its name and contents
  * The domain name should not already exist in the ConfigManager.
diff --git a/common/config-manager.h b/common/config-manager.h
index 854b0ec2b92..bc510e71bc5 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -125,8 +125,8 @@ public:
 	static char const *const kCloudDomain;
 #endif
 
-	void                     loadDefaultConfigFile(); /*!< Load the default configuration file. */
-	void                     loadConfigFile(const String &filename); /*!< Load a specific configuration file. */
+	void                     loadDefaultConfigFile(const String &fallbackFilename); /*!< Load the default configuration file. */
+	void                     loadConfigFile(const String &filename, const String &fallbackFilename); /*!< Load a specific configuration file. */
 
 	/**
 	 * Retrieve the config domain with the given name.
@@ -222,6 +222,7 @@ private:
 	friend class Singleton<SingletonBaseType>;
 	ConfigManager();
 
+	bool            loadFallbackConfigFile(const String &filename);
 	void			loadFromStream(SeekableReadStream &stream);
 	void			addDomain(const String &domainName, const Domain &domain);
 	void			writeDomain(WriteStream &stream, const String &name, const Domain &domain);


Commit: 3d725a176d9771f0e449c52a5902616ddcf316ee
    https://github.com/scummvm/scummvm/commit/3d725a176d9771f0e449c52a5902616ddcf316ee
Author: elasota (ejlasota at gmail.com)
Date: 2023-01-11T14:46:39+01:00

Commit Message:
DOCS: Update command line arguments to include initial config option.

Changed paths:
    doc/docportal/advanced_topics/command_line.rst


diff --git a/doc/docportal/advanced_topics/command_line.rst b/doc/docportal/advanced_topics/command_line.rst
index aef9dddf413..f8c7c125594 100755
--- a/doc/docportal/advanced_topics/command_line.rst
+++ b/doc/docportal/advanced_topics/command_line.rst
@@ -160,7 +160,8 @@ Short options are listed where they are available.
         ``--auto-detect``,,"Displays a list of games from the current or specified directory and starts the first game. Use ``--path=PATH`` before ``--auto-detect`` to specify a directory."
         ``--boot-param=NUM``,``-b``,"Pass number to the boot script (`boot param <https://wiki.scummvm.org/index.php/Boot_Params>`_)."
         ``--cdrom=DRIVE``,,"Sets the CD drive to play CD audio from. This can be a drive, path, or numeric index (default: 0)"
-        ``--config=FILE``,``-c``,"Uses alternate configuration file"
+        ``--config=FILE``,``-c``,"Uses alternate configuration file path"
+        ``--initial-cfg=FILE``,``-i``,"Loads an initial configuration file if no configuration file has been saved yet."
         ``--console``,,"Enables the console window (default: enabled). Win32 and Symbian32 only."
         ``--copy-protection``,,"Enables copy protection"
         ``--debug-channels-only``,,"Shows only the specified debug channels"


Commit: f71a2e5aafb6cfddef278bd8c23a2b41c057b4c3
    https://github.com/scummvm/scummvm/commit/f71a2e5aafb6cfddef278bd8c23a2b41c057b4c3
Author: elasota (ejlasota at gmail.com)
Date: 2023-01-11T14:46:39+01:00

Commit Message:
NEWS: Add mention of --initial-cfg/-i option.  Fix typo.

Changed paths:
    NEWS.md


diff --git a/NEWS.md b/NEWS.md
index 7adfbc3a4ae..7e5250f05bc 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -23,11 +23,14 @@ For a more comprehensive changelog of the latest experimental code, see:
    - Improved cursor scaling in OpenGL mode.
    - Fix crash when browsing folders containing files with \1 in the names.
    - Added possibility to specify RNG seed via GUI or command line option.
-   - Added possibility to run ScummVM in autodetection name by renaming the
+   - Added possibility to run ScummVM in autodetection mode by renaming the
      executable starting with 'scummvm-auto' or by providing an empty file
      named 'scummvm-autorun' next to the ScummVM executable.
    - Added possibility to supply command line parameters which will be picked
      up automatically. Put them one per line in a file named 'scummvm-autorun'.
+   - Added possibility to customize the default settings by specifying an initial
+     configuration file to load if no configuration file exists in the usual
+     location (via --initial-cfg=FILE or -i command line option).
 
  AGI:
    - Improved support for French translations.




More information about the Scummvm-git-logs mailing list