【问题标题】:QtIFW - platform independent paths in installer configuration file. Is it possible?QtIFW - 安装程序配置文件中与平台无关的路径。可能吗?
【发布时间】:2020-04-09 05:48:19
【问题描述】:

我的安装程序有以下配置文件:

<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>

是否有可能使用与平台无关的斜杠设置\Company\Application 路径?原始文档似乎没有回答这个问题https://doc.qt.io/qtinstallerframework/ifw-globalconfig.html

【问题讨论】:

    标签: qt frameworks installation platform


    【解决方案1】:

    是的,可以使用脚本。在某个地方(我不记得现在在哪里,但这是一个官方的 qt 教程)我找到了这个函数,可以进行你想要的转换:

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

    这个函数可以在脚本中使用来转换为原生分隔符(警告,从现在开始我解释这个概念,不要把代码当作好,因为它没有经过测试并且可能包含一些错误)。你可以做一个脚本,比如

    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")));
      }
    }
    

    然后你必须修改你的 config.xml 通过添加来包含脚本

    <ControlScript>installer.js</ControlScript>
    

    如果设置不正确,可以尝试在组件中设置。这是controllercomponent 中的脚本文档。

    【讨论】:

    • 它按应有的方式工作。我需要做的更改是使用正斜杠&lt;TargetDir&gt;@HomeDir@/Company/Application&lt;/TargetDir&gt; 指定路径。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    相关资源
    最近更新 更多