MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Update Hosts File[Next]: Finding 'WSCRIPT.EXE' or 'CSCRIPT.EXE' Files
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->File and Directory->ZIP Images for Directory Trees (UnzipImage)

ZIP Images for Directory Trees (UnzipImage)

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).

This extraction occurs at build time, if the zip file contains large numbers of files it can make the msi creation and installation much slower and you may want to consider permforming the extraction at install time with the "FilesInZip" command instead.

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".^>

The Macro Code

#(
    #define UnzipImage                       ;;Version 10.015

    ;--- Make sure that "iunzip.exe" exists (user can override shortname with "EXE_IUNZIP.EXE") ---
    <$GetFullBuildTimeFileName RcVar="@@FullMakeIUnZipExeName" Macro="EXE_IUNZIP.EXE" File="<$@@IUnzipExeShortName>" MustExist="N">
    #if [@@FullMakeIUnZipExeName = '']
        ;--- Report error -------------------------------------------------------
        #error ^Could not find "<$@@IUnzipExeShortName>"!{NL}Please download the Info-zip "unzip.exe" from "http://www.info-zip.org/UnZip.html"^
    #endif

    ;--- The tool exists so lets unzip away! --------------------------------
    #evaluate ^^ ^<$@@Rexx2UnzipDirectoryTree {$?}>^
#)
#define? UnzipImageOutputColor  {CYAN}          ;;Output of the unzipping process..
#define @@IUnzipExeShortName  iunzip.exe    ;;We rename info-zip's "unzip.exe" to "iunzip.exe' to remove any doubt as to what it is...
#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';
    @@UnzipCmd = '"<??@@FullMakeIUnZipExeName>" {$Options=^-o^} "' || @@ZipFile || '" -d "' || @@DestinationDirectory || '"'
    <$DBG_SAY> 'UNZIP command: ' || @@UnzipCmd;             ;;If it fails user can copy from log and manually retry etc!
    @@UnzipCmd = '"' || @@UnzipCmd || '"'                   ;;Got to love Windows...
    @@Rc = AddressCmd(@@UnzipCmd)
    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


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Update Hosts File[Next]: Finding 'WSCRIPT.EXE' or 'CSCRIPT.EXE' Files


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday December 09 2017 at 9:30am
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.