user3417815
user3417815

Reputation: 635

QtIFW - platform independent paths in installer configuration file. Is it possible?

I have the following configuration file for my installer:

<Installer>
    <Name>Application</Name>
    <Version>1.0.0</Version>
    <Title>Application</Title>
    <StartMenuDir>Application</StartMenuDir>
    <TargetDir>@HomeDir@\Company\Application</TargetDir>
    <MaintenanceToolName>MaintenanceTool</MaintenanceToolName>
    <AllowSpaceInPath>true</AllowSpaceInPath>
</Installer>

Is there any possibility of setting \Company\Application path with platform-independent slashes? Original documentation doesn't seem to answer on that question https://doc.qt.io/qtinstallerframework/ifw-globalconfig.html

Upvotes: 0

Views: 655

Answers (1)

apalomer
apalomer

Reputation: 1935

Yes, it is possible using scripts. Somewhere (I cannot remember where now but it was an official qt tutorial) I found this function that does the conversion you want:

var Dir = new function () {
    this.toNativeSparator = function (path) {
        if (systemInfo.productType === "windows")
            return path.replace(/\//g, '\\');
        return path;
    }
};

This function can be used in a script to convert to native separators (warning, from now on I explain the concept, don't take the code for good as it is not tested and might contain some error). You can do a script such as

var Dir = new function () {
    this.toNativeSparator = function (path) {
        if (systemInfo.productType === "windows")
            return path.replace(/\//g, '\\');
        return path;
    }
};

function Controller()
{
  if (installer.isInstaller()) {
    installer.setValue("TargetDir", Dir.toNativeSparator(installer.value("TargetDir")));
  }
}

Then you have to modify your config.xml to include the script by adding

<ControlScript>installer.js</ControlScript>

If this does not set it properly, you can try to set it in a component. Here is the documentation for scripting in controller and component.

Upvotes: 2

Related Questions