{"id":103,"date":"2023-07-15T16:14:39","date_gmt":"2023-07-15T16:14:39","guid":{"rendered":"https:\/\/blogs.scummvm.org\/ankushdutt\/?p=103"},"modified":"2023-07-15T16:14:39","modified_gmt":"2023-07-15T16:14:39","slug":"dlc-curl","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/ankushdutt\/2023\/07\/15\/dlc-curl\/","title":{"rendered":"Implementing DLC Dowloading through cURL"},"content":{"rendered":"<p>This week I started with implementing the helper functions for Google Play Store in Java. However, we later decided to initially use ScummVM&#8217;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.<\/p>\n<p>The existing download manager utilizes cURL and has appropriate methods to download\/fetch something from a URL. In my code, I have <code>DLCManager<\/code> class which provides the interface for calling DLC-related methods. There&#8217;s also the <code>Store<\/code> abstract class, deriving <code>ScummVMCloud<\/code> 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 <code>ScummVMCloud<\/code>. Both are asynchronous methods as they both are network requests.<\/p>\n<p><span data-preserver-spaces=\"true\">The first is <code>getAllDLCs()<\/code>, 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 <\/span><a class=\"editor-rtfLink\" href=\"https:\/\/downloads.scummvm.org\/frs\/icons\/LIST\" target=\"_blank\" rel=\"noopener\"><span data-preserver-spaces=\"true\">https:\/\/downloads.scummvm.org\/frs\/icons\/LIST<\/span><\/a><span data-preserver-spaces=\"true\">), 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 <code>CurlJsonRequest<\/code>, which can handle the JSON response. The JSON response will contain an array where each item will contain the description for DLC &#8211; name, id, URL, size, etc. This method will run once on start (in <code>scummvm_main()<\/code>) 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.).<\/span><\/p>\n<p>The second method is <code>startDownloadAsync()<\/code>, which starts the downloading process as the name suggests. Under the hood, it creates a <code>SessionRequest<\/code> (already implemented), which maintains the session and downloads the file on the URL. The <code>downloadFileCallback()<\/code> 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 <code>scummvm.ini<\/code> file (ScummVM&#8217;s configuration file).<\/p>\n<p>Finally, the downloading works and the list shown in the dialog for browsing DLC is no longer hardcoded.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week I started with implementing the helper functions for Google Play Store in Java. However, we later decided to initially use ScummVM&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":4,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":107,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts\/103\/revisions\/107"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}