2017-09-27 14 views
1

この質問は、Qtインストーラフレームワークのバージョン2.0についてです。Qtインストーラフレームワークの回避策が既存のインストールを上書きしない

この時点では、Qtインストーラフレームワークを使用している人は、カスタマイズすることなく、インストーラで既存のインストールを上書きすることはできません。これは明らかに、これがQtフレームワークで行われたときに発生したいくつかの問題を解決するために行われました。

しかし、比較的小さくて比較的単純なプロジェクトでは、事前に手動でメンテナンスツールを実行しなければならないよりも、上書きは完全にうまく機能します。

私はそれが存在する場合

  1. は、指定されたディレクトリを削除するのいずれかをユーザーに許可するターゲットディレクトリページにボタンを追加し、カスタムUI +コンポーネントのスクリプトを含むソリューションを探しています

    、または

  2. そのディレクトリでメンテナンスツールを実行します。それが自動的に与えられたパッケージを削除した、ターゲットディレクトリにメンテナンスツールを実行できることが望ましいだろう

しかし私は少し多すぎるために求めていることを実現します。

私は同じ問題を解決することについてこのサイトの他の質問に対する回答を読んだが、解決策のどれも正しく動作しません。コンポーネントスクリプトを作成して実行していますが、カスタムUIはありません。

答えて

1

私は最終的に実行可能な解決策を見つけました。

あなたがこれをやってのけるために3つのことを必要とする:

  1. コンポーネントスクリプト、
  2. ターゲット・ディレクトリページのカスタムUI、および
  3. 自動的にアンインストーラによってクリックするコントローラスクリプト。

ここでは、私のために働いているもの(私のプロジェクト特有のもの)を逐語的にリストします。

<?xml version="1.0" encoding="UTF-8"?> 
<Installer> 
    <Name>Atlas4500 Tuner</Name> 
    <Version>1.0.0</Version> 
    <Title>Atlas4500 Tuner Installer</Title> 
    <Publisher>EF Johnson Technologies</Publisher> 
    <StartMenuDir>EF Johnson</StartMenuDir> 
    <TargetDir>C:\Program Files (x86)\EF Johnson\Atlas4500 Tuner</TargetDir> 
</Installer> 

パッケージ/ Atlas4500チューナー/メタ/パッケージ:私のコンポーネントがAtlas4500 Tuner

config.xmlのと呼ばれています。XML

<?xml version="1.0" encoding="UTF-8"?> 
<Package> 
    <DisplayName>Atlas4500Tuner</DisplayName> 
    <Description>Install the Atlas4500 Tuner</Description> 
    <Version>1.0.0</Version> 
    <ReleaseDate></ReleaseDate> 
    <Default>true</Default> 
    <Required>true</Required> 
    <Script>installscript.qs</Script> 
    <UserInterfaces> 
     <UserInterface>targetwidget.ui</UserInterface> 
    </UserInterfaces> 
</Package> 

カスタムコンポーネントスクリプト installscript.qs パッケージ/ Atlas4500チューナー/メタ/:

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", 
          "@[email protected]/Atlas4500Tuner.exe", 
          "@[email protected]/Atlas4500 Tuner.lnk", 
          "[email protected]@"); 

    component.addOperation("CreateShortcut", 
          "@[email protected]/Atlas4500Tuner.exe", 
          "@[email protected]/Atlas4500 Tuner.lnk", 
          "[email protected]@"); 
} 

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("<p style=\"color: red\">Existing installation detected and will be overwritten.</p>"); 
    } 
    else if (installer.fileExists(dir)) { 
      targetDirectoryPage.warning.setText("<p style=\"color: red\">Installing in existing directory. It will be wiped on uninstallation.</p>"); 
    } 
    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チューナー/メタ/ targetwidget.ui

<?xml version="1.0" encoding="UTF-8"?> 
<ui version="4.0"> 
<class>TargetWidget</class> 
<widget class="QWidget" name="TargetWidget"> 
    <property name="geometry"> 
    <rect> 
    <x>0</x> 
    <y>0</y> 
    <width>491</width> 
    <height>190</height> 
    </rect> 
    </property> 
    <property name="sizePolicy"> 
    <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> 
    <horstretch>0</horstretch> 
    <verstretch>0</verstretch> 
    </sizepolicy> 
    </property> 
    <property name="minimumSize"> 
    <size> 
    <width>491</width> 
    <height>190</height> 
    </size> 
    </property> 
    <property name="windowTitle"> 
    <string>Form</string> 
    </property> 
    <layout class="QVBoxLayout" name="verticalLayout"> 
    <item> 
    <widget class="QLabel" name="description"> 
    <property name="text"> 
     <string/> 
    </property> 
    </widget> 
    </item> 
    <item> 
    <layout class="QHBoxLayout" name="horizontalLayout"> 
    <item> 
     <widget class="QLineEdit" name="targetDirectory"> 
     <property name="readOnly"> 
     <bool>true</bool> 
     </property> 
     </widget> 
    </item> 
    <item> 
     <widget class="QToolButton" name="targetChooser"> 
     <property name="sizePolicy"> 
     <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> 
     <horstretch>0</horstretch> 
     <verstretch>0</verstretch> 
     </sizepolicy> 
     </property> 
     <property name="minimumSize"> 
     <size> 
     <width>0</width> 
     <height>0</height> 
     </size> 
     </property> 
     <property name="text"> 
     <string>...</string> 
     </property> 
     </widget> 
    </item> 
    </layout> 
    </item> 
    <item> 
    <layout class="QHBoxLayout" name="horizontalLayout_2"> 
    <property name="topMargin"> 
     <number>0</number> 
    </property> 
    <item> 
     <widget class="QLabel" name="warning"> 
     <property name="enabled"> 
     <bool>true</bool> 
     </property> 
     <property name="text"> 
     <string>TextLabel</string> 
     </property> 
     </widget> 
    </item> 
    <item> 
     <spacer name="horizontalSpacer"> 
     <property name="orientation"> 
     <enum>Qt::Horizontal</enum> 
     </property> 
     <property name="sizeHint" stdset="0"> 
     <size> 
     <width>40</width> 
     <height>20</height> 
     </size> 
     </property> 
     </spacer> 
    </item> 
    </layout> 
    </item> 
    <item> 
    <spacer name="verticalSpacer"> 
    <property name="orientation"> 
     <enum>Qt::Vertical</enum> 
    </property> 
    <property name="sizeHint" stdset="0"> 
     <size> 
     <width>20</width> 
     <height>122</height> 
     </size> 
    </property> 
    </spacer> 
    </item> 
    </layout> 
</widget> 
<resources/> 
<connections/> 
</ui> 

パッケージ/ Atlas4500チューナー/データ/スクリプト/ 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: <target dir>/maintenancetool.exe --script=<target dir>/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); 
} 

ここでの考え方は、現在のディレクトリが、その中にインストールされているかいないかを検出することであり、それがない場合は、コントローラとそのディレクトリにメンテナンスツールを実行しますスクリプトをクリックするだけです。

実際のコンポーネントデータの一部であるスクリプトディレクトリにコントローラスクリプトを置きます。複数のコンポーネントがある場合は、おそらくもっとクリーンな処理を行うことができますが、これは私が使用しているものです。

これらのファイルを自分でコピーし、文字列を調整して機能させることができます。

0

あなたがする必要があるいくつかあります:あなたを許す

  • は、あなたがこのコード installer.setValue("RemoveTargetDir", false)

  • カスタムUI(またはメッセージ・ボックス)を追加することによって達成することができますTargetDirectoryPageの過去を取得するにはこのコードを実行します。このUIは、TargetDirectoryPageの後に挿入する必要があります。 // you need to append .exe on the maintenance for windows installation installer.execute(installer.findPath(installer.value("MaintenanceToolName"), installer.value("TargetDir")));

+0

これは、メンテナンスツールを実行すると、このように動作するので、私は正しい道のりに私を置く。ただし、 "RemoveTargerDir"は何もしません。私が思いついた解決策については私の答えを見てください。 – rationalcoder

関連する問題