mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-24 05:01:43 +00:00
BACKENDS: Initial code for downloading DLCs using CURL
This commit is contained in:
parent
478d3f2ab9
commit
c0f91421cc
49
backends/dlc/dlcdesc.h
Normal file
49
backends/dlc/dlcdesc.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DLC_DLCT_H
|
||||
#define DLC_DLCT_H
|
||||
|
||||
#include "common/str.h"
|
||||
|
||||
namespace DLC {
|
||||
|
||||
class DLCDesc {
|
||||
|
||||
public:
|
||||
enum State {
|
||||
kAvailable,
|
||||
kInProgress,
|
||||
kDownloaded,
|
||||
kCancelled,
|
||||
kErrorDownloading
|
||||
};
|
||||
Common::String name;
|
||||
Common::String id;
|
||||
uint32 size;
|
||||
uint32 idx;
|
||||
State state;
|
||||
};
|
||||
|
||||
|
||||
} // End of namespace DLC
|
||||
|
||||
#endif
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include "backends/dlc/android/playstore.h"
|
||||
#include "backends/dlc/dlcmanager.h"
|
||||
#include "backends/dlc/scummvmcloud.h"
|
||||
#include "backends/dlc/android/playstore.h"
|
||||
#include "common/system.h"
|
||||
|
||||
namespace Common {
|
||||
@ -33,48 +35,49 @@ DECLARE_SINGLETON(DLC::DLCManager);
|
||||
namespace DLC {
|
||||
|
||||
DLCManager::DLCManager() {
|
||||
_store = g_system->getDLCStore();
|
||||
// _store = g_system->getDLCStore();
|
||||
// TODO: Handle creation through getDLCStore()
|
||||
_store = new DLC::ScummVMCloud::ScummVMCloud();
|
||||
}
|
||||
|
||||
void DLCManager::init() {
|
||||
getAllDLCs(_dlcs);
|
||||
DLCManager::getAllDLCs(_dlcs);
|
||||
}
|
||||
|
||||
void DLCManager::getAllDLCs(Common::Array<DLC*>& dlcs) {
|
||||
// if distribution store's API available call it else hardcode
|
||||
void DLCManager::getAllDLCs(Common::Array<DLCDesc*> &dlcs) {
|
||||
_store->getAllDLCs(dlcs);
|
||||
}
|
||||
|
||||
void DLCManager::addDownload(uint32 idx) {
|
||||
_dlcs[idx]->state = kInProgress;
|
||||
_dlcs[idx]->state = DLCDesc::kInProgress;
|
||||
_queuedDownloadTasks.push(_dlcs[idx]);
|
||||
if (!_isDLCDownloading) {
|
||||
DLCManager::processDownload();
|
||||
// if queue is not already processing
|
||||
DLCManager::processDownloadQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void DLCManager::processDownload() {
|
||||
void DLCManager::processDownloadQueue() {
|
||||
_isDLCDownloading = true;
|
||||
if (!_queuedDownloadTasks.empty()) {
|
||||
if (_dlcs[_queuedDownloadTasks.front()->idx]->state == kInProgress) {
|
||||
_isDLCDownloading = true;
|
||||
if (_queuedDownloadTasks.front()->state == DLCDesc::kInProgress) {
|
||||
_currentDownloadingDLC = _queuedDownloadTasks.front()->id;
|
||||
DLCManager::startDownloadAsync(_queuedDownloadTasks.front()->id, &DLCManager::cb);
|
||||
DLCManager::startDownloadAsync(_queuedDownloadTasks.front()->id);
|
||||
} else {
|
||||
// state is already cancelled/downloaded -> skip download
|
||||
_queuedDownloadTasks.pop();
|
||||
// process next download in the queue
|
||||
processDownload();
|
||||
processDownloadQueue();
|
||||
}
|
||||
} else {
|
||||
// no more download in queue
|
||||
_isDLCDownloading = false;
|
||||
_currentDownloadingDLC = "";
|
||||
}
|
||||
}
|
||||
|
||||
void DLCManager::cb() {
|
||||
// if finished successfully
|
||||
_dlcs[_queuedDownloadTasks.front()->idx]->state = kDownloaded;
|
||||
_queuedDownloadTasks.pop();
|
||||
// process next download in the queue
|
||||
DLCManager::processDownload();
|
||||
void DLCManager::startDownloadAsync(Common::String &id) {
|
||||
_store->startDownloadAsync(id);
|
||||
}
|
||||
|
||||
bool DLCManager::cancelDownload(uint32 idx) {
|
||||
@ -82,7 +85,7 @@ bool DLCManager::cancelDownload(uint32 idx) {
|
||||
// if already downloading, interrupt startDownloadAsync
|
||||
} else {
|
||||
// if not started, skip it in processDownload()
|
||||
_dlcs[idx]->state = kCancelled;
|
||||
_dlcs[idx]->state = DLCDesc::kCancelled;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -27,42 +27,30 @@
|
||||
#include "common/queue.h"
|
||||
#include "common/singleton.h"
|
||||
#include "backends/dlc/store.h"
|
||||
#include "backends/dlc/dlcdesc.h"
|
||||
#include "backends/networking/curl/request.h"
|
||||
|
||||
namespace DLC {
|
||||
|
||||
enum State {
|
||||
kAvailable,
|
||||
kInProgress,
|
||||
kDownloaded,
|
||||
kCancelled
|
||||
};
|
||||
|
||||
struct DLC {
|
||||
Common::String name;
|
||||
Common::String id;
|
||||
uint32 size;
|
||||
uint32 idx;
|
||||
State state;
|
||||
};
|
||||
|
||||
class DLCManager : public Common::Singleton<DLCManager> {
|
||||
|
||||
Common::Array<DLC*> _dlcs;
|
||||
Common::Queue<DLC*> _queuedDownloadTasks;
|
||||
Common::Array<DLCDesc*> _dlcs;
|
||||
|
||||
Store* _store;
|
||||
Store *_store;
|
||||
|
||||
bool _isDLCDownloading = false;
|
||||
Common::String _currentDownloadingDLC;
|
||||
|
||||
public:
|
||||
Common::Queue<DLCDesc*> _queuedDownloadTasks;
|
||||
|
||||
DLCManager();
|
||||
virtual ~DLCManager() {}
|
||||
|
||||
void init();
|
||||
|
||||
// Runs only once in init()
|
||||
void getAllDLCs(Common::Array<DLC*>& dlcs);
|
||||
void getAllDLCs(Common::Array<DLCDesc*> &dlcs);
|
||||
|
||||
// Requested by GUI to show all available DLCs in simple list view
|
||||
Common::U32StringArray getDLCList();
|
||||
@ -72,18 +60,18 @@ public:
|
||||
|
||||
bool cancelDownload(uint32 idx);
|
||||
|
||||
void processDownload();
|
||||
void processDownloadQueue();
|
||||
|
||||
// Returns the % download progress of current downloading game
|
||||
uint32 downloadProgress();
|
||||
|
||||
Common::String getCurrentDownloadingDLC();
|
||||
|
||||
// Callback function for startDownloadAsync
|
||||
void cb();
|
||||
void startDownloadAsync(Common::String &id);
|
||||
|
||||
void startDownloadAsync(Common::String id, void(DLCManager::*callback)()) {}
|
||||
void errorCallback(Networking::ErrorResponse error);
|
||||
|
||||
void downloadFileCallback(Networking::DataResponse r);
|
||||
};
|
||||
|
||||
#define DLCMan DLC::DLCManager::instance()
|
||||
|
63
backends/dlc/scummvmcloud.cpp
Normal file
63
backends/dlc/scummvmcloud.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "backends/dlc/scummvmcloud.h"
|
||||
#include "backends/dlc/dlcmanager.h"
|
||||
#include "common/config-manager.h"
|
||||
|
||||
namespace DLC {
|
||||
namespace ScummVMCloud {
|
||||
|
||||
void ScummVMCloud::getAllDLCs(Common::Array<DLCDesc*> &dlcs) {
|
||||
dlcs.push_back(new DLCDesc{"Beneath a Steel Sky - Freeware CD Version", "bass_cd", 100, 0, DLCDesc::kAvailable});
|
||||
dlcs.push_back(new DLCDesc{"Beneath a Steel Sky - Freeware Floppy Version", "bass_floppy", 230, 1, DLCDesc::kAvailable});
|
||||
}
|
||||
|
||||
void ScummVMCloud::downloadFileCallback(Networking::DataResponse r) {
|
||||
Networking::SessionFileResponse *response = static_cast<Networking::SessionFileResponse *>(r.value);
|
||||
if (response->eos) {
|
||||
warning("downloaded");
|
||||
DLCMan._queuedDownloadTasks.front()->state = DLCDesc::kDownloaded;
|
||||
DLCMan._queuedDownloadTasks.pop();
|
||||
DLCMan.processDownloadQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void ScummVMCloud::errorCallback(Networking::ErrorResponse error) {
|
||||
// error downloading - start next download in queue
|
||||
DLCMan._queuedDownloadTasks.front()->state = DLCDesc::kErrorDownloading;
|
||||
DLCMan._queuedDownloadTasks.pop();
|
||||
DLCMan.processDownloadQueue();
|
||||
}
|
||||
|
||||
void ScummVMCloud::startDownloadAsync(Common::String &id) {
|
||||
Common::String url = Common::String::format("https://downloads.scummvm.org/frs/extras/Beneath%%20a%%20Steel%%20Sky/bass-cd-1.2.zip");
|
||||
Common::String localFile = "";
|
||||
|
||||
Networking::SessionRequest *rq = session.get(url, localFile,
|
||||
new Common::Callback<ScummVMCloud, Networking::DataResponse>(this, &ScummVMCloud::downloadFileCallback),
|
||||
new Common::Callback<ScummVMCloud, Networking::ErrorResponse>(this, &ScummVMCloud::errorCallback));
|
||||
|
||||
rq->start();
|
||||
}
|
||||
|
||||
} // End of namespace ScummVMCloud
|
||||
} // End of namespace DLC
|
66
backends/dlc/scummvmcloud.h
Normal file
66
backends/dlc/scummvmcloud.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_DLC_ScummVMCloud_ScummVMCloud_H
|
||||
#define BACKENDS_DLC_ScummVMCloud_ScummVMCloud_H
|
||||
|
||||
#include "backends/dlc/store.h"
|
||||
#include "backends/dlc/dlcdesc.h"
|
||||
#include "backends/networking/curl/session.h"
|
||||
#include "backends/networking/curl/request.h"
|
||||
#include "common/queue.h"
|
||||
|
||||
namespace DLC {
|
||||
namespace ScummVMCloud {
|
||||
|
||||
class ScummVMCloud: public DLC::Store {
|
||||
|
||||
Networking::Session session;
|
||||
|
||||
public:
|
||||
ScummVMCloud() {}
|
||||
virtual ~ScummVMCloud() {}
|
||||
|
||||
virtual void init() override {}
|
||||
|
||||
virtual void requestInfo() override {}
|
||||
|
||||
virtual void getDownloadState() override {}
|
||||
|
||||
virtual void requestDownload() override {}
|
||||
|
||||
virtual void getBytesDownloaded() override {}
|
||||
|
||||
virtual void cancelDownload() override {}
|
||||
|
||||
virtual void getAllDLCs(Common::Array<DLCDesc*> &dlcs) override;
|
||||
|
||||
virtual void startDownloadAsync(Common::String &id) override;
|
||||
|
||||
void downloadFileCallback(Networking::DataResponse response);
|
||||
|
||||
void errorCallback(Networking::ErrorResponse error);
|
||||
};
|
||||
|
||||
} // End of namespace ScummVMCloud
|
||||
} // End of namespace DLC
|
||||
|
||||
#endif
|
@ -22,6 +22,11 @@
|
||||
#ifndef DLC_STORE_H
|
||||
#define DLC_STORE_H
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/array.h"
|
||||
#include "common/queue.h"
|
||||
#include "backends/dlc/dlcdesc.h"
|
||||
|
||||
namespace DLC {
|
||||
|
||||
class Store {
|
||||
@ -41,6 +46,11 @@ public:
|
||||
virtual void getBytesDownloaded() = 0;
|
||||
|
||||
virtual void cancelDownload() = 0;
|
||||
|
||||
virtual void getAllDLCs(Common::Array<DLCDesc*> &dlcs) = 0;
|
||||
|
||||
virtual void startDownloadAsync(Common::String &id) = 0;
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace DLC
|
||||
|
@ -79,7 +79,8 @@ MODULE_OBJS += \
|
||||
networking/curl/session.o \
|
||||
networking/curl/sessionrequest.o \
|
||||
networking/curl/socket.o \
|
||||
networking/curl/url.o
|
||||
networking/curl/url.o \
|
||||
dlc/scummvmcloud.o
|
||||
endif
|
||||
|
||||
ifdef USE_SDL_NET
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "gui/widget.h"
|
||||
#include "gui/widgets/list.h"
|
||||
#include "common/translation.h"
|
||||
#include "backends/dlc/dlcmanager.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
@ -78,6 +79,7 @@ void DownloadGamesDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
|
||||
case kDownloadSelectedCmd: {
|
||||
MessageDialog dialog("Downloading: " + _gamesList->getSelectedString());
|
||||
dialog.runModal();
|
||||
DLCMan.addDownload(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user