comparison 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
comparison
equal deleted inserted replaced
1115:648ac596a98a 1116:df2297e741ad
15 #include <QDialog> 15 #include <QDialog>
16 #include <QDir> 16 #include <QDir>
17 #include <QMenu> 17 #include <QMenu>
18 #include <QApplication> 18 #include <QApplication>
19 #include <QFile> 19 #include <QFile>
20 #include <QTemporaryDir>
20 #include <QTimer> 21 #include <QTimer>
21 #include <QHBoxLayout> 22 #include <QHBoxLayout>
22 #include <QVBoxLayout> 23 #include <QVBoxLayout>
23 #include <QGridLayout> 24 #include <QGridLayout>
24 #include <QGroupBox> 25 #include <QGroupBox>
289 290
290 mSettings.sync(); 291 mSettings.sync();
291 showMessage(); 292 showMessage();
292 } 293 }
293 294
295 QString getPrettyInstallerName(QString realFileName) {
296 QTemporaryDir tDir;
297 if (!tDir.isValid()) {
298 qDebug () << "Failed to create temporary directory.";
299 return QString();
300 }
301 QString targetPath = tDir.path() + QObject::tr("TrustBridge-Updater",
302 "Used as filename for the updater. Only use ASCII please.");
303
304 tDir.setAutoRemove(false);
305 #ifdef WIN32
306 targetPath += ".exe";
307 #endif
308 if (!QFile::copy(realFileName, targetPath)) {
309 qDebug() << "Failed to create temporary copy of installer.";
310 }
311 return targetPath;
312 }
313
294 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) { 314 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) {
295 QFileInfo instProcInfo = QFileInfo(fileName); 315 QFileInfo instProcInfo = QFileInfo(fileName);
296 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath()); 316 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
317
318 /* Copy the file to a temporary name for installation */
319 filePath = getPrettyInstallerName(filePath);
320
321 if (filePath.isEmpty()) {
322 qDebug() << "Failed to copy updater to temporary location.";
323 showErrorMessage(tr("Failed to create update process.") + "\n" +
324 tr("This could be caused by not enough disk space or invalid permissions."));
325 return;
326 }
327 mSettings.setValue("Software/Updater", filePath); /* So it can be deleted
328 on next start */
329 mSettings.sync();
330
297 bin_verify_result vres = verify_binary(filePath.toUtf8().constData(), 331 bin_verify_result vres = verify_binary(filePath.toUtf8().constData(),
298 filePath.toUtf8().size()); 332 filePath.toUtf8().size());
299 333
300 if (vres.result != VerifyValid) { 334 if (vres.result != VerifyValid) {
301 qDebug() << "Invalid software. Not installing"; 335 qDebug() << "Invalid software. Not installing";
380 } 414 }
381 415
382 void MainWindow::checkUpdates(bool downloadSW) 416 void MainWindow::checkUpdates(bool downloadSW)
383 { 417 {
384 verifyListData(); 418 verifyListData();
419
420 /* Delete old temporary installers if they exist */
421 QString oldUpdater = mSettings.value("Software/Updater").toString();
422
423 if (!oldUpdater.isEmpty()) {
424 qDebug() << "Removing old updater: " << oldUpdater;
425 QFileInfo fiUpdater(oldUpdater);
426 if (!QFile::remove(fiUpdater.absoluteFilePath())) {
427 qDebug() << "Failed to remove file";
428 } else {
429 if (!fiUpdater.absoluteDir().rmdir(fiUpdater.absoluteDir().absolutePath())) {
430 qDebug() << "Failed to remove temporary directory.";
431 }
432 }
433 mSettings.remove("Software/Updater");
434 }
385 435
386 if (!mSettings.contains("Software/installedDate") || 436 if (!mSettings.contains("Software/installedDate") ||
387 mSettings.value("Software/installedVersion").toString() != QApplication::applicationVersion()) { 437 mSettings.value("Software/installedVersion").toString() != QApplication::applicationVersion()) {
388 /* This should only happen on initial startup and after an update has 438 /* This should only happen on initial startup and after an update has
389 * been installed */ 439 * been installed */

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