diff --git a/companion/src/burnconfigdialog.cpp b/companion/src/burnconfigdialog.cpp index 2ccf4609a..3c52fbecc 100644 --- a/companion/src/burnconfigdialog.cpp +++ b/companion/src/burnconfigdialog.cpp @@ -354,10 +354,8 @@ void burnConfigDialog::restFuses(bool eeProtect) //use hfuse = 0x81 to prevent eeprom being erased with every flashing } else { - QString tempDir = QDir::tempPath(); - QString tempFile; QString lfuses; - tempFile = tempDir + "/ftemp.bin"; + QString tempFile = generateProcessUniqueTempFileName("ftemp.bin"); QStringList argread; argread << "-c" << avrProgrammer << "-p" << avrMCU << args <<"-U" << "lfuse:r:"+tempFile+":r" ; avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, argread, "Reset Fuses",AVR_DIALOG_CLOSE_IF_SUCCESSFUL,FALSE); @@ -376,7 +374,7 @@ void burnConfigDialog::restFuses(bool eeProtect) lfuses="lfuse:w:0x3F:m"; } file.close(); - unlink(tempFile); + qunlink(tempFile); } else { lfuses="lfuse:w:0x3F:m"; diff --git a/companion/src/burndialog.cpp b/companion/src/burndialog.cpp index a64ee1a37..d0c166cfc 100644 --- a/companion/src/burndialog.cpp +++ b/companion/src/burndialog.cpp @@ -418,12 +418,11 @@ void burnDialog::on_BurnFlashButton_clicked() image = pixmap->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height()); } if (!image.isNull()) { - QString tempDir = QDir::tempPath(); QString tempFile; if (getFileType(fileName) == FILE_TYPE_HEX) - tempFile = tempDir + "/flash.hex"; + tempFile = generateProcessUniqueTempFileName("flash.hex"); else - tempFile = tempDir + "/flash.bin"; + tempFile = generateProcessUniqueTempFileName("flash.bin"); FlashInterface flash(fileName); flash.setSplash(image); if (flash.saveFlash(tempFile) > 0) { @@ -556,8 +555,7 @@ void burnDialog::on_BurnFlashButton_clicked() } if (patch) { - QString tempDir = QDir::tempPath(); - QString fileName = tempDir + "/temp.bin"; + QString fileName = generateProcessUniqueTempFileName("temp.bin"); QFile file(fileName); uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize()); diff --git a/companion/src/comparedialog.cpp b/companion/src/comparedialog.cpp index 94197c382..b5f1c4feb 100644 --- a/companion/src/comparedialog.cpp +++ b/companion/src/comparedialog.cpp @@ -156,8 +156,8 @@ void CompareDialog::dropEvent(QDropEvent *event) void CompareDialog::closeEvent(QCloseEvent *event) { - unlink(curvefile5); - unlink(curvefile9); + qunlink(curvefile5); + qunlink(curvefile9); } CompareDialog::~CompareDialog() diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index f726949db..f8e4960a2 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -1,4 +1,11 @@ #include +#if defined WIN32 + #include + #include +#endif +#if !defined WIN32 && defined __GNUC__ + #include +#endif #include "appdata.h" #include "helpers.h" #include "simulatordialog.h" @@ -966,8 +973,16 @@ QString index2version(int index) } -int unlink(const QString & fileName) +int qunlink(const QString & fileName) { + qDebug() << "unlinking "<< fileName; QByteArray ba = fileName.toLatin1(); return unlink(ba.constData()); } + +QString generateProcessUniqueTempFileName(const QString & fileName) +{ + QString sanitizedFileName = fileName; + sanitizedFileName.remove('/'); + return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName; +} diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 5d33e1a0a..a6cabb8cf 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -140,6 +140,8 @@ class QTimeS : public QTime }; -int unlink(const QString & fileName); +int qunlink(const QString & fileName); + +QString generateProcessUniqueTempFileName(const QString & fileName); #endif // HELPERS_H diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index 37cc36619..d4ca6e913 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -239,13 +239,13 @@ void logsDialog::on_mapsButton_clicked() { itemSelected=n-1; } - QString geFilename = QDir::tempPath() + "/track0.png"; - if (QFile::exists(geFilename)) { - QFile::remove(geFilename); + QString geIconFilename = generateProcessUniqueTempFileName("track0.png"); + if (QFile::exists(geIconFilename)) { + QFile::remove(geIconFilename); } - QFile::copy(":/images/track0.png", geFilename); + QFile::copy(":/images/track0.png", geIconFilename); - geFilename = QDir::tempPath() + "/flight.kml"; + QString geFilename = generateProcessUniqueTempFileName("flight.kml"); if (QFile::exists(geFilename)) { QFile::remove(geFilename); } @@ -264,7 +264,7 @@ void logsDialog::on_mapsButton_clicked() { QTextStream outputStream(&geFile); outputStream << "\n\n"; outputStream << "\t\n\t\t" << logFilename << "\n"; - outputStream << "\t\t\n"; + outputStream << "\t\t\n"; outputStream << "\t\t\n"; outputStream << "\t\t\n\t\t\t\n\t\t\t\tnormal\n\t\t\t\t#multiTrack_n\n\t\t\t\n\t\t\t\n\t\t\t\thighlight\n\t\t\t\t#multiTrack_h\n\t\t\t\n\t\t\n"; outputStream << "\t\t\n"; diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index d48be68bb..e05c013d8 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -804,9 +804,9 @@ QStringList MainWindow::GetSambaArguments(const QString &tcl) { QStringList result; - QString tclFilename = QDir::tempPath() + "/temp.tcl"; + QString tclFilename = generateProcessUniqueTempFileName("temp.tcl"); if (QFile::exists(tclFilename)) { - unlink(tclFilename); + qunlink(tclFilename); } QFile tclFile(tclFilename); if (!tclFile.open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -946,15 +946,14 @@ QString MainWindow::FindMassstoragePath(QString filename) void MainWindow::readEeprom() { - QString tempDir = QDir::tempPath(); - QString tempFile = tempDir + QString("/temp-%1").arg(QCoreApplication::applicationPid());; + QString tempFile; EEPROMInterface *eepromInterface = GetEepromInterface(); if (IS_ARM(eepromInterface->getBoard())) - tempFile += ".bin"; + tempFile = generateProcessUniqueTempFileName("temp.bin"); else - tempFile += ".hex"; + tempFile += generateProcessUniqueTempFileName("temp.hex"); qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile; @@ -963,7 +962,7 @@ void MainWindow::readEeprom() child->newFile(); child->loadFile(tempFile, false); child->show(); - unlink(tempFile); + qunlink(tempFile); } } @@ -1171,13 +1170,12 @@ void MainWindow::writeBackup() return; } int oldrev = getEpromVersion(fileName); - QString tempDir = QDir::tempPath(); - QString tempFlash = tempDir + QString("/flash-%1.bin").arg(QCoreApplication::applicationPid()); + QString tempFlash = generateProcessUniqueTempFileName("flash.bin"); if (!readFirmwareFromRadio(tempFlash)) return; - QString restoreFile = tempDir + QString("/compat.bin-%1.bin").arg(QCoreApplication::applicationPid()); + QString restoreFile = generateProcessUniqueTempFileName("compat.bin"); if (!convertEEPROM(fileName, restoreFile, tempFlash)) { int ret = QMessageBox::question(this, "Error", tr("Cannot check Models and Settings compatibility! Continue anyway?") , QMessageBox::Yes | QMessageBox::No); @@ -1194,7 +1192,7 @@ void MainWindow::writeBackup() } fileName = restoreFile; } - unlink(tempFlash); + qunlink(tempFlash); } else { if (backupEnable) { @@ -1308,8 +1306,7 @@ void MainWindow::writeFlash(QString fileToFlash) if (!fileName.isEmpty()) { g.backupOnFlash(backup); if (backup) { - QString tempDir = QDir::tempPath(); - QString backupFile = tempDir + "/backup.bin"; + QString backupFile = generateProcessUniqueTempFileName("backup.bin"); bool backupEnable=g.enableBackup(); QString backupPath=g.backupDir(); if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) { @@ -1334,7 +1331,7 @@ void MainWindow::writeFlash(QString fileToFlash) sleep(2); int res = writeFirmwareToRadio(fileName); if (res) { - QString restoreFile = tempDir + "/restore.bin"; + QString restoreFile = generateProcessUniqueTempFileName("restore.bin"); if (!convertEEPROM(backupFile, restoreFile, fileName)) { QMessageBox::warning(this, tr("Conversion failed"), tr("Cannot convert Models and Settings for use with this firmware, original data will be used")); restoreFile = backupFile; diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index a62be58e0..42f3fa8d1 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -531,8 +531,7 @@ void MdiChild::writeEeprom() // write to Tx } QString stickCal=g.profile[g.id()].stickPotCalib(); burnConfigDialog bcd; - QString tempDir = QDir::tempPath(); - QString tempFile = tempDir + "/temp.bin"; + QString tempFile = generateProcessUniqueTempFileName("temp.bin"); saveFile(tempFile, false); if(!QFileInfo(tempFile).exists()) { QMessageBox::critical(this,tr("Error"), tr("Cannot write temporary file!")); @@ -550,12 +549,12 @@ void MdiChild::writeEeprom() // write to Tx return; } int oldrev=((MainWindow *)this->parent())->getEpromVersion(tempFile); - QString tempFlash=tempDir + "/flash.bin"; + QString tempFlash = generateProcessUniqueTempFileName("flash.bin"); if (!((MainWindow *)this->parent())->readFirmwareFromRadio(tempFlash)) return; - QString restoreFile = tempDir + "/compat.bin"; + QString restoreFile = generateProcessUniqueTempFileName("compat.bin"); if (!((MainWindow *)this->parent())->convertEEPROM(tempFile, restoreFile, tempFlash)) { int ret = QMessageBox::question(this, tr("Error"), tr("Cannot check eeprom compatibility! Continue anyway?"), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::No) @@ -571,7 +570,7 @@ void MdiChild::writeEeprom() // write to Tx } tempFile=restoreFile; } - unlink(tempFlash); + qunlink(tempFlash); } else { if (backupEnable) { diff --git a/companion/src/printdialog.cpp b/companion/src/printdialog.cpp index 2e8d281b1..a8f42b0fc 100644 --- a/companion/src/printdialog.cpp +++ b/companion/src/printdialog.cpp @@ -31,12 +31,12 @@ PrintDialog::PrintDialog(QWidget *parent, FirmwareInterface * firmware, GeneralS te->clear(); QString modelname=g_model->name; if (modelname.isEmpty()) { - curvefile5=QString("%1/curve5.png").arg(qd->tempPath()); - curvefile9=QString("%1/curve9.png").arg(qd->tempPath()); + curvefile5=generateProcessUniqueTempFileName("curve5.png"); + curvefile9=generateProcessUniqueTempFileName("curve9.png"); } else { - curvefile5=QString("%1/%2-curve5.png").arg(qd->tempPath()).arg(modelname); - curvefile9=QString("%1/%2-curve9.png").arg(qd->tempPath()).arg(modelname); + curvefile5=generateProcessUniqueTempFileName(QString("%1-curve5.png").arg(modelname)); + curvefile9=generateProcessUniqueTempFileName(QString("%1-curve9.png").arg(modelname)); } printSetup(); if (gvars) { @@ -60,15 +60,16 @@ PrintDialog::PrintDialog(QWidget *parent, FirmwareInterface * firmware, GeneralS void PrintDialog::closeEvent(QCloseEvent *event) { - if (printfilename.isEmpty()) { - unlink(curvefile5); - unlink(curvefile9); - } + // if (printfilename.isEmpty()) { + // } } PrintDialog::~PrintDialog() { - delete ui; + qDebug() << "PrintDialog::~PrintDialog"; + qunlink(curvefile5); + qunlink(curvefile9); + delete ui; } QString doTC(const QString s, const QString color="", bool bold=false)