Skip to content

Commit

Permalink
BACKENDS: Populate dlc list using getAllDLCs() response
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushdutt committed Jul 20, 2023
1 parent 15c78a3 commit 77e2e91
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
6 changes: 1 addition & 5 deletions backends/dlc/dlcmanager.h
Expand Up @@ -34,14 +34,13 @@ namespace DLC {

class DLCManager : public Common::Singleton<DLCManager> {

Common::Array<DLCDesc*> _dlcs;

Store *_store;

bool _isDLCDownloading = false;
Common::String _currentDownloadingDLC;

public:
Common::Array<DLCDesc*> _dlcs;
Common::Queue<DLCDesc*> _queuedDownloadTasks;

DLCManager();
Expand All @@ -52,9 +51,6 @@ class DLCManager : public Common::Singleton<DLCManager> {
// Runs only once in init()
void getAllDLCs(Common::Array<DLCDesc*> &dlcs);

// Requested by GUI to show all available DLCs in simple list view
Common::U32StringArray getDLCList();

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

Expand Down
40 changes: 38 additions & 2 deletions backends/dlc/scummvmcloud.cpp
Expand Up @@ -22,13 +22,49 @@
#include "backends/dlc/scummvmcloud.h"
#include "backends/dlc/dlcmanager.h"
#include "common/config-manager.h"
#include "common/formats/json.h"

namespace DLC {
namespace ScummVMCloud {

void ScummVMCloud::jsonCallbackGetAllDLCs(Networking::JsonResponse response) {
Common::JSONValue *json = (Common::JSONValue *)response.value;
if (json == nullptr || !json->isObject()) {
return;
}
// warning("%s", json->stringify(true).c_str());
Common::JSONObject result = json->asObject();
if (result.contains("entries")) {
Common::JSONArray items = result.getVal("entries")->asArray();
for (uint32 i = 0; i < items.size(); ++i) {
if (!Networking::CurlJsonRequest::jsonIsObject(items[i], "ScummVMCloud")) continue;
Common::JSONObject item = items[i]->asObject();
Common::String id = item.getVal("id")->asString();
Common::String name = item.getVal("name")->asString();
Common::String url = item.getVal("url")->asString();
uint32 size;
if (item.getVal("size")->isString()) {
size = item.getVal("size")->asString().asUint64();
} else {
size = item.getVal("size")->asIntegerNumber();
}
DLCMan._dlcs.push_back(new DLCDesc{name, id, url, size, i, DLCDesc::kAvailable});
}
}
}

void ScummVMCloud::errorCallbackGetAllDLCs(Networking::ErrorResponse error) {
warning("JsonRequest Error - getAllDLCs");
}

void ScummVMCloud::getAllDLCs(Common::Array<DLCDesc*> &dlcs) {
dlcs.push_back(new DLCDesc{"Beneath a Steel Sky - Freeware CD Version", "bass_cd", "https://downloads.scummvm.org/frs/extras/Beneath%20a%20Steel%20Sky/bass-cd-1.2.zip", 100, 0, DLCDesc::kAvailable});
dlcs.push_back(new DLCDesc{"Beneath a Steel Sky - Freeware Floppy Version", "bass_floppy", "https://downloads.scummvm.org/frs/extras/Beneath%20a%20Steel%20Sky/BASS-Floppy-1.3.zip", 230, 1, DLCDesc::kAvailable});
Common::String url("https://mocki.io/v1/0d86064d-1c04-41c8-a7b0-7e7e044b9b58"); // temporary mock api
Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(
new Common::Callback<ScummVMCloud, Networking::JsonResponse>(this, &ScummVMCloud::jsonCallbackGetAllDLCs),
new Common::Callback<ScummVMCloud, Networking::ErrorResponse>(this, &ScummVMCloud::errorCallbackGetAllDLCs),
url);

request->execute();
}

void ScummVMCloud::downloadFileCallback(Networking::DataResponse r) {
Expand Down
6 changes: 6 additions & 0 deletions backends/dlc/scummvmcloud.h
Expand Up @@ -26,6 +26,7 @@
#include "backends/dlc/dlcdesc.h"
#include "backends/networking/curl/session.h"
#include "backends/networking/curl/request.h"
#include "backends/networking/curl/curljsonrequest.h"
#include "common/queue.h"

namespace DLC {
Expand Down Expand Up @@ -55,6 +56,11 @@ Networking::Session session;

virtual void startDownloadAsync(const Common::String &id, const Common::String &url) override;

// callback functions
void jsonCallbackGetAllDLCs(Networking::JsonResponse response);

void errorCallbackGetAllDLCs(Networking::ErrorResponse error);

void downloadFileCallback(Networking::DataResponse response);

void errorCallback(Networking::ErrorResponse error);
Expand Down
18 changes: 5 additions & 13 deletions gui/download-games-dialog.cpp
Expand Up @@ -43,18 +43,10 @@ DownloadGamesDialog::DownloadGamesDialog()
_gamesList->setEditable(false);

// Populate the ListWidget
Common::U32StringArray games = {
_("Beneath a Steel Sky - Freeware CD Version"),
_("Beneath a Steel Sky - Freeware Floppy Version"),
_("Broken Sword 2.5: The Return of the Templars - Freeware Version"),
_("Broken Sword 2.5: The Return of the Templars - Hebrew translation AddOn"),
_("Dráscula: The Vampire Strikes Back - Freeware Version (English)"),
_("Dráscula: The Vampire Strikes Back - Freeware Version (Music AddOn, MP3 format)"),
_("Dráscula: The Vampire Strikes Back - Freeware Version (Music AddOn, FLAC format)"),
_("Dráscula: The Vampire Strikes Back - Freeware Version (Music AddOn, OGG format)"),
_("Dráscula: The Vampire Strikes Back - Freeware Version (Spanish, German, French and Italian AddOn)"),
_("Dráscula: The Vampire Strikes Back - Freeware Version (Updated Spanish, German, French and Italian AddOn) - requires ScummVM 1.3.0 or more"),
};
Common::U32StringArray games;
for (int i = 0; i < DLCMan._dlcs.size(); ++i) {
games.push_back(DLCMan._dlcs[i]->name);
}

// Gray out already downloaded packages
for (Common::ConfigManager::DomainMap::iterator domain = ConfMan.beginGameDomains(); domain != ConfMan.endGameDomains(); ++domain) {
Expand All @@ -79,7 +71,7 @@ void DownloadGamesDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
case kDownloadSelectedCmd: {
MessageDialog dialog("Downloading: " + _gamesList->getSelectedString());
dialog.runModal();
DLCMan.addDownload(1);
DLCMan.addDownload(_gamesList->getSelected());
}
break;
default:
Expand Down

0 comments on commit 77e2e91

Please sign in to comment.