Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact:  Website

Conditional installation of files

Sat Feb 25, 2006 12:40 pm

Hi,

A common problem when creating a setup package would be to install files only when
several conditions are met (for example, depending on a user's answer, the OS version
etc).

In what follows I shall explain the process for conditional file installation depending on the OS family. That is, if the OS is Win9x based, a certain directory tree will be installed, otherwise, if the OS is WinNT based, a different directory tree will be installed. This method applies in the same way even when the files that need to be installed conditionally have the same names for both OS families.

These are the required steps:

A. The first step is to organize appropriately (on disk) the files that need to be installed. Consider the following directory structure:

Code: Select all

Project Folder
  - project.aip
  - source
      - program.exe
      - readme.txt
      - Win9x
          - APPDIR_9x
              - subdir1
                  - file3.dll
                  - file4.dll
              - subdir2
                  - file5.exe
              - file.exe
              - file1.dll
              - file2.dll
          - System
              - somedll.dll
      - WinNT
          - APPDIR_NT
              - (same or different dir structure as APPDIR_9x)
          - System32
              - somedll.dll
      - ...
The "source" folder contains the files that need to be installed. However, only one set of files (either from the "Win9x" or "WinNT" folders) will be installed, depending on the OS family. The directory tree under the "Win9x\APPDIR_9x" or "WinNT\APPDIR_NT" will be installed directly under "APPDIR". The files in the "Win9x\System" folder will be installed in the [System16Folder] (usually "Windows\System") only if the OS is Win9x based. If the OS is NT based, the files from "WinNT\System32" will be installed to [SystemFolder] (usually "Windows\System32" or "WinNT\System32").


B. After you have organized your files and folders as shown above, you need to add them in Advanced Installer:

1. First, switch to the Organization page in AI and create the "layout" of your package, that is, the Features and Sub-Features your application will have. This step could be performed later, after all the files have been added in the Files and Folders page. However, it is better if you perform it now, because this way you will avoid dragging Components from one Feature to another later on.

For this example, you will need to create 2 additional Features, let's name them "Feature9X" and "FeatureNT". Only one of these 2 Features will be installed depending on the OS family.

2. Switch to the Files and Folders page and add the files and folders that do not depend on the OS family. These should be all the files and folders under the "source" directory apart from the "Win9x" or "WinNT" folders:

a) Make sure that in the "Current Feature" combobox from the toolbar it is selected the appropriate Feature (for this example, this is "MainFeature").

b) You will use the "Add files" and "Add folders" toolbar buttons. These files will be added to the Current Feature selected in the combobox.

3. Add the files and folders that depend on the OS family:

a) Select "Feature9X" in the "Current Feature" combobox. Then use the "Add folder" toolbar button and add the "Win9x\APPDIR_9x" and "Win9x\System" folders under the "Application Folder" tree node. Later, we shall use 2 Custom Action to redirect the content of these directories to the Installation Folder and to the [System16Folder], respectively.

b) Select "FeatureNT" in the "Current Feature" combobox. Then use the "Add folder" toolbar button and add the "WinNT\APPDIR_NT" and "WinNT\System32" folders under the "Application Folder" tree node. Later, we shall use 2 Custom Action to redirect the content of these directories to the Installation Folder and to the [SystemFolder], respectively.

The tree control from the Files and Folders page should look like this:

Code: Select all

Target Computer
  - Application Folder
      - APPDIR_9x
          - subdir1
          - subdir2
      - APPDIR_NT
          - subdir1
          - subdir2
      - System
      - System32
  - Application Shortcut Folder
  - ... 

C. Switch to the Custom Actions page and make sure that the tree item "InstallInitialize" is visible under "InstallExecuteSequence" (if not, right click on "InstallExecuteSequence" and select "Show Standard Action -> Before File Installation -> InstallInitialize"). Then:

1. Add a new "Directory Set with Formatted Custom Action" on the "InstallInitialize" stage. Select the "Installation Folder\APPDIR_9x" folder. In the "Formatted Text" filed enter: [APPDIR]

2. Repeat step C.1 for the other 3 folders that need to be redirected, creating a "Directory Set with Formatted" CA for each of them:
"Installation Folder\APPDIR_NT" -> Formatted Text: [APPDIR]
"Installation Folder\System" -> Formatted Text: [System16Folder]
"Installation Folder\System32" -> Formatted Text: [SystemFolder]

The purpose of these 4 Directory Set with Formatted CAs is to redirect the contents of the 4 folders to the appropriate directory. Remember that only the file(s) from one of the folders (APPDIR_9x,System) or (APPDIR_NT,System32) will be installed.


D. The last step is to set Conditions for the Features whose installation depends on the OS family:

1. Switch to the Organization page and make sure that each file that will be installed conditionally belongs to the appropriate Feature. If you have followed step B.1 outlined above, all the files should be in the appropriate place. If this is not the case, drag the corresponding Components to the appropriate Feature.

For this example, the tree control from the Organization page should look like this:

Code: Select all

Product
- MainFeature
    - program.exe
    - readme.txt
- Feature9X
    - file.exe
    - file1.dll
    - file2.dll
    - file3.dll
    - file4.dll
    - file5.dll
    - somedll.dll
- FeatureNT
    - file.exe_1
    - file1.dll_1
    - file2.dll_1
    - file3.dll_1
    - file4.dll_1
    - file5.dll_1
    - somedll.dll_1
2. For each of the the 2 OS family dependent Features you have added, click the "Conditional" button at the right of the "Install Level" field and in the "Edit Conditional Levels" dialog, click the "New" button. Then set the Level to zero and the Condition to:
- for the "Feature9X" Feature : (NOT Version9X) AND (NOT Installed)
- for the "FeatureNT" Feature : (NOT VersionNT) AND (NOT Installed)

Be advised that the "Version9X" and "VersionNT" Windows Installer Properties are case-sensitive.

Therefore, only one Feature will be installed depending on the family of the operating system.

For a more complex example of a conditional file install (based on the user's answer to several VBScript "MsgBox"-based questions) see my second post from this thread:
http://www.advancedinstaller.com/forums ... .php?t=985

Hope this helps.

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Sample Projects”