[PATCH 6 of 7] Call makensis in create installer dialog

Wald Commits scm-commit at wald.intevation.org
Mon Apr 28 19:15:58 CEST 2014


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1398705331 0
# Node ID 3332db04c77d01375a661dcca7c2ec28051374fe
# Parent  9d3880db6ba7b233c66164e7726d0027f6ed0857
Call makensis in create installer dialog

diff -r 9d3880db6ba7 -r 3332db04c77d ui/createinstallerdialog.cpp
--- a/ui/createinstallerdialog.cpp	Mon Apr 28 14:02:40 2014 +0000
+++ b/ui/createinstallerdialog.cpp	Mon Apr 28 17:15:31 2014 +0000
@@ -18,7 +18,8 @@
 #include <QMessageBox>
 
 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) :
-    QDialog(parent)
+    QDialog(parent),
+    mProgress(this)
 {
     QSettings settings;
     setWindowTitle(tr("Create binary installer"));
@@ -27,6 +28,11 @@
     mCertFile->setText(settings.value("CodeSignCert", QString()).toString());
     mBinaryFolder->setText(settings.value("LastBinaryFolder", QString()).toString());
     mSaveFile->setText(settings.value("LastBinOutputFolder", QString()).toString());
+
+    connect(&mNSISProc, SIGNAL(finished(int, QProcess::ExitStatus)),
+            this, SLOT(processFinished(int, QProcess::ExitStatus)));
+    connect(&mNSISProc, SIGNAL(error(QProcess::ProcessError)),
+            this, SLOT(processError(QProcess::ProcessError)));
 }
 
 void CreateInstallerDialog::setupGUI()
@@ -106,6 +112,12 @@
 
     setLayout(topLayout);
 
+    mProgress.setWindowModality(Qt::WindowModal);
+    mProgress.setLabelText(tr("Creating installer package..."));
+    mProgress.setCancelButton(0);
+    mProgress.setRange(0,0);
+    mProgress.setMinimumDuration(0);
+
     return;
 }
 
@@ -145,14 +157,64 @@
     QMessageBox::warning(this, tr("Error!"), msg);
 }
 
+void CreateInstallerDialog::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+    mProgress.cancel();
+}
+
+void CreateInstallerDialog::processError(QProcess::ProcessError error)
+{
+    mProgress.cancel();
+}
+
 void CreateInstallerDialog::createInstaller()
 {
     QDir binDir(mBinaryFolder->text());
-    if (mBinaryFolder->text().isEmpty() && binDir.exists()) {
+    QDir outDir(mSaveFile->text());
+    if (mBinaryFolder->text().isEmpty() || !binDir.exists()) {
         showErrorMessage(tr("Please select an existing input folder."));
+        return;
     }
-    qDebug() << "and now create the installer using:";
-    qDebug() << "source archive: " << mBinaryFolder->text();
-    qDebug() << "certificate: " << mCertFile->text();
-    qDebug() << "target" << mSaveFile->text();
+    if (mCertFile->text().isEmpty()) {
+        showErrorMessage(tr("Please select a codesigning certificate."));
+        return;
+    }
+    if (mSaveFile->text().isEmpty() || !outDir.exists()) {
+        showErrorMessage(tr("Please select a output folder."));
+        return;
+    }
+    QSettings options(binDir.filePath("meta.ini"), QSettings::IniFormat);
+    options.sync();
+    QStringList keys = options.allKeys();
+    if (options.status() != QSettings::NoError || keys.size() < 1) {
+        showErrorMessage(tr("Folder %1 does not appear to contain a meta.ini")
+                .arg(binDir.path()));
+        return;
+    }
+
+    /* Copy windows directory contents to tmpdir */
+    QStringList arguments;
+    mNSISProc.setProgram("makensis");
+    mNSISProc.setWorkingDirectory(outDir.path());
+    arguments << QString::fromLatin1("-Dfiles_dir=") + binDir.path() + "/windows";
+
+    foreach (const QString &key, keys) {
+        arguments << QString::fromLatin1("-D%1=\"%2\"").arg(key,
+                options.value(key, QString()).toString());
+    }
+
+    arguments << binDir.path() + "/trustbridge.nsi";
+
+    mNSISProc.start();
+    mProgress.show();
+
+    if (!mNSISProc.waitForStarted() ||
+        mNSISProc.state() == QProcess::NotRunning) {
+        showErrorMessage(tr("Failed to start makensis.\n"
+            "Please ensure that makensis is installed and in your PATH variable."));
+    }
+
+
+
+
 }
diff -r 9d3880db6ba7 -r 3332db04c77d ui/createinstallerdialog.h
--- a/ui/createinstallerdialog.h	Mon Apr 28 14:02:40 2014 +0000
+++ b/ui/createinstallerdialog.h	Mon Apr 28 17:15:31 2014 +0000
@@ -11,6 +11,8 @@
 #include <QDialog>
 #include <QMainWindow>
 #include <QLineEdit>
+#include <QProcess>
+#include <QProgressDialog>
 /**
  * @file createinstallerdialog.h
  * @brief The dialog to show settings and create an installer.
@@ -34,6 +36,9 @@
     QLineEdit *mBinaryFolder;
     QLineEdit *mSaveFile;
 
+    QProcess mNSISProc;
+    QProgressDialog mProgress;
+
     /** @brief show an error message with QMessageBox
      *
      * @param [in] msg The message to show
@@ -45,6 +50,10 @@
     void openFolderSelect();
     void openSaveLocation();
     void createInstaller();
+
+    /* Slots for the creator process */
+    void processError(QProcess::ProcessError error);
+    void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
 };
 
 #endif // CREATEINSTALLERDIALOG_H


More information about the Trustbridge-commits mailing list