Mercurial > trustbridge
diff ui/mainwindow.cpp @ 1116:df2297e741ad
(issue127) Rename the installer to a pretty name before execution.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 16 Sep 2014 11:45:20 +0200 |
parents | b6cb4fd7ee20 |
children | dd9094d92899 |
line wrap: on
line diff
--- a/ui/mainwindow.cpp Tue Sep 16 11:57:05 2014 +0200 +++ b/ui/mainwindow.cpp Tue Sep 16 11:45:20 2014 +0200 @@ -17,6 +17,7 @@ #include <QMenu> #include <QApplication> #include <QFile> +#include <QTemporaryDir> #include <QTimer> #include <QHBoxLayout> #include <QVBoxLayout> @@ -291,9 +292,42 @@ showMessage(); } +QString getPrettyInstallerName(QString realFileName) { + QTemporaryDir tDir; + if (!tDir.isValid()) { + qDebug () << "Failed to create temporary directory."; + return QString(); + } + QString targetPath = tDir.path() + QObject::tr("TrustBridge-Updater", + "Used as filename for the updater. Only use ASCII please."); + + tDir.setAutoRemove(false); +#ifdef WIN32 + targetPath += ".exe"; +#endif + if (!QFile::copy(realFileName, targetPath)) { + qDebug() << "Failed to create temporary copy of installer."; + } + return targetPath; +} + void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) { QFileInfo instProcInfo = QFileInfo(fileName); QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath()); + + /* Copy the file to a temporary name for installation */ + filePath = getPrettyInstallerName(filePath); + + if (filePath.isEmpty()) { + qDebug() << "Failed to copy updater to temporary location."; + showErrorMessage(tr("Failed to create update process.") + "\n" + + tr("This could be caused by not enough disk space or invalid permissions.")); + return; + } + mSettings.setValue("Software/Updater", filePath); /* So it can be deleted + on next start */ + mSettings.sync(); + bin_verify_result vres = verify_binary(filePath.toUtf8().constData(), filePath.toUtf8().size()); @@ -383,6 +417,22 @@ { verifyListData(); + /* Delete old temporary installers if they exist */ + QString oldUpdater = mSettings.value("Software/Updater").toString(); + + if (!oldUpdater.isEmpty()) { + qDebug() << "Removing old updater: " << oldUpdater; + QFileInfo fiUpdater(oldUpdater); + if (!QFile::remove(fiUpdater.absoluteFilePath())) { + qDebug() << "Failed to remove file"; + } else { + if (!fiUpdater.absoluteDir().rmdir(fiUpdater.absoluteDir().absolutePath())) { + qDebug() << "Failed to remove temporary directory."; + } + } + mSettings.remove("Software/Updater"); + } + if (!mSettings.contains("Software/installedDate") || mSettings.value("Software/installedVersion").toString() != QApplication::applicationVersion()) { /* This should only happen on initial startup and after an update has