changeset 516:3332db04c77d

Call makensis in create installer dialog
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 28 Apr 2014 17:15:31 +0000
parents 9d3880db6ba7
children a3e027cd0683
files ui/createinstallerdialog.cpp ui/createinstallerdialog.h
diffstat 2 files changed, 77 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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."));
+    }
+
+
+
+
 }
--- 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

http://wald.intevation.org/projects/trustbridge/