Skip to content

Commit

Permalink
BACKENDS: Implement auto addition of DLC entry in ScummVM config afte…
Browse files Browse the repository at this point in the history
…r download
  • Loading branch information
ankushdutt committed Jul 27, 2023
1 parent fa6944e commit b976a7b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
4 changes: 4 additions & 0 deletions backends/dlc/dlcmanager.cpp
Expand Up @@ -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]);
Expand Down
2 changes: 2 additions & 0 deletions backends/dlc/dlcmanager.h
Expand Up @@ -55,6 +55,8 @@ class DLCManager : public Common::Singleton<DLCManager>, public GUI::CommandSend

void refreshDLCList();

void refreshLauncherGameList();

// Add download task to queue, runs on click download button,
void addDownload(uint32 idx);

Expand Down
32 changes: 32 additions & 0 deletions backends/dlc/scummvmcloud.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions backends/dlc/scummvmcloud.h
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions gui/download-games-dialog.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion gui/download-games-dialog.h
Expand Up @@ -24,24 +24,27 @@

#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;

void refreshDLCList();

private:
ListWidget *_gamesList;
LauncherDialog *_launcher;
};

} // End of namespace GUI
Expand Down
2 changes: 1 addition & 1 deletion gui/launcher.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit b976a7b

Please sign in to comment.