5

I've created an installer package based on the Qt installer framework with multiple components. I needed to install each component in the appropriate directory.

Is it possible to specify the target directory for the individual component? I am referring to something like this:

var appData = installer.environmentVariable("AppData");
     if (appData != "")
         component.setValue("TargetDir", appData+ "/MyComponent");

Thank you in advance.

MBach
  • 1,647
  • 16
  • 30
Rustem
  • 326
  • 2
  • 10

3 Answers3

12

This question has already been answered, but I thought I would add a more detailed answer.

The documentation states that "for each component, you can specify one script that prepares the operations to be performed by the installer."

The Qt installer framework QtIFW comes with a set of examples, one of which is called modifyextract. Using this, I modified my package.xml file to include the line

<Script>installscript.qs</Script>

I then added a file installscript.qs to my package meta directory with the following content

function Component()
{
}

Component.prototype.createOperationsForArchive = function(archive)
{
    // don't use the default operation
    // component.createOperationsForArchive(archive);

    // add an extract operation with a modified path
    component.addOperation("Extract", archive, "@TargetDir@/SubDirectoryName");
}

The files in the package data folder were then installed in the subfolder SubDirectoryName

eatyourgreens
  • 1,053
  • 1
  • 12
  • 16
  • In concert with this, to control the archiving process and what flows through this call back, use `archivegen`: http://doc.qt.io/qtinstallerframework/ifw-tools.html#archivegen. QtIFW will leave your 7zip files basically as is rather than packing them into another archive implicitly. That will allow to you to then make use this mechanism here with more precision. Note they will have the package version prepended onto their file names, so include that detail when you evaluate the `archive` argument. Example archive arg: `installer://com.mycompany.mypackage/1.0.0.0myarchive.7z` – BuvinJ Oct 15 '20 at 23:10
1

You need this based on the documentation:

Extract "Extract" archive target directory Extracts archive to target directory.

László Papp
  • 51,870
  • 39
  • 111
  • 135
0

In my case, the component.addOperation("Extract", ... line resulted in extracting to @TargetDir@.

Instead, use one of the 'Operations> options in the Package.xml file.