1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 04:15:26 +03:00
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:
Damjan Adamic 2014-08-03 19:18:28 +02:00
parent 4103adf75d
commit 741ef45f3e
9 changed files with 57 additions and 47 deletions

View file

@ -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";

View file

@ -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());

View file

@ -156,8 +156,8 @@ void CompareDialog::dropEvent(QDropEvent *event)
void CompareDialog::closeEvent(QCloseEvent *event)
{
unlink(curvefile5);
unlink(curvefile9);
qunlink(curvefile5);
qunlink(curvefile9);
}
CompareDialog::~CompareDialog()

View file

@ -1,4 +1,11 @@
#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 "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;
}

View file

@ -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

View file

@ -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 << "<?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\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<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";

View file

@ -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;

View file

@ -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) {

View file

@ -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)