mirror of
https://github.com/opentx/opentx.git
synced 2025-07-14 03:49:52 +03:00
Re #1567:
introduced generateProcessUniqueTempFileName() which is used everywhere we need temporary file renamed unlink() into qunlink() fixed missing deletion of curve pngs in print dialog
This commit is contained in:
parent
4103adf75d
commit
741ef45f3e
9 changed files with 57 additions and 47 deletions
|
@ -354,10 +354,8 @@ void burnConfigDialog::restFuses(bool eeProtect)
|
||||||
//use hfuse = 0x81 to prevent eeprom being erased with every flashing
|
//use hfuse = 0x81 to prevent eeprom being erased with every flashing
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QString tempDir = QDir::tempPath();
|
|
||||||
QString tempFile;
|
|
||||||
QString lfuses;
|
QString lfuses;
|
||||||
tempFile = tempDir + "/ftemp.bin";
|
QString tempFile = generateProcessUniqueTempFileName("ftemp.bin");
|
||||||
QStringList argread;
|
QStringList argread;
|
||||||
argread << "-c" << avrProgrammer << "-p" << avrMCU << args <<"-U" << "lfuse:r:"+tempFile+":r" ;
|
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);
|
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";
|
lfuses="lfuse:w:0x3F:m";
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
unlink(tempFile);
|
qunlink(tempFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lfuses="lfuse:w:0x3F:m";
|
lfuses="lfuse:w:0x3F:m";
|
||||||
|
|
|
@ -418,12 +418,11 @@ void burnDialog::on_BurnFlashButton_clicked()
|
||||||
image = pixmap->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height());
|
image = pixmap->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height());
|
||||||
}
|
}
|
||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
QString tempDir = QDir::tempPath();
|
|
||||||
QString tempFile;
|
QString tempFile;
|
||||||
if (getFileType(fileName) == FILE_TYPE_HEX)
|
if (getFileType(fileName) == FILE_TYPE_HEX)
|
||||||
tempFile = tempDir + "/flash.hex";
|
tempFile = generateProcessUniqueTempFileName("flash.hex");
|
||||||
else
|
else
|
||||||
tempFile = tempDir + "/flash.bin";
|
tempFile = generateProcessUniqueTempFileName("flash.bin");
|
||||||
FlashInterface flash(fileName);
|
FlashInterface flash(fileName);
|
||||||
flash.setSplash(image);
|
flash.setSplash(image);
|
||||||
if (flash.saveFlash(tempFile) > 0) {
|
if (flash.saveFlash(tempFile) > 0) {
|
||||||
|
@ -556,8 +555,7 @@ void burnDialog::on_BurnFlashButton_clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patch) {
|
if (patch) {
|
||||||
QString tempDir = QDir::tempPath();
|
QString fileName = generateProcessUniqueTempFileName("temp.bin");
|
||||||
QString fileName = tempDir + "/temp.bin";
|
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
|
|
||||||
uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize());
|
uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize());
|
||||||
|
|
|
@ -156,8 +156,8 @@ void CompareDialog::dropEvent(QDropEvent *event)
|
||||||
|
|
||||||
void CompareDialog::closeEvent(QCloseEvent *event)
|
void CompareDialog::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
unlink(curvefile5);
|
qunlink(curvefile5);
|
||||||
unlink(curvefile9);
|
qunlink(curvefile9);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompareDialog::~CompareDialog()
|
CompareDialog::~CompareDialog()
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
#if defined WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
#if !defined WIN32 && defined __GNUC__
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#include "appdata.h"
|
#include "appdata.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "simulatordialog.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();
|
QByteArray ba = fileName.toLatin1();
|
||||||
return unlink(ba.constData());
|
return unlink(ba.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString generateProcessUniqueTempFileName(const QString & fileName)
|
||||||
|
{
|
||||||
|
QString sanitizedFileName = fileName;
|
||||||
|
sanitizedFileName.remove('/');
|
||||||
|
return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName;
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
#endif // HELPERS_H
|
||||||
|
|
|
@ -239,13 +239,13 @@ void logsDialog::on_mapsButton_clicked() {
|
||||||
itemSelected=n-1;
|
itemSelected=n-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString geFilename = QDir::tempPath() + "/track0.png";
|
QString geIconFilename = generateProcessUniqueTempFileName("track0.png");
|
||||||
if (QFile::exists(geFilename)) {
|
if (QFile::exists(geIconFilename)) {
|
||||||
QFile::remove(geFilename);
|
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)) {
|
if (QFile::exists(geFilename)) {
|
||||||
QFile::remove(geFilename);
|
QFile::remove(geFilename);
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ void logsDialog::on_mapsButton_clicked() {
|
||||||
QTextStream outputStream(&geFile);
|
QTextStream outputStream(&geFile);
|
||||||
outputStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">\n";
|
outputStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">\n";
|
||||||
outputStream << "\t<Document>\n\t\t<name>" << logFilename << "</name>\n";
|
outputStream << "\t<Document>\n\t\t<name>" << logFilename << "</name>\n";
|
||||||
outputStream << "\t\t<Style id=\"multiTrack_n\">\n\t\t\t<IconStyle>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>file://" << QDir::tempPath() << "/track0.png</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
|
outputStream << "\t\t<Style id=\"multiTrack_n\">\n\t\t\t<IconStyle>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>file://" << geIconFilename << "</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
|
||||||
outputStream << "\t\t<Style id=\"multiTrack_h\">\n\t\t\t<IconStyle>\n\t\t\t\t<scale>0</scale>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>file://" << QDir::tempPath() << "/track0.png</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>8</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
|
outputStream << "\t\t<Style id=\"multiTrack_h\">\n\t\t\t<IconStyle>\n\t\t\t\t<scale>0</scale>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>file://" << QDir::tempPath() << "/track0.png</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>8</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
|
||||||
outputStream << "\t\t<StyleMap id=\"multiTrack\">\n\t\t\t<Pair>\n\t\t\t\t<key>normal</key>\n\t\t\t\t<styleUrl>#multiTrack_n</styleUrl>\n\t\t\t</Pair>\n\t\t\t<Pair>\n\t\t\t\t<key>highlight</key>\n\t\t\t\t<styleUrl>#multiTrack_h</styleUrl>\n\t\t\t</Pair>\n\t\t</StyleMap>\n";
|
outputStream << "\t\t<StyleMap id=\"multiTrack\">\n\t\t\t<Pair>\n\t\t\t\t<key>normal</key>\n\t\t\t\t<styleUrl>#multiTrack_n</styleUrl>\n\t\t\t</Pair>\n\t\t\t<Pair>\n\t\t\t\t<key>highlight</key>\n\t\t\t\t<styleUrl>#multiTrack_h</styleUrl>\n\t\t\t</Pair>\n\t\t</StyleMap>\n";
|
||||||
outputStream << "\t\t<Style id=\"lineStyle\">\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
|
outputStream << "\t\t<Style id=\"lineStyle\">\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
|
||||||
|
|
|
@ -804,9 +804,9 @@ QStringList MainWindow::GetSambaArguments(const QString &tcl)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
QString tclFilename = QDir::tempPath() + "/temp.tcl";
|
QString tclFilename = generateProcessUniqueTempFileName("temp.tcl");
|
||||||
if (QFile::exists(tclFilename)) {
|
if (QFile::exists(tclFilename)) {
|
||||||
unlink(tclFilename);
|
qunlink(tclFilename);
|
||||||
}
|
}
|
||||||
QFile tclFile(tclFilename);
|
QFile tclFile(tclFilename);
|
||||||
if (!tclFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if (!tclFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
@ -946,15 +946,14 @@ QString MainWindow::FindMassstoragePath(QString filename)
|
||||||
|
|
||||||
void MainWindow::readEeprom()
|
void MainWindow::readEeprom()
|
||||||
{
|
{
|
||||||
QString tempDir = QDir::tempPath();
|
QString tempFile;
|
||||||
QString tempFile = tempDir + QString("/temp-%1").arg(QCoreApplication::applicationPid());;
|
|
||||||
|
|
||||||
EEPROMInterface *eepromInterface = GetEepromInterface();
|
EEPROMInterface *eepromInterface = GetEepromInterface();
|
||||||
|
|
||||||
if (IS_ARM(eepromInterface->getBoard()))
|
if (IS_ARM(eepromInterface->getBoard()))
|
||||||
tempFile += ".bin";
|
tempFile = generateProcessUniqueTempFileName("temp.bin");
|
||||||
else
|
else
|
||||||
tempFile += ".hex";
|
tempFile += generateProcessUniqueTempFileName("temp.hex");
|
||||||
|
|
||||||
qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile;
|
qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile;
|
||||||
|
|
||||||
|
@ -963,7 +962,7 @@ void MainWindow::readEeprom()
|
||||||
child->newFile();
|
child->newFile();
|
||||||
child->loadFile(tempFile, false);
|
child->loadFile(tempFile, false);
|
||||||
child->show();
|
child->show();
|
||||||
unlink(tempFile);
|
qunlink(tempFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1171,13 +1170,12 @@ void MainWindow::writeBackup()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int oldrev = getEpromVersion(fileName);
|
int oldrev = getEpromVersion(fileName);
|
||||||
QString tempDir = QDir::tempPath();
|
QString tempFlash = generateProcessUniqueTempFileName("flash.bin");
|
||||||
QString tempFlash = tempDir + QString("/flash-%1.bin").arg(QCoreApplication::applicationPid());
|
|
||||||
|
|
||||||
if (!readFirmwareFromRadio(tempFlash))
|
if (!readFirmwareFromRadio(tempFlash))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString restoreFile = tempDir + QString("/compat.bin-%1.bin").arg(QCoreApplication::applicationPid());
|
QString restoreFile = generateProcessUniqueTempFileName("compat.bin");
|
||||||
if (!convertEEPROM(fileName, restoreFile, tempFlash)) {
|
if (!convertEEPROM(fileName, restoreFile, tempFlash)) {
|
||||||
int ret = QMessageBox::question(this, "Error", tr("Cannot check Models and Settings compatibility! Continue anyway?") ,
|
int ret = QMessageBox::question(this, "Error", tr("Cannot check Models and Settings compatibility! Continue anyway?") ,
|
||||||
QMessageBox::Yes | QMessageBox::No);
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
@ -1194,7 +1192,7 @@ void MainWindow::writeBackup()
|
||||||
}
|
}
|
||||||
fileName = restoreFile;
|
fileName = restoreFile;
|
||||||
}
|
}
|
||||||
unlink(tempFlash);
|
qunlink(tempFlash);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (backupEnable) {
|
if (backupEnable) {
|
||||||
|
@ -1308,8 +1306,7 @@ void MainWindow::writeFlash(QString fileToFlash)
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
g.backupOnFlash(backup);
|
g.backupOnFlash(backup);
|
||||||
if (backup) {
|
if (backup) {
|
||||||
QString tempDir = QDir::tempPath();
|
QString backupFile = generateProcessUniqueTempFileName("backup.bin");
|
||||||
QString backupFile = tempDir + "/backup.bin";
|
|
||||||
bool backupEnable=g.enableBackup();
|
bool backupEnable=g.enableBackup();
|
||||||
QString backupPath=g.backupDir();
|
QString backupPath=g.backupDir();
|
||||||
if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) {
|
if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) {
|
||||||
|
@ -1334,7 +1331,7 @@ void MainWindow::writeFlash(QString fileToFlash)
|
||||||
sleep(2);
|
sleep(2);
|
||||||
int res = writeFirmwareToRadio(fileName);
|
int res = writeFirmwareToRadio(fileName);
|
||||||
if (res) {
|
if (res) {
|
||||||
QString restoreFile = tempDir + "/restore.bin";
|
QString restoreFile = generateProcessUniqueTempFileName("restore.bin");
|
||||||
if (!convertEEPROM(backupFile, restoreFile, fileName)) {
|
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"));
|
QMessageBox::warning(this, tr("Conversion failed"), tr("Cannot convert Models and Settings for use with this firmware, original data will be used"));
|
||||||
restoreFile = backupFile;
|
restoreFile = backupFile;
|
||||||
|
|
|
@ -531,8 +531,7 @@ void MdiChild::writeEeprom() // write to Tx
|
||||||
}
|
}
|
||||||
QString stickCal=g.profile[g.id()].stickPotCalib();
|
QString stickCal=g.profile[g.id()].stickPotCalib();
|
||||||
burnConfigDialog bcd;
|
burnConfigDialog bcd;
|
||||||
QString tempDir = QDir::tempPath();
|
QString tempFile = generateProcessUniqueTempFileName("temp.bin");
|
||||||
QString tempFile = tempDir + "/temp.bin";
|
|
||||||
saveFile(tempFile, false);
|
saveFile(tempFile, false);
|
||||||
if(!QFileInfo(tempFile).exists()) {
|
if(!QFileInfo(tempFile).exists()) {
|
||||||
QMessageBox::critical(this,tr("Error"), tr("Cannot write temporary file!"));
|
QMessageBox::critical(this,tr("Error"), tr("Cannot write temporary file!"));
|
||||||
|
@ -550,12 +549,12 @@ void MdiChild::writeEeprom() // write to Tx
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int oldrev=((MainWindow *)this->parent())->getEpromVersion(tempFile);
|
int oldrev=((MainWindow *)this->parent())->getEpromVersion(tempFile);
|
||||||
QString tempFlash=tempDir + "/flash.bin";
|
QString tempFlash = generateProcessUniqueTempFileName("flash.bin");
|
||||||
|
|
||||||
if (!((MainWindow *)this->parent())->readFirmwareFromRadio(tempFlash))
|
if (!((MainWindow *)this->parent())->readFirmwareFromRadio(tempFlash))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString restoreFile = tempDir + "/compat.bin";
|
QString restoreFile = generateProcessUniqueTempFileName("compat.bin");
|
||||||
if (!((MainWindow *)this->parent())->convertEEPROM(tempFile, restoreFile, tempFlash)) {
|
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);
|
int ret = QMessageBox::question(this, tr("Error"), tr("Cannot check eeprom compatibility! Continue anyway?"), QMessageBox::Yes | QMessageBox::No);
|
||||||
if (ret == QMessageBox::No)
|
if (ret == QMessageBox::No)
|
||||||
|
@ -571,7 +570,7 @@ void MdiChild::writeEeprom() // write to Tx
|
||||||
}
|
}
|
||||||
tempFile=restoreFile;
|
tempFile=restoreFile;
|
||||||
}
|
}
|
||||||
unlink(tempFlash);
|
qunlink(tempFlash);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (backupEnable) {
|
if (backupEnable) {
|
||||||
|
|
|
@ -31,12 +31,12 @@ PrintDialog::PrintDialog(QWidget *parent, FirmwareInterface * firmware, GeneralS
|
||||||
te->clear();
|
te->clear();
|
||||||
QString modelname=g_model->name;
|
QString modelname=g_model->name;
|
||||||
if (modelname.isEmpty()) {
|
if (modelname.isEmpty()) {
|
||||||
curvefile5=QString("%1/curve5.png").arg(qd->tempPath());
|
curvefile5=generateProcessUniqueTempFileName("curve5.png");
|
||||||
curvefile9=QString("%1/curve9.png").arg(qd->tempPath());
|
curvefile9=generateProcessUniqueTempFileName("curve9.png");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
curvefile5=QString("%1/%2-curve5.png").arg(qd->tempPath()).arg(modelname);
|
curvefile5=generateProcessUniqueTempFileName(QString("%1-curve5.png").arg(modelname));
|
||||||
curvefile9=QString("%1/%2-curve9.png").arg(qd->tempPath()).arg(modelname);
|
curvefile9=generateProcessUniqueTempFileName(QString("%1-curve9.png").arg(modelname));
|
||||||
}
|
}
|
||||||
printSetup();
|
printSetup();
|
||||||
if (gvars) {
|
if (gvars) {
|
||||||
|
@ -60,15 +60,16 @@ PrintDialog::PrintDialog(QWidget *parent, FirmwareInterface * firmware, GeneralS
|
||||||
|
|
||||||
void PrintDialog::closeEvent(QCloseEvent *event)
|
void PrintDialog::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
if (printfilename.isEmpty()) {
|
// if (printfilename.isEmpty()) {
|
||||||
unlink(curvefile5);
|
// }
|
||||||
unlink(curvefile9);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintDialog::~PrintDialog()
|
PrintDialog::~PrintDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
qDebug() << "PrintDialog::~PrintDialog";
|
||||||
|
qunlink(curvefile5);
|
||||||
|
qunlink(curvefile9);
|
||||||
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString doTC(const QString s, const QString color="", bool bold=false)
|
QString doTC(const QString s, const QString color="", bool bold=false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue