sách gpt4 ai đã đi

qt - Qt 安装程序框架不覆盖现有安装的解决方法

In lại 作者:行者123 更新时间:2023-12-04 22:56:03 34 4
mua khóa gpt4 Nike

这个问题是关于 Qt Installer Framework 2.0 版的。

在这一点上,使用 Qt 安装程序框架的人都知道,如果不进行自定义,您根本无法通过安装程序覆盖现有安装。这样做显然是为了解决使用 Qt 框架完成此操作时出现的一些问题。

但是,对于较小的、相对简单的项目,覆盖非常好,而且比事先手动运行维护工具要方便得多。

我正在寻找一个涉及自定义 UI + 组件脚本的解决方案,该脚本向目标目录页面添加一个按钮,允许用户

  • 删除指定的目录(如果存在),或
  • 在该目录中运行维护工具。

  • 最好能够在目标目录中运行维护工具,让它自动删除给定的包,但我意识到这要求有点高。

    我已阅读本网站上有关解决同一问题的其他问题的答案,但没有一个解决方案能正常工作。我还想提一下,我有一个组件脚本正在运行,但没有自定义 UI。

    1 Câu trả lời

    我终于找到了一个可行的解决方案。

    你需要三件事来完成它:

  • 一个组件脚本,
  • 目标目录页面的自定义 UI,以及
  • 自动点击卸载程序的 Controller 脚本。

  • 我现在将逐字列出对我有用的东西(包括我的项目特定的东西)。我的组件名为 Atlas4500 Tuner
    配置文件:


    Atlas4500 Tuner
    1.0.0
    Atlas4500 Tuner Installer
    EF Johnson Technologies
    EF Johnson
    C:\Program Files (x86)\EF Johnson\Atlas4500 Tuner


    包/Atlas4500 Tuner/meta/package.xml:


    Atlas4500Tuner
    Install the Atlas4500 Tuner
    1.0.0

    true
    true


    targetwidget.ui



    自定义组件脚本包/Atlas4500 Tuner/meta/installscript.qs:
    var targetDirectoryPage = null;

    function Component()
    {
    installer.gainAdminRights();
    component.loaded.connect(this, this.installerLoaded);
    }

    Component.prototype.createOperations = function()
    {
    // Add the desktop and start menu shortcuts.
    component.createOperations();
    component.addOperation("CreateShortcut",
    "@TargetDir@/Atlas4500Tuner.exe",
    "@DesktopDir@/Atlas4500 Tuner.lnk",
    "workingDirectory=@TargetDir@");

    component.addOperation("CreateShortcut",
    "@TargetDir@/Atlas4500Tuner.exe",
    "@StartMenuDir@/Atlas4500 Tuner.lnk",
    "workingDirectory=@TargetDir@");
    }

    Component.prototype.installerLoaded = function()
    {
    installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
    installer.addWizardPage(component, "TargetWidget", QInstaller.TargetDirectory);

    targetDirectoryPage = gui.pageWidgetByObjectName("DynamicTargetWidget");
    targetDirectoryPage.windowTitle = "Choose Installation Directory";
    targetDirectoryPage.description.setText("Please select where the Atlas4500 Tuner will be installed:");
    targetDirectoryPage.targetDirectory.textChanged.connect(this, this.targetDirectoryChanged);
    targetDirectoryPage.targetDirectory.setText(installer.value("TargetDir"));
    targetDirectoryPage.targetChooser.released.connect(this, this.targetChooserClicked);

    gui.pageById(QInstaller.ComponentSelection).entered.connect(this, this.componentSelectionPageEntered);
    }

    Component.prototype.targetChooserClicked = function()
    {
    var dir = QFileDialog.getExistingDirectory("", targetDirectoryPage.targetDirectory.text);
    targetDirectoryPage.targetDirectory.setText(dir);
    }

    Component.prototype.targetDirectoryChanged = function()
    {
    var dir = targetDirectoryPage.targetDirectory.text;
    if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
    targetDirectoryPage.warning.setText("

    Existing installation detected and will be overwritten.

    ");
    }
    else if (installer.fileExists(dir)) {
    targetDirectoryPage.warning.setText("

    Installing in existing directory. It will be wiped on uninstallation.

    ");
    }
    else {
    targetDirectoryPage.warning.setText("");
    }
    installer.setValue("TargetDir", dir);
    }

    Component.prototype.componentSelectionPageEntered = function()
    {
    var dir = installer.value("TargetDir");
    if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
    installer.execute(dir + "/maintenancetool.exe", "--script=" + dir + "/scripts/auto_uninstall.qs");
    }
    }

    自定义目标目录小部件包/Atlas4500 Tuner/meta/targetwidget.ui:


    TargetWidget



    0
    0
    491
    190




    0
    0




    491
    190



    Form














    true







    0
    0




    0
    0



    ...








    0




    true


    TextLabel






    Qt::Horizontal



    40
    20









    Qt::Vertical



    20
    122










    包/Atlas4500 Tuner/data/scripts/auto_uninstall.qs:
    // Controller script to pass to the uninstaller to get it to run automatically.
    // It's passed to the maintenance tool during installation if there is already an
    // installation present with: /maintenancetool.exe --script=/scripts/auto_uninstall.qs.
    // This is required so that the user doesn't have to see/deal with the uninstaller in the middle of
    // an installation.

    function Controller()
    {
    gui.clickButton(buttons.NextButton);
    gui.clickButton(buttons.NextButton);

    installer.uninstallationFinished.connect(this, this.uninstallationFinished);
    }

    Controller.prototype.uninstallationFinished = function()
    {
    gui.clickButton(buttons.NextButton);
    }

    Controller.prototype.FinishedPageCallback = function()
    {
    gui.clickButton(buttons.FinishButton);
    }

    这里的想法是检测当前目录中是否有安装,如果有,使用 Controller 脚本运行该目录中的维护工具,只需点击它即可。

    请注意,我将 Controller 脚本放在脚本目录中,该目录是实际组件数据的一部分。如果您有多个组件,您可能可以做一些更清洁的事情,但这就是我正在使用的。

    您应该能够自己复制这些文件,只需调整字符串即可使其工作。

    关于qt - Qt 安装程序框架不覆盖现有安装的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46455360/

    34 4 0
    Bài viết được đề xuất: list - Haskell 自引用列表终止
    Bài viết được đề xuất: validation - 使用 tcomb-form-native 验证字符串相等性(确认密码)
    Bài viết được đề xuất: elixir - 将 LEFT OUTER JOIN 查询转换为 Ecto
    Bài viết được đề xuất: perl - 使用 IO::Event 检测目录中的新文件
    行者123
    Hồ sơ cá nhân

    Tôi là một lập trình viên xuất sắc, rất giỏi!

    Nhận phiếu giảm giá Didi Taxi miễn phí
    Mã giảm giá Didi Taxi
    Giấy chứng nhận ICP Bắc Kinh số 000000
    Hợp tác quảng cáo: 1813099741@qq.com 6ren.com