[Companion] Centralize download URLs; URLs now based on build major.minor version macros; Remove AVR fw download URL; Make some QStrings cheaper.

This commit is contained in:
Max Paperno
2018-07-16 17:36:33 -04:00
parent 71c5132c57
commit df5722717a
5 changed files with 40 additions and 53 deletions
@@ -23,19 +23,13 @@
#include "rlefile.h"
#include "appdata.h"
#include "constants.h"
#include <bitset>
#include <QMessageBox>
#include <QTime>
#include <QUrl>
#include <companion/src/storage/storage.h>
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<typename T, size_t N>
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)
+1 -7
View File
@@ -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]);
+13 -19
View File
@@ -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();
+2 -2
View File
@@ -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();
+16 -2
View File
@@ -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;