aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/commandLine.cpp1
-rw-r--r--base/main.cpp2
-rw-r--r--base/plugins.cpp84
3 files changed, 87 insertions, 0 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 74a5982f32..5c823b2425 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -769,6 +769,7 @@ static Common::Error listSaves(const Common::String &target) {
const Plugin *plugin = nullptr;
PlainGameDescriptor game;
if (domain) {
+ EngineMan.upgradeTargetIfNecessary(target);
game = EngineMan.findTarget(target, &plugin);
} else {
game = EngineMan.findGame(target, &plugin);
diff --git a/base/main.cpp b/base/main.cpp
index 45c8e393b7..85fdbb2986 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -545,6 +545,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
while (0 != ConfMan.getActiveDomain()) {
saveLastLaunchedTarget(ConfMan.getActiveDomainName());
+ EngineMan.upgradeTargetIfNecessary(ConfMan.getActiveDomainName());
+
// Try to find a plugin which feels responsible for the specified game.
const Plugin *plugin = detectPlugin();
if (plugin) {
diff --git a/base/plugins.cpp b/base/plugins.cpp
index a64dbdd65c..ac98de4d15 100644
--- a/base/plugins.cpp
+++ b/base/plugins.cpp
@@ -675,6 +675,90 @@ PlainGameDescriptor EngineManager::findTarget(const Common::String &target, cons
return desc;
}
+void EngineManager::upgradeTargetIfNecessary(const Common::String &target) const {
+ Common::ConfigManager::Domain *domain = ConfMan.getDomain(target);
+ assert(domain);
+
+ if (!domain->contains("engineid")) {
+ upgradeTargetForEngineId(target);
+ }
+}
+
+void EngineManager::upgradeTargetForEngineId(const Common::String &target) const {
+ Common::ConfigManager::Domain *domain = ConfMan.getDomain(target);
+ assert(domain);
+
+ debug("Target '%s' lacks an engine ID, upgrading...", target.c_str());
+
+ Common::String oldGameId = domain->getVal("gameid");
+ Common::String path = domain->getVal("path");
+
+ // At this point the game ID and game path must be known
+ if (oldGameId.empty()) {
+ warning("The game ID is required to upgrade target '%s'", target.c_str());
+ return;
+ }
+ if (path.empty()) {
+ warning("The game path is required to upgrade target '%s'", target.c_str());
+ return;
+ }
+
+ // Game descriptor for the upgraded target
+ Common::String engineId;
+ Common::String newGameId;
+
+ // First, try to update entries for engines that previously used the "single id" system
+ // Search for an engine whose ID is the game ID
+ const Plugin *plugin = findPlugin(oldGameId);
+ if (plugin) {
+ // Run detection on the game path
+ Common::FSNode dir(path);
+ Common::FSList files;
+ if (!dir.getChildren(files, Common::FSNode::kListAll)) {
+ warning("Failed to access path '%s' when upgrading target '%s'", path.c_str(), target.c_str());
+ return;
+ }
+
+ // Take the first detection entry
+ const MetaEngine &metaEngine = plugin->get<MetaEngine>();
+ DetectedGames candidates = metaEngine.detectGames(files);
+ if (candidates.empty()) {
+ warning("No games supported by the engine '%s' were found in path '%s' when upgrading target '%s'",
+ metaEngine.getEngineId(), path.c_str(), target.c_str());
+ return;
+ }
+
+ engineId = candidates[0].engineId;
+ newGameId = candidates[0].gameId;
+ }
+
+ // Next, try to find an engine with the game ID in its supported games list
+ if (engineId.empty()) {
+ PlainGameDescriptor pgd = findGame(oldGameId, &plugin);
+ if (plugin) {
+ engineId = plugin->get<MetaEngine>().getEngineId();
+ newGameId = pgd.gameId;
+ }
+ }
+
+ if (engineId.empty() || newGameId.empty()) {
+ warning("No matching engine was found when upgrading target '%s'", target.c_str());
+ return;
+ }
+
+ domain->setVal("engineid", engineId);
+ domain->setVal("gameid", newGameId);
+
+ // Save a backup of the pre-upgrade gameId to the config file
+ if (newGameId != oldGameId) {
+ domain->setVal("oldgameid", oldGameId);
+ }
+
+ debug("Upgrade complete (engine ID '%s', game ID '%s')", engineId.c_str(), newGameId.c_str());
+
+ ConfMan.flushToDisk();
+}
+
// Music plugins
#include "audio/musicplugin.h"