How to add files and unpack zip archives ?

Comments

3 comments

  • Avatar
    wojciechka

    Adding files to InstallBuilder can be easily done from the GUI. For new projects, files can be added by going to Files section of the builder GUI, selecting Program Files (All Platforms) and selecting Add Files or Add Directory Tree. Those files will be installed for all platforms.

    You can find more information about it in Select the files section of InstallBuilder UserGuide.

    The demo projects provided with InstallBuilder show how files can be deployed, both using a single component and multiple components.

    You can find more information about it in Sample installers bundled with InstallBuilder section of InstallBuilder UserGuide.

  • Avatar
    wojciechka

    Embedding zip files can be done in two ways. You can <unzip> the files in <preBuildActionList> and package the unzipped contents. This approach is better since the unzipping is done when building the installer and unpacked files are shipped.

    InstallBuilder's compression is also better than zip, especially when LZMA is enabled, so this should also reduce the overall size of the installer.

    A complete example to package two zip archives is as follows:

    <project>
      <componentList>
        <!-- other components -->
    
        <component>
          <name>archive</name>
          <folderList>
            <folder>
              <destination>${installdir}</destination>
              <name>archive1</name>
              <platforms>all</platforms>
              <distributionFileList>
                <distributionDirectory>
                  <allowWildcards>1</allowWildcards>
                  <origin>${system_temp_directory}/archive1/*</origin>
                </distributionDirectory>
              </distributionFileList>
            </folder>
            <folder>
              <destination>${installdir}</destination>
              <name>archive2</name>
              <platforms>all</platforms>
              <distributionFileList>
                <distributionDirectory>
                  <allowWildcards>1</allowWildcards>
                  <origin>${system_temp_directory}/archive2/*</origin>
                </distributionDirectory>
              </distributionFileList>
            </folder>
          </folderList>
        </component>
      </componentList>
    
      <!-- unpack zip archives -->
      <preBuildActionList>
        <deleteFile>
          <path>${system_temp_directory}/build_zip_contents</path>
        </deleteFile>
        <createDirectory>
          <path>${system_temp_directory}/build_zip_contents</path>
        </createDirectory>
        <unzip>
          <destinationDirectory>${system_temp_directory}/archive1</destinationDirectory>
          <zipFile>path/to/archive1.zip</zipFile>
        </unzip>
        <unzip>
          <destinationDirectory>${system_temp_directory}/archive2</destinationDirectory>
          <zipFile>path/to/archive2.zip</zipFile>
        </unzip>
      </preBuildActionList>
    
      <!-- delete temporary directory -->
      <postBuildActionList>
        <deleteFile>
          <path>${system_temp_directory}/build_zip_contents</path>
        </deleteFile>
      </postBuildActionList>
      <!-- remaining parts of project -->
    </project>
    

    An alternative is to ship the zip files and run <unzip> action after installation. You do not need to unpack the files, what you can do is unpack it after installation. The below unzips the archive and removes the file, also removing it from list of files to delete by uninstaller:

    <postInstallationActionList>
      <unzip>
        <destinationDirectory>${installdir}</destinationDirectory>
        <zipFile>${installdir}/archive1.zip</zipFile>
      </unzip>
      <deleteFile>
        <path>${installdir}/archive1.zip</path>
      </deleteFile>
      <removeFilesFromUninstaller>
        <files>${installdir}/archive1.zip</files>
      </removeFilesFromUninstaller>
    </postInstallationActionList>
    

    The last step is not needed (uninstaller will simply skip the file if it is not present), but is a good practice to avoid deleting files customers may copy that would just have the same name.

    As for running the binary, if it is done after installation, you can simply invoke the <runProgram> action. If it has to be done before running the installation (i.e. to validate a serial number), you need to use <unpackFile> or <unpackDirectory> action.

    You can find more information on this in Unpacking Before Installation Time section of our documentation.

  • Avatar
    ridruejo

    It seems

    ${system_temp_directory}
    

    is only defined at runtime, not at build time and that is why it did not work. There is no reason probably why it needs to be that way, so we will be changing that. In the mean time, can you just hardcode the value?

    You can also add the following at beginning of <preBuildActionList>:

    <preBuildActionList>
     <setInstallerVariable>
      <name>system_temp_directory</name>
      <value>${env(TEMP)}</value>
     </setInstallerVariable>
     <!-- remaining actions -->
    </preBuildActionList>
    

Please sign in to leave a comment.