From 55cb5dce877786a79bab1b5707ff77a95102bc40 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Sun, 3 Aug 2014 17:27:39 +0200 Subject: [PATCH] Re #1567: readEeprom(): * added PID to temporary file name * better error message * temporary file deletion --- companion/src/avroutputdialog.cpp | 4 ++-- companion/src/mainwindow.cpp | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/companion/src/avroutputdialog.cpp b/companion/src/avroutputdialog.cpp index a5f3e630b..fd3862ee5 100644 --- a/companion/src/avroutputdialog.cpp +++ b/companion/src/avroutputdialog.cpp @@ -156,11 +156,11 @@ void avrOutputDialog::doCopy() dest.close(); } else { - QMessageBox::warning(this, tr("Error"),tr("Cannot write destination") + ": " + dest.errorString()); + QMessageBox::warning(this, tr("Error"),tr("Cannot write destination") + ": " + dest.fileName() + ", " + tr("reason") + ": " + dest.errorString()); } } else { - QMessageBox::warning(this, tr("Error"),tr("Cannot open source file") + ": " + source.errorString()); + QMessageBox::warning(this, tr("Error"),tr("Cannot open source file") + ": " + source.fileName() + ", " + tr("reason") + ": " + source.errorString()); } source.close(); diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 2f1823583..d5341dc33 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -947,20 +947,23 @@ QString MainWindow::FindMassstoragePath(QString filename) void MainWindow::readEeprom() { QString tempDir = QDir::tempPath(); - QString tempFile; + QString tempFile = tempDir + QString("/temp-%1").arg(QCoreApplication::applicationPid());; EEPROMInterface *eepromInterface = GetEepromInterface(); if (IS_ARM(eepromInterface->getBoard())) - tempFile = tempDir + "/temp.bin"; + tempFile += ".bin"; else - tempFile = tempDir + "/temp.hex"; + tempFile += ".hex"; + + qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile; if (readEepromFromRadio(tempFile, tr("Read Models and Settings From Radio"))) { MdiChild *child = createMdiChild(); child->newFile(); child->loadFile(tempFile, false); child->show(); + unlink(tempFile.toAscii()); } } @@ -1042,7 +1045,10 @@ bool MainWindow::readEepromFromRadio(const QString filename, const QString messa QFile file(filename); if (file.exists()) { - file.remove(); + if (!file.remove()) { + QMessageBox::warning(this, tr("Error"), tr("Could not delete temporary file: %1").arg(filename)); + return false; + } } if (IS_ARM(GetCurrentFirmware()->getBoard())) {