From b976a7bffe7a91352466eee7adb69e00660dcd70 Mon Sep 17 00:00:00 2001 From: Ankush Dutt Date: Thu, 27 Jul 2023 22:49:59 +0530 Subject: [PATCH] BACKENDS: Implement auto addition of DLC entry in ScummVM config after download --- backends/dlc/dlcmanager.cpp | 4 ++++ backends/dlc/dlcmanager.h | 2 ++ backends/dlc/scummvmcloud.cpp | 32 ++++++++++++++++++++++++++++++++ backends/dlc/scummvmcloud.h | 2 ++ gui/download-games-dialog.cpp | 8 ++++++-- gui/download-games-dialog.h | 5 ++++- gui/launcher.cpp | 2 +- 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/backends/dlc/dlcmanager.cpp b/backends/dlc/dlcmanager.cpp index c6fd57cd1f95..d7d180c3397e 100644 --- a/backends/dlc/dlcmanager.cpp +++ b/backends/dlc/dlcmanager.cpp @@ -51,6 +51,10 @@ void DLCManager::refreshDLCList() { sendCommand(GUI::kRefreshDLCList, 0); } +void DLCManager::refreshLauncherGameList() { + sendCommand(GUI::kRefreshLauncher, 0); +} + void DLCManager::addDownload(uint32 idx) { _dlcs[idx]->state = DLCDesc::kInProgress; _queuedDownloadTasks.push(_dlcs[idx]); diff --git a/backends/dlc/dlcmanager.h b/backends/dlc/dlcmanager.h index 16a8274ac332..78aed85b7ae7 100644 --- a/backends/dlc/dlcmanager.h +++ b/backends/dlc/dlcmanager.h @@ -55,6 +55,8 @@ class DLCManager : public Common::Singleton, public GUI::CommandSend void refreshDLCList(); + void refreshLauncherGameList(); + // Add download task to queue, runs on click download button, void addDownload(uint32 idx); diff --git a/backends/dlc/scummvmcloud.cpp b/backends/dlc/scummvmcloud.cpp index 4da64a943130..dcd6c6c0a2e2 100644 --- a/backends/dlc/scummvmcloud.cpp +++ b/backends/dlc/scummvmcloud.cpp @@ -33,6 +33,8 @@ #include "backends/dlc/dlcmanager.h" #include "common/config-manager.h" #include "common/formats/json.h" +#include "engines/metaengine.h" +#include "gui/gui-manager.h" namespace DLC { namespace ScummVMCloud { @@ -98,6 +100,8 @@ void ScummVMCloud::downloadFileCallback(Networking::DataResponse r) { extractZip(relativeFilePath, destPath); // remove cache (the downloaded .zip) removeCacheFile(relativeFilePath); + // add downloaded game entry in scummvm configuration file + addEntryToConfig(destPath); // handle next download DLCMan._queuedDownloadTasks.front()->state = DLCDesc::kDownloaded; DLCMan._queuedDownloadTasks.pop(); @@ -150,5 +154,33 @@ void ScummVMCloud::removeCacheFile(Common::Path file) { #endif } +void ScummVMCloud::addEntryToConfig(Common::Path gamePath) { + Common::FSNode dir(gamePath); + Common::FSList fsnodes; + if (!dir.getChildren(fsnodes, Common::FSNode::kListAll)) { + warning("ScummVMCloud::addEntryToConfig(): Game directory does not exists"); + return; + } + if (fsnodes.size() == 1 && fsnodes[0].isDirectory()) { + // if extraction process created a new folder inside gamePath, set gamePath to that directory + gamePath = gamePath.appendComponent(fsnodes[0].getFileName()); + } + // add a new entry in scummvm config file + Common::String domain = EngineMan.generateUniqueDomain(DLCMan._queuedDownloadTasks.front()->gameid); + ConfMan.addGameDomain(domain); + ConfMan.set("engineid", DLCMan._queuedDownloadTasks.front()->engineid, domain); + ConfMan.set("gameid", DLCMan._queuedDownloadTasks.front()->gameid, domain); + ConfMan.set("description", DLCMan._queuedDownloadTasks.front()->description, domain); + ConfMan.set("language", DLCMan._queuedDownloadTasks.front()->language, domain); + ConfMan.set("platform", DLCMan._queuedDownloadTasks.front()->platform, domain); + ConfMan.set("path", gamePath.toString(), domain); + ConfMan.set("extra", DLCMan._queuedDownloadTasks.front()->extra, domain); + ConfMan.set("guioptions", DLCMan._queuedDownloadTasks.front()->guioptions, domain); + ConfMan.set("download", DLCMan._queuedDownloadTasks.front()->id, domain); + + // send refresh launcher command to GUI + DLCMan.refreshLauncherGameList(); +} + } // End of namespace ScummVMCloud } // End of namespace DLC diff --git a/backends/dlc/scummvmcloud.h b/backends/dlc/scummvmcloud.h index 37e63687bc23..d5509855f26c 100644 --- a/backends/dlc/scummvmcloud.h +++ b/backends/dlc/scummvmcloud.h @@ -61,6 +61,8 @@ Networking::SessionRequest *_rq; // extracts the provided zip in the provided destination path void extractZip(const Common::Path &file, const Common::Path &destPath); + void addEntryToConfig(Common::Path gamePath); + // callback functions void jsonCallbackGetAllDLCs(Networking::JsonResponse response); diff --git a/gui/download-games-dialog.cpp b/gui/download-games-dialog.cpp index 6cade6de66a1..2625cdc00639 100644 --- a/gui/download-games-dialog.cpp +++ b/gui/download-games-dialog.cpp @@ -29,8 +29,8 @@ namespace GUI { -DownloadGamesDialog::DownloadGamesDialog() - : Dialog("DownloadGames") { +DownloadGamesDialog::DownloadGamesDialog(LauncherDialog *launcher) + : Dialog("DownloadGames"), _launcher(launcher) { // Set target (Command Receiver) for Command Sender DLCMan.setTarget(this); @@ -91,6 +91,10 @@ void DownloadGamesDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 refreshDLCList(); } break; + case kRefreshLauncher: { + _launcher->rebuild(); + } + break; default: Dialog::handleCommand(sender, cmd, data); } diff --git a/gui/download-games-dialog.h b/gui/download-games-dialog.h index 3afd4113ba33..68640e8d1e41 100644 --- a/gui/download-games-dialog.h +++ b/gui/download-games-dialog.h @@ -24,17 +24,19 @@ #include "gui/dialog.h" #include "gui/widgets/list.h" +#include "gui/launcher.h" namespace GUI { enum { kDownloadSelectedCmd = 'DWNS', kRefreshDLCList = 'RDLC', + kRefreshLauncher = 'RFLR' }; class DownloadGamesDialog : public Dialog { public: - DownloadGamesDialog(); + DownloadGamesDialog(LauncherDialog *launcher); void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override; @@ -42,6 +44,7 @@ class DownloadGamesDialog : public Dialog { private: ListWidget *_gamesList; + LauncherDialog *_launcher; }; } // End of namespace GUI diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 3aac8b46ca45..cb4ac01c05cf 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -735,7 +735,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat massAddGame(); break; case kDownloadGameCmd: { - DownloadGamesDialog downloader; + DownloadGamesDialog downloader(this); downloader.runModal(); } break;