{"id":109,"date":"2023-07-22T21:35:03","date_gmt":"2023-07-22T21:35:03","guid":{"rendered":"https:\/\/blogs.scummvm.org\/ankushdutt\/?p=109"},"modified":"2023-07-23T06:48:42","modified_gmt":"2023-07-23T06:48:42","slug":"extracting-dlc","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/ankushdutt\/2023\/07\/22\/extracting-dlc\/","title":{"rendered":"Extracting DLC"},"content":{"rendered":"<p>I spent my time implementing the extracting the DLCs methods this week. Since the DLCs were downloaded as .zip files. We needed a way to extract the files from the zip file.<\/p>\n<p>The process of extracting the contents was simple: use the existing method called <code>dumpArchive()<\/code> after creating the new <code>Archive<\/code> object. You can read more about the ScummVM&#8217;s <code>Archive<\/code> class on the <a href=\"https:\/\/doxygen.scummvm.org\/d8\/d23\/group__common__arch.html\">doxygen documentation<\/a>. We already have a method called <code>makeZipArchive()<\/code> that does the job of creating an archive object using the zip in the provided path.<\/p>\n<p>However, there were some problems with the current <code>dumpArchive()<\/code> method. All files extracted were getting renamed to something like <code>xn--lureprotect.pdf-ua69e<\/code>. The original corresponding file is <code>protect.pdf<\/code> of a game called Lure of the Temptress. This was an issue because ScummVM&#8217;s game detector could not automatically recognize these files with the new name. When adding a new game from the ScummVM&#8217;s GUI, we were presented with the could not find any game error.<\/p>\n<p>The new file names are punycode encoded file names. The purpose of punycode encoding is to ensure compatibility with all operating systems by processing different symbols (like <code>\/<\/code>, <code>:<\/code>, etc.) in filenames. If we were to remove the punycode encoding, certain special symbols in filenames might not be allowed\/supported on certain operating systems. For example, we could not name <code>Echo I\/O:Room<\/code> in MacOS since it didn&#8217;t allow colon <code>:<\/code> for naming a file\/folder as it used <code>:<\/code> as a path separator.<\/p>\n<p>The problem in the current punycode encoding was that the file name we were initially getting from the zip file was a relative file path instead of just the file name (like lure\/protect.pdf and not protect.pdf). Indeed it should be a path; how else are we going to preserve the original location of the zip&#8217;s contents with multiple folder hierarchies? Punycode encoding this path name with the special symbol slash (<code>\/<\/code>) prevented it from getting detected. We already have a class called <code>Path<\/code>, which can contain string components of any file path. For example, the components of a path <code>abc\/def\/g.h<\/code> are <code>abc<\/code>, <code>def<\/code>, <code>g.h<\/code>. By using <code>Path<\/code> instead of <code>String<\/code>, we can differentiate between the <code>\/<\/code>, the path separator, and <code>\/<\/code> that appears in the file name. To get the <code>Path<\/code>\u00a0for each file in the zip, I used the method that was recently created in this <a href=\"https:\/\/github.com\/scummvm\/scummvm\/pull\/5108\">PR<\/a>. Also, the punycode encoding method for the path object was already implemented, which executed the original punycode encoding of string for all the path&#8217;s components.<\/p>\n<p>Once the zip file is downloaded and extracted, it should be deleted to free up the user&#8217;s storage. For deleting the zip file, a simple call to <code>unlink()<\/code> with the file&#8217;s path is sufficient, and the file will be deleted. This <code>unlink()<\/code> is included in <code>&lt;unistd.h&gt;<\/code>, which is included in POSIX-supported operating systems. On Windows, we needed to call <code>_unlink()<\/code> instead.<\/p>\n<p>Apart from the extracting, there was also a bug in my session request code for starting a download session of DLC. Once the DLC was downloaded, this session was not automatically killed and remained in paused state. And I was getting the error callback called whenever I quit the ScummVM program. This was fixed by calling the session request&#8217;s close() method in the download file callback at the end of the stream (i.e., DLC is downloaded) to delete the request.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent my time implementing the extracting the DLCs methods this week. Since the DLCs were downloaded as .zip files. We needed a way to extract the files from the zip file. The process of extracting the contents was simple: use the existing method called dumpArchive() after creating the new Archive object. You can read [&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-109","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts\/109","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=109"}],"version-history":[{"count":6,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/posts\/109\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ankushdutt\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}