# HG changeset patch # User Andre Heinecke # Date 1410860720 -7200 # Node ID df2297e741ad6b632e0db87b571921027e53b616 # Parent 648ac596a98a2542c607ec65a1b7b30b619b52b1 (issue127) Rename the installer to a pretty name before execution. diff -r 648ac596a98a -r df2297e741ad ui/mainwindow.cpp --- 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 #include #include +#include #include #include #include @@ -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