Categories
Uncategorized

Extracting DLC

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 more about the ScummVM’s Archive class on the doxygen documentation. We already have a method called makeZipArchive() that does the job of creating an archive object using the zip in the provided path.

However, there were some problems with the current dumpArchive() method. All files extracted were getting renamed to something like xn--lureprotect.pdf-ua69e. The original corresponding file is protect.pdf of a game called Lure of the Temptress. This was an issue because ScummVM’s game detector could not automatically recognize these files with the new name. When adding a new game from the ScummVM’s GUI, we were presented with the could not find any game error.

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 /, :, 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 Echo I/O:Room in MacOS since it didn’t allow colon : for naming a file/folder as it used : as a path separator.

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’s contents with multiple folder hierarchies? Punycode encoding this path name with the special symbol slash (/) prevented it from getting detected. We already have a class called Path, which can contain string components of any file path. For example, the components of a path abc/def/g.h are abc, def, g.h. By using Path instead of String, we can differentiate between the /, the path separator, and / that appears in the file name. To get the Path for each file in the zip, I used the method that was recently created in this PR. Also, the punycode encoding method for the path object was already implemented, which executed the original punycode encoding of string for all the path’s components.

Once the zip file is downloaded and extracted, it should be deleted to free up the user’s storage. For deleting the zip file, a simple call to unlink() with the file’s path is sufficient, and the file will be deleted. This unlink() is included in <unistd.h>, which is included in POSIX-supported operating systems. On Windows, we needed to call _unlink() instead.

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’s close() method in the download file callback at the end of the stream (i.e., DLC is downloaded) to delete the request.

Leave a Reply

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