\
Tips and Tricks
File and Directory
ZIP Images for Directory Trees
| ZIP Images for Directory Trees |
You could have an unpacked image from a CD-ROM or similar but sometimes
its just easier to manage and version control (with PVCS etc) a single file.
I like this approach when a 3rd party product changes infrequently
and you'd generally want to replace the complete old image with a
complete new one
(so I don't really/often need to know exactly which file(s) in the image changed).
| Sample Code Which Uses the Macro |
;--- Unzip the image --------------------------------------------------------
#define UNZIPPED_IMAGE_DIR <$MAKEMSI_OTHER_DIR>\UnpackedZips\product.zip ;;This directory ERASED then recreated
<$UnzipImage ZipFile="c:\tmp\product.zip" Dir="<$UNZIPPED_IMAGE_DIR>">
;--- Add the files (components generated) -----------------------------------
<$Files "<$UNZIPPED_IMAGE_DIR>\*.*" DestDir="INSTALLDIR" SubDir="TREE" Comment=^Extracted from "product.zip".^>
#(
#define UnzipImage ;;Version 07.146
#evaluate ^^ ^<$@@Rexx2UnzipDirectoryTree {$?}>^
#)
#define? UnzipImageOutputColor {CYAN} ;;Output of the unzipping process..
#DefineRexx '@@Rexx2UnzipDirectoryTree'
;--- Get parameters -----------------------------------------------------
{$!:ZIPFILE,DIR,CLEAR,Options} ;;Validate passed parameters
@@ZipFile = '{$ZipFile}';
@@DestinationDirectory = '{$Dir}';
if FileQueryExists(@@ZipFile) = '' then
error('The zip file "' || @@ZipFile || '" doesn''t exist!');
;--- Almost always want to start with a clean directory -----------------
if '{$Clear=^Y^}' = 'N' then ;;Allow for multiple zips unpacking into a single location.
call Info 'Adding unpacked image to the destination directory.'
else
do
;--- We expect to start from scratch --------------------------------
call Info 'Clearing the unzip destination directory'
call AddressCmd 'rd "' || @@DestinationDirectory || '" /q /s >nul <$Stderr2Out>'
;--- We will need to create the directory ---------------------------
call AddressCmd 'md "' || @@DestinationDirectory || '" >nul <$Stderr2Out>'
end;
;--- Unzip --------------------------------------------------------------
call Info 'Unpacking ZIP (' || @@ZipFile || ')'
call ColorCfg '?UNZIPSRCIMG', '<$UnzipImageOutputColor>';
call ColorSet '?UNZIPSRCIMG';
@@Rc = AddressCmd('iunzip.exe {$Options=^-o^} "' || @@ZipFile || '" -d "' || @@DestinationDirectory || '"')
call ColorSet 'DEFAULT';
if @@Rc <> 0 then
error('The unzip of "' || @@ZipFile || '" failed with return code ' || @@Rc);
else
do
;--- Make sure we find at least one (non-hidden) file (double check) ---
call Files4Mask @@DestinationDirectory || "\*.*", "@@ZipImage", "Y", "N"
if @@ZipImage.0 = 0 then
error('The unzip of "' || @@ZipFile || '" probably failed as no files seem to have been extracted to the directory "' || @@DestinationDirectory || '"');
end;
#DefineRexx