Skip to content

Commit

Permalink
BACKENDS: Implement extract downloaded DLCs and remove cache in Scumm…
Browse files Browse the repository at this point in the history
…VMCloud
  • Loading branch information
ankushdutt committed Jul 21, 2023
1 parent 77e2e91 commit 314ff70
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
38 changes: 38 additions & 0 deletions backends/dlc/scummvmcloud.cpp
Expand Up @@ -19,6 +19,15 @@
*
*/

#if defined(POSIX)
#define FORBIDDEN_SYMBOL_EXCEPTION_unlink

#include <unistd.h>
#endif

#include "common/archive.h"
#include "common/compression/unzip.h"
#include "common/file.h"
#include "backends/dlc/scummvmcloud.h"
#include "backends/dlc/dlcmanager.h"
#include "common/config-manager.h"
Expand Down Expand Up @@ -71,6 +80,12 @@ void ScummVMCloud::downloadFileCallback(Networking::DataResponse r) {
Networking::SessionFileResponse *response = static_cast<Networking::SessionFileResponse *>(r.value);
if (response->eos) {
warning("downloaded");
Common::Path relativeFilePath = Common::Path(DLCMan._queuedDownloadTasks.front()->id);
// extract the downloaded zip
extractZip(relativeFilePath);
// remove cache (the downloaded .zip)
removeCacheFile(relativeFilePath);
// handle next download
DLCMan._queuedDownloadTasks.front()->state = DLCDesc::kDownloaded;
DLCMan._queuedDownloadTasks.pop();
DLCMan.processDownloadQueue();
Expand All @@ -95,5 +110,28 @@ void ScummVMCloud::startDownloadAsync(const Common::String &id, const Common::St
rq->start();
}

void ScummVMCloud::extractZip(Common::Path file) {
Common::Archive *dataArchive = nullptr;
Common::Path dlcPath = Common::Path(ConfMan.get("iconspath"));
Common::FSNode *fs = new Common::FSNode(dlcPath.join(file));
if (fs->exists()) {
dataArchive = Common::makeZipArchive(*fs);
// dataArchive is nullptr if zip file is incomplete
if (dataArchive != nullptr) {
dataArchive->dumpArchive(dlcPath.toString());
}
}
delete fs;
delete dataArchive;
}

void ScummVMCloud::removeCacheFile(Common::Path file) {
Common::Path dlcPath = Common::Path(ConfMan.get("iconspath"));
Common::Path fileToDelete = dlcPath.join(file);
#if defined(POSIX)
unlink(fileToDelete.toString().c_str());
#endif
}

} // End of namespace ScummVMCloud
} // End of namespace DLC
4 changes: 4 additions & 0 deletions backends/dlc/scummvmcloud.h
Expand Up @@ -56,6 +56,10 @@ Networking::Session session;

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

virtual void removeCacheFile(Common::Path file) override;

void extractZip(Common::Path file);

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

Expand Down
2 changes: 2 additions & 0 deletions backends/dlc/store.h
Expand Up @@ -25,6 +25,7 @@
#include "common/str.h"
#include "common/array.h"
#include "common/queue.h"
#include "common/path.h"
#include "backends/dlc/dlcdesc.h"

namespace DLC {
Expand All @@ -51,6 +52,7 @@ class Store {

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

virtual void removeCacheFile(Common::Path file) = 0;
};

} // End of namespace DLC
Expand Down

0 comments on commit 314ff70

Please sign in to comment.