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]: Magic Tweeks[Next]: Debug Macro - Cause Rollback (or just failure)
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Create Macro For Adding Files

EXAMPLE - Complete MSI Script

The following 3 line script builds a complete MSI:

#include "dennis.mmh"   ;;Include MAKEMSI support and define my macro!
<$DirFiles Dir="c:\tmp\aaaa"      "a*.dll;a*.exe">
<$DirFiles Dir="c:\tmp\aaaa\bbbb" "a*.ocx">

EXAMPLE - Macro (defined in DENNIS.MMH)

You would generally define a macro in a single place and a common header file such as "DENNIS.MMH" would be ideal.

This macro started out very simple but to handle all sorts of user type interactions (reduce restrictions on how it should be used) it snowballed :-)

The macro takes these parameters:

#NextId
#define? OPTION_DIRFILES_FIRST_USE_SETS_ROOT_FEATURE_DIRECTORY  Y         ;;Y/N
#define? OPTION_DIRFILES_FIRST_DIRKEY                           DIRFILES
#define? OPTION_DIRFILES_OTHER_DIRKEYS                          <$OPTION_DIRFILES_FIRST_DIRKEY>_{$Cnt}
#define? OPTION_DIRFILES_DEFAULT_Options4Files
#RexxVar @@DirFilesCnt = 0
#( ''
   #define DirFiles

   ;--- Some Parameter Validations ------------------------------------------
   {$!KEYWORDS}                 ;;Don't accept/use keyword parameters
   #( ''
       ;--- Check passed parameter names against this list ------------------
       {$!:#1,              ;;List of one or more file masks (normally must be at least one file matching mask)
           Dir,             ;;Destination dir (first one usually configurable via root feature). Can also be a Directory key such as "INSTALLDIR"
           Options4Files    ;;A mechanism to supply "FILES" command options
       }
   #)

   ;--- Create the MSI directory key if not seen before ---------------------
   #DefineRexx ''
    @@Dir    = '{$Dir}';
    if  pos(@@Dir, '\') = 0 then;
        @@DirKey = @@Dir;
    else
        @@DirKey = DataGet(translate('{$Dir}'))    ;;Returns '' if not seen
   #DefineRexx
   #if   [@@DirKey = '']
       ;--- Have not seen before so what do we wish to call this directory? ---
       #RexxVar @@DirFilesCnt + 1
       #if [@@DirFilesCnt = 1]
            #RexxVar @@DirKey = "<$OPTION_DIRFILES_FIRST_DIRKEY>"
       #elseif
            #RexxVar @@DirKey = "<$OPTION_DIRFILES_OTHER_DIRKEYS Cnt=^<??@@DirFilesCnt>^>"
       #endif

       ;--- Save this info away ---------------------------------------------
       #DefineRexx ''
            call DataSave translate('{$Dir}'),, @@DirKey
       #DefineRexx

       ;--- Create the directory --------------------------------------------
       #RexxVar @@FeatureDir = 'N'
       #if [@@DirFilesCnt = 1]
           #if   ['<$OPTION_DIRFILES_FIRST_USE_SETS_ROOT_FEATURE_DIRECTORY $$UPPER>' = 'Y']
                 #RexxVar @@FeatureDir = 'Y'
           #endif
       #endif
       #if   [@@FeatureDir = 'N']
             <$DirectoryTree Key="<??@@DirKey>" Dir="{$Dir}">
       #elseif
             <$DirectoryTree Key="<??@@DirKey>" Dir="{$Dir}" CHANGE='\'>
       #endif
   #endif

   ;--- Add the Files to the MSI --------------------------------------------
   #if  ['{$Options4Files=^^ $$IsPassed}' = 'Y']
        <$Files "{$#1}" DestDir="<??@@DirKey>" {$Options4Files}>
   #elseif
       ;--- Bit trickier ----------------------------------------------------
       #DefineRexx ''
            @@Options4Files = MacroGet('OPTION_DIRFILES_DEFAULT_Options4Files');
            @@FilesCmd      = '<' || '$Files "{$#1}" DestDir="' || @@DirKey || '" ' || @@Options4Files || '>'
        #DefineRexx
        <??@@FilesCmd><?RestartLine>
   #endif
#)


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]: Magic Tweeks[Next]: Debug Macro - Cause Rollback (or just failure)


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
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.