From df5722717a4ed7252b205e20e7823018a8267863 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Mon, 16 Jul 2018 17:36:33 -0400 Subject: [PATCH] [Companion] Centralize download URLs; URLs now based on build major.minor version macros; Remove AVR fw download URL; Make some QStrings cheaper. --- .../src/firmwares/opentx/opentxinterface.cpp | 31 +++++------------- companion/src/fwpreferencesdialog.cpp | 8 +---- companion/src/mainwindow.cpp | 32 ++++++++----------- companion/src/mainwindow.h | 4 +-- companion/src/storage/appdata.h | 18 +++++++++-- 5 files changed, 40 insertions(+), 53 deletions(-) diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index f07704994..8a33a926d 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -23,19 +23,13 @@ #include "rlefile.h" #include "appdata.h" #include "constants.h" + #include #include #include #include -#include -using namespace Board; - -const char * const OPENTX_FIRMWARE_DOWNLOAD_URL[] = { - "https://downloads.open-tx.org/2.2/release/firmware", - "https://downloads.open-tx.org/2.2/rc/firmware", - "https://downloads.open-tx.org/2.2/nightlies/firmware" -}; +#include "storage.h" // does this need to be last include? #define FILE_TYP_GENERAL 1 #define FILE_TYP_MODEL 2 @@ -45,6 +39,8 @@ const char * const OPENTX_FIRMWARE_DOWNLOAD_URL[] = { /// convert model number 0..MAX_MODELS-1 int fileId #define FILE_MODEL(n) (1+n) +using namespace Board; + template inline size_t SizeOfArray(T(&)[N]) @@ -1045,33 +1041,22 @@ unsigned long OpenTxEepromInterface::loadBackup(RadioData &radioData, const uint QString OpenTxFirmware::getFirmwareBaseUrl() { - return OPENTX_FIRMWARE_DOWNLOAD_URL[g.boundedOpenTxBranch()]; + return g.openTxCurrentDownloadBranchUrl() % QStringLiteral("firmware/"); } QString OpenTxFirmware::getFirmwareUrl() { - QString url = getFirmwareBaseUrl(); - QByteArray data = QUrl::toPercentEncoding(id); - - if (IS_ARM(board)) - url.append(QString("/getfw.php?fw=%1.bin").arg((QString) data)); - else - url.append(QString("/getfw.php?fw=%1.hex").arg((QString) data)); - return url; + return getFirmwareBaseUrl() % QString("getfw.php?fw=%1.bin").arg(QString(QUrl::toPercentEncoding(id))); } QString OpenTxFirmware::getReleaseNotesUrl() { - QString url = getFirmwareBaseUrl(); - url.append("/releasenotes.txt"); - return url; + return getFirmwareBaseUrl() % QStringLiteral("releasenotes.txt"); } QString OpenTxFirmware::getStampUrl() { - QString url = getFirmwareBaseUrl(); - url.append("/stamp-opentx.txt"); - return url; + return getFirmwareBaseUrl() % QStringLiteral("stamp-opentx.txt"); } void addOpenTxCommonOptions(OpenTxFirmware * firmware) diff --git a/companion/src/fwpreferencesdialog.cpp b/companion/src/fwpreferencesdialog.cpp index ebfc5b9df..dd0a2f20d 100644 --- a/companion/src/fwpreferencesdialog.cpp +++ b/companion/src/fwpreferencesdialog.cpp @@ -24,12 +24,6 @@ #include "helpers.h" #include "appdata.h" -const char * const OPENTX_SDCARD_DOWNLOAD_URL[] = { - "https://downloads.open-tx.org/2.2/release/sdcard/", - "https://downloads.open-tx.org/2.2/rc/sdcard/", - "https://downloads.open-tx.org/2.2/nightlies/sdcard/" -}; - FirmwarePreferencesDialog::FirmwarePreferencesDialog(QWidget * parent) : QDialog(parent), ui(new Ui::FirmwarePreferencesDialog) @@ -69,7 +63,7 @@ void FirmwarePreferencesDialog::on_fw_dnld_clicked() void FirmwarePreferencesDialog::on_sd_dnld_clicked() { - QString url = OPENTX_SDCARD_DOWNLOAD_URL[g.boundedOpenTxBranch()]; + QString url = g.openTxCurrentDownloadBranchUrl() % QStringLiteral("sdcard/"); QString fwType = g.profile[g.id()].fwType(); QStringList list = fwType.split("-"); QString firmware = QString("%1-%2").arg(list[0]).arg(list[1]); diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index deff0aa3c..00d50647f 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -61,32 +61,26 @@ #define INTERACTIVE_DOWNLOAD 4 #define AUTOMATIC_DOWNLOAD 8 -#define OPENTX_DOWNLOADS_PAGE_URL "http://www.open-tx.org/downloads" -#define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2" +#define OPENTX_DOWNLOADS_PAGE_URL QStringLiteral("http://www.open-tx.org/downloads") +#define DONATE_STR QStringLiteral("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2") #ifdef Q_OS_MACOS - #define COMPANION_STAMP "companion-macosx.stamp" - #define COMPANION_INSTALLER "macosx/opentx-companion-%1.dmg" + #define COMPANION_STAMP QStringLiteral("companion-macosx.stamp") + #define COMPANION_INSTALLER QStringLiteral("macosx/opentx-companion-%1.dmg") #define COMPANION_FILEMASK QT_TRANSLATE_NOOP("MainWindow", "Diskimage (*.dmg)") #define COMPANION_INSTALL_QUESTION QT_TRANSLATE_NOOP("MainWindow", "Would you like to open the disk image to install the new version?") #elif defined(Q_OS_WIN) - #define COMPANION_STAMP "companion-windows.stamp" - #define COMPANION_INSTALLER "windows/companion-windows-%1.exe" + #define COMPANION_STAMP QStringLiteral("companion-windows.stamp") + #define COMPANION_INSTALLER QStringLiteral("windows/companion-windows-%1.exe") #define COMPANION_FILEMASK QT_TRANSLATE_NOOP("MainWindow", "Executable (*.exe)") #define COMPANION_INSTALL_QUESTION QT_TRANSLATE_NOOP("MainWindow", "Would you like to launch the installer?") #else - #define COMPANION_STAMP "companion-linux.stamp" + #define COMPANION_STAMP QStringLiteral("companion-linux.stamp") #define COMPANION_INSTALLER "" // no automated updates for linux - #define COMPANION_FILEMASK "*.*" + #define COMPANION_FILEMASK QStringLiteral("*.*") #define COMPANION_INSTALL_QUESTION QT_TRANSLATE_NOOP("MainWindow", "Would you like to launch the installer?") #endif -const char * const OPENTX_COMPANION_DOWNLOAD_URL[] = { - "https://downloads.open-tx.org/2.2/release/companion", - "https://downloads.open-tx.org/2.2/rc/companion", - "https://downloads.open-tx.org/2.2/nightlies/companion" -}; - MainWindow::MainWindow(): downloadDialog_forWait(nullptr), checkForUpdatesState(0), @@ -260,9 +254,9 @@ void MainWindow::dowloadLastFirmwareUpdate() checkForUpdates(); } -QString MainWindow::getCompanionUpdateBaseUrl() +QString MainWindow::getCompanionUpdateBaseUrl() const { - return OPENTX_COMPANION_DOWNLOAD_URL[g.boundedOpenTxBranch()]; + return g.openTxCurrentDownloadBranchUrl() % QStringLiteral("companion/"); } void MainWindow::checkForUpdates() @@ -286,7 +280,7 @@ void MainWindow::checkForUpdates() checkForUpdatesState -= CHECK_COMPANION; if (checkForUpdatesState & INTERACTIVE_DOWNLOAD) openUpdatesWaitDialog(); - url.setUrl(QString("%1/%2").arg(getCompanionUpdateBaseUrl()).arg(COMPANION_STAMP)); + url.setUrl(getCompanionUpdateBaseUrl() % COMPANION_STAMP); connect(networkManager, &QNetworkAccessManager::finished, this, &MainWindow::checkForCompanionUpdateFinished); qDebug() << "Checking for Companion update " << url.url(); } @@ -334,7 +328,7 @@ void MainWindow::closeUpdatesWaitDialog() } } -QString MainWindow::seekCodeString(const QByteArray & qba, const QString & label) +QString MainWindow::seekCodeString(const QByteArray & qba, const QString & label) const { int posLabel = qba.indexOf(label); if (posLabel < 0) @@ -374,7 +368,7 @@ void MainWindow::checkForCompanionUpdateFinished(QNetworkReply * reply) if (!fileName.isEmpty()) { g.updatesDir(QFileInfo(fileName).dir().absolutePath()); - downloadDialog * dd = new downloadDialog(this, QString("%1/%2").arg(getCompanionUpdateBaseUrl()).arg(QString(COMPANION_INSTALLER).arg(version)), fileName); + downloadDialog * dd = new downloadDialog(this, getCompanionUpdateBaseUrl() % QString(COMPANION_INSTALLER).arg(version), fileName); installer_fileName = fileName; connect(dd, SIGNAL(accepted()), this, SLOT(updateDownloaded())); dd->exec(); diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index 88680b848..cda66e163 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -52,8 +52,8 @@ class MainWindow : public QMainWindow void startSync(); protected: - QString getCompanionUpdateBaseUrl(); - QString seekCodeString(const QByteArray & qba, const QString & label); + QString getCompanionUpdateBaseUrl() const; + QString seekCodeString(const QByteArray & qba, const QString & label) const; protected slots: void dowloadLastFirmwareUpdate(); diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index b4020759f..c4a67c560 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -58,6 +58,12 @@ #define CPN_SETTINGS_INI_FILE QString(PRODUCT % " " % QCoreApplication::translate("Companion", "settings") % " %1.ini") #define CPN_SETTINGS_INI_PATH QString(CPN_SETTINGS_BACKUP_DIR % "/" % CPN_SETTINGS_INI_FILE) +#define CPN_URL_DOWNLOAD "https://downloads.open-tx.org/" +#define CPN_URL_DOWNLOAD_CUR_VERS CPN_URL_DOWNLOAD QT_STRINGIFY(VERSION_MAJOR) "." QT_STRINGIFY(VERSION_MINOR) "/" +#define CPN_URL_DOWNLOAD_CUR_REL CPN_URL_DOWNLOAD_CUR_VERS "release/" +#define CPN_URL_DOWNLOAD_CUR_RC CPN_URL_DOWNLOAD_CUR_VERS "rc/" +#define CPN_URL_DOWNLOAD_CUR_UNST CPN_URL_DOWNLOAD_CUR_VERS "nightlies/" + #define MAX_PROFILES 15 #define MAX_JOYSTICKS 8 @@ -490,12 +496,20 @@ class AppData: public CompStoreObj inline DownloadBranchType boundedOpenTxBranch() const { #if defined(ALLOW_NIGHTLY_BUILDS) - return qBound(BRANCH_RELEASE_STABLE, DownloadBranchType(OpenTxBranch()), BRANCH_NIGHTLY_UNSTABLE); + return qBound(BRANCH_RELEASE_STABLE, OpenTxBranch(), BRANCH_NIGHTLY_UNSTABLE); #else - return qBound(BRANCH_RELEASE_STABLE, DownloadBranchType(OpenTxBranch()), BRANCH_RC_TESTING); + return qBound(BRANCH_RELEASE_STABLE, OpenTxBranch(), BRANCH_RC_TESTING); #endif } + inline QString openTxCurrentDownloadBranchUrl() const { return openTxDownloadBranchUrl(boundedOpenTxBranch()); } + + static const QString openTxDownloadBranchUrl(DownloadBranchType type) + { + static const QStringList urlList({ CPN_URL_DOWNLOAD_CUR_REL, CPN_URL_DOWNLOAD_CUR_RC, CPN_URL_DOWNLOAD_CUR_UNST }); + return urlList.value(type, CPN_URL_DOWNLOAD_CUR_VERS); + } + Profile profile[MAX_PROFILES]; JStickData joystick[MAX_JOYSTICKS]; FwRevision fwRev;