Skip to main content

The "xzip_verify" Function

Syntax#

xzip_verify(arch, dir, file);
ArgumentTypeDescription
archstringThe full path and filename of the archive to check
dirstringThe full path of the destination folder to check, excluding final slash
filestring/integerThe name or index of a file to check

Description#

Verifies an extracted file against its original archive and returns true or false if the files' data matches. This is useful not only to test for file corruption or incomplete extraction, but also to protect file integrity. If a file has been illegitimately modified, this script can be used to detect it and trigger re-extraction of the unmodified file from the archive.

tip

To take security one step further, use GameMaker Studio's built-in MD5 functions to store a hash of the archive itself. Then your code can detect if illegitimate modifications have been made to the archive source file in an attempt to thwart xzip_verify.

For files stored in the archive, a full path should not be used, just the file name with extension. Use xzip_list to see what file names are available in the archive. The numerical index from xzip_list can also be used.

This function does not support folders as file inputs. Any relative paths inside the archive will be automatically applied to file names. Likewise, the archive file name will be automatically applied to the target directory to check. (Using a directory instead of explicit file names to compare enables simpler batch verifications.)

Be warned that verification takes time, and verifying many files at once can cause the game to temporarily appear frozen. It is recommended to verify large archives over a series of Steps and display a loading screen. (See example usage.)

Example#

//CREATE
file_archive = "C:\\archive.xz";
file_dest = "C:\\my\\destination\\folder";
file_count = xzip_count(file_archive);
file_current = 0;
file_list = xzip_list(file_archive);
file_fail_list = 0;
file_fail_current = 0;
//STEP
if (file_current < file_count) {
//Verify files
if (!xzip_verify(file_archive, file_dest, file_list[file_current])) {
//Create an array of failed files
file_fail_list[file_fail_current] = file_list[file_current];
file_fail_current++;
}
file_current++;
}
//DRAW
var file_prog = file_current/file_count;
draw_text(25, 25, "Verification: " + string(file_prog) + "% complete");
draw_text(25, 50, "Failed: " + string(array_height(file_fail_list)) + " files");