mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 17:55:19 +03:00
Version automatically appended to the firmware name. Is now calculated
BEFORE the user chooses a filename!
This commit is contained in:
parent
9919ad026b
commit
483e36e646
5 changed files with 111 additions and 122 deletions
|
@ -87,6 +87,7 @@ void downloadDialog::fileError()
|
|||
reject();
|
||||
}
|
||||
|
||||
#if 0
|
||||
void downloadDialog::closeEvent( QCloseEvent * event)
|
||||
{
|
||||
// Delay closing 2 seconds to avoid unpleasant flashing download dialogs
|
||||
|
@ -96,4 +97,4 @@ void downloadDialog::closeEvent( QCloseEvent * event)
|
|||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,9 @@ private slots:
|
|||
void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
|
||||
|
||||
private:
|
||||
#if 0
|
||||
void closeEvent( QCloseEvent * event);
|
||||
#endif
|
||||
Ui::downloadDialog *ui;
|
||||
|
||||
QNetworkAccessManager qnam;
|
||||
|
|
|
@ -40,7 +40,7 @@ void FirmwarePreferencesDialog::on_checkFWUpdates_clicked()
|
|||
void FirmwarePreferencesDialog::on_fw_dnld_clicked()
|
||||
{
|
||||
MainWindow * mw = (MainWindow *)this->parent();
|
||||
mw->downloadLatestFW(current_firmware_variant);
|
||||
mw->dowloadLastFirmwareUpdate();
|
||||
initSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -138,15 +138,15 @@ MainWindow::MainWindow():
|
|||
printfilename=strl[count];
|
||||
}
|
||||
}
|
||||
if(strl.count()>1) str = strl[1];
|
||||
if(!str.isEmpty()) {
|
||||
if (strl.count()>1) str = strl[1];
|
||||
if (!str.isEmpty()) {
|
||||
int fileType = getFileType(str);
|
||||
|
||||
if(fileType==FILE_TYPE_HEX) {
|
||||
if (fileType==FILE_TYPE_HEX) {
|
||||
writeFlash(str);
|
||||
}
|
||||
|
||||
if(fileType==FILE_TYPE_EEPE || fileType==FILE_TYPE_EEPM || fileType==FILE_TYPE_BIN) {
|
||||
if (fileType==FILE_TYPE_EEPE || fileType==FILE_TYPE_EEPM || fileType==FILE_TYPE_BIN) {
|
||||
MdiChild *child = createMdiChild();
|
||||
if (child->loadFile(str)) {
|
||||
if (!(printing && (model >=0 && model<GetEepromInterface()->getMaxModels()) && !printfilename.isEmpty() )) {
|
||||
|
@ -207,11 +207,17 @@ void MainWindow::checkForFirmwareUpdate()
|
|||
checkForUpdates();
|
||||
}
|
||||
|
||||
void MainWindow::dowloadLastFirmwareUpdate()
|
||||
{
|
||||
checkForUpdatesState = CHECK_FIRMWARE | AUTOMATIC_DOWNLOAD | SHOW_DIALOG_WAIT;
|
||||
checkForUpdates();
|
||||
}
|
||||
|
||||
void MainWindow::checkForUpdates()
|
||||
{
|
||||
if (checkForUpdatesState & SHOW_DIALOG_WAIT) {
|
||||
checkForUpdatesState -= SHOW_DIALOG_WAIT;
|
||||
downloadDialog_forWait = new downloadDialog(this, tr("Checking for updates"));
|
||||
downloadDialog_forWait = new downloadDialog(NULL, tr("Checking for updates"));
|
||||
downloadDialog_forWait->show();
|
||||
}
|
||||
|
||||
|
@ -320,18 +326,6 @@ void MainWindow::updateDownloaded()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::downloadLatestFW(FirmwareVariant & firmware)
|
||||
{
|
||||
QString url, ext;
|
||||
url = firmware.getFirmwareUrl();
|
||||
ext = url.mid(url.lastIndexOf("."));
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + firmware.id + ext);
|
||||
if (!filename.isEmpty()) {
|
||||
needRename = true;
|
||||
startFirmwareDownload(url, filename);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::firmwareDownloadAccepted()
|
||||
{
|
||||
QString errormsg;
|
||||
|
@ -370,31 +364,13 @@ void MainWindow::firmwareDownloadAccepted()
|
|||
return;
|
||||
}
|
||||
file.close();
|
||||
FlashInterface flash(g.profile[g.id()].fwName());
|
||||
int stamp = flash.getVersionId();
|
||||
if (stamp > 0) {
|
||||
#if 0
|
||||
if (g.profile[g.id()].renameFwFiles() && needRename) {
|
||||
QFileInfo fi(g.profile[g.id()].fwName());
|
||||
QString path=fi.path()+QDir::separator ();
|
||||
path.append(fi.completeBaseName());
|
||||
path.append(rev.mid(pos));
|
||||
path.append(".");
|
||||
path.append(fi.suffix());
|
||||
QDir qd;
|
||||
qd.remove(path);
|
||||
qd.rename(g.profile[g.id()].fwName(),path);
|
||||
g.profile[g.id()].fwName(path);
|
||||
}
|
||||
#endif
|
||||
g.fwRev.set(current_firmware_variant.id, stamp);
|
||||
g.fwRev.set(current_firmware_variant.id, version2index(firmwareVersionString));
|
||||
if (g.profile[g.id()].burnFirmware()) {
|
||||
int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the radio now ?"), QMessageBox::Yes | QMessageBox::No);
|
||||
if (ret == QMessageBox::Yes) {
|
||||
writeFlash(g.profile[g.id()].fwName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
||||
|
@ -411,13 +387,18 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||
|
||||
QString versionString;
|
||||
if (versionIndex > 0 && dateIndex > 0) {
|
||||
versionString = qba.mid(versionIndex+10, qba.indexOf("\"", versionIndex+10)-versionIndex-10);
|
||||
firmwareVersionString = qba.mid(versionIndex+10, qba.indexOf("\"", versionIndex+10)-versionIndex-10);
|
||||
QString dateString = qba.mid(dateIndex+10, 10);
|
||||
version = version2index(versionString);
|
||||
versionString = QString("%1 (%2)").arg(versionString).arg(dateString);
|
||||
version = version2index(firmwareVersionString);
|
||||
versionString = QString("%1 (%2)").arg(firmwareVersionString).arg(dateString);
|
||||
}
|
||||
|
||||
if (version > 0) {
|
||||
if (checkForUpdatesState & AUTOMATIC_DOWNLOAD) {
|
||||
checkForUpdatesState -= AUTOMATIC_DOWNLOAD;
|
||||
download = true;
|
||||
}
|
||||
else {
|
||||
int currentVersion = g.fwRev.get(current_firmware_variant.id);
|
||||
QString currentVersionString = index2version(currentVersion);
|
||||
|
||||
|
@ -492,6 +473,7 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||
QMessageBox::information(this, "Companion", tr("No updates available at this time."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ignore) {
|
||||
int res = QMessageBox::question(this, "Companion", tr("Ignore this release %1?").arg(versionString), QMessageBox::Yes | QMessageBox::No);
|
||||
|
@ -500,11 +482,7 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||
}
|
||||
}
|
||||
else if (download == true) {
|
||||
QString url = GetFirmwareVariant(current_firmware_variant.id).getFirmwareUrl();
|
||||
QString ext = url.mid(url.lastIndexOf("."));
|
||||
needRename = false;
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + current_firmware_variant.id + ext);
|
||||
startFirmwareDownload(url, filename);
|
||||
startFirmwareDownload();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -515,8 +493,17 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
|||
checkForUpdates();
|
||||
}
|
||||
|
||||
void MainWindow::startFirmwareDownload(QString url, QString filename)
|
||||
void MainWindow::startFirmwareDownload()
|
||||
{
|
||||
QString url = current_firmware_variant.getFirmwareUrl();
|
||||
QString ext = url.mid(url.lastIndexOf("."));
|
||||
QString defaultFilename = g.flashDir() + "/" + current_firmware_variant.id;
|
||||
if (g.profile[g.id()].renameFwFiles()) {
|
||||
defaultFilename += "-" + firmwareVersionString;
|
||||
}
|
||||
defaultFilename += ext;
|
||||
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), defaultFilename);
|
||||
if (!filename.isEmpty()) {
|
||||
g.profile[g.id()].fwName(filename);
|
||||
g.flashDir(QFileInfo(filename).dir().absolutePath());
|
||||
|
|
|
@ -64,6 +64,7 @@ QT_END_NAMESPACE
|
|||
#define CHECK_COMPANION 1
|
||||
#define CHECK_FIRMWARE 2
|
||||
#define SHOW_DIALOG_WAIT 4
|
||||
#define AUTOMATIC_DOWNLOAD 8
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
|
@ -76,14 +77,12 @@ class MainWindow : public QMainWindow
|
|||
MainWindow();
|
||||
|
||||
protected:
|
||||
void startFirmwareDownload(QString url, QString filename);
|
||||
void dowloadLastFirmwareUpdate();
|
||||
void startFirmwareDownload();
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
public slots:
|
||||
void downloadLatestFW(FirmwareVariant & firmware);
|
||||
|
||||
private slots:
|
||||
void openDocURL();
|
||||
|
||||
|
@ -209,8 +208,8 @@ class MainWindow : public QMainWindow
|
|||
|
||||
QString installer_fileName;
|
||||
downloadDialog * downloadDialog_forWait;
|
||||
bool needRename;
|
||||
unsigned int checkForUpdatesState;
|
||||
QString firmwareVersionString;
|
||||
|
||||
QNetworkAccessManager *networkManager;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue