Categories
Uncategorized

Implementing DLC Dowloading through cURL

This week I started with implementing the helper functions for Google Play Store in Java. However, we later decided to initially use ScummVM’s exisiting download manager since it will let us quickly implement the downloading functions and can give us the opportunity to design a POC (proof of concept) for the ScummVM Downloader. It will also be better to initially have basic functions and not be biased towards implementing functions for a particular distribution platform as we need to extend it to other distribution platforms.

The existing download manager utilizes cURL and has appropriate methods to download/fetch something from a URL. In my code, I have DLCManager class which provides the interface for calling DLC-related methods. There’s also the Store abstract class, deriving ScummVMCloud class, where I have used the method provided by the existing download manager. Right now, there were only two required functions that I had to implement in ScummVMCloud. Both are asynchronous methods as they both are network requests.

The first is getAllDLCs(), which sends a request to a URL and expects a JSON response. Initially, I was thinking of the simple comma-separated approach for the schema (similar to https://downloads.scummvm.org/frs/icons/LIST), but that would not work since there were many special characters (including the comma) in the names and URLs of DLCs. Fortunately, the ScummVM codebase has already implemented CurlJsonRequest, which can handle the JSON response. The JSON response will contain an array where each item will contain the description for DLC – name, id, URL, size, etc. This method will run once on start (in scummvm_main()) and set our DLC Array. The DLC Array maintains the information about DLC as well as their state (available, downloading, downloaded, cancelled, error downloading, etc.).

The second method is startDownloadAsync(), which starts the downloading process as the name suggests. Under the hood, it creates a SessionRequest (already implemented), which maintains the session and downloads the file on the URL. The downloadFileCallback() repeatedly runs after downloading a fixed chunk and lets us run any function like update state, update the downloaded size, calculate speed, etc. There is a method for identifying if the file is completely downloaded so we can start extracting the file (if compressed). Once downloaded and extracted, I can add the game entry in the scummvm.ini file (ScummVM’s configuration file).

Finally, the downloading works and the list shown in the dialog for browsing DLC is no longer hardcoded.

Leave a Reply

Your email address will not be published. Required fields are marked *