aboutsummaryrefslogtreecommitdiff
path: root/base/plugins.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'base/plugins.cpp')
-rw-r--r--base/plugins.cpp84
1 files changed, 84 insertions, 0 deletions
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"