Delay initialisation of fw flavour and language until update process runs
This commit is contained in:
@@ -39,7 +39,7 @@ UpdateFirmware::UpdateFirmware(QWidget * parent) :
|
||||
ap.flags = dfltParams->data.flags | UPDFLG_CopyFiles;
|
||||
ap.destSubDir = "FIRMWARE";
|
||||
ap.copyFilterType = UpdateParameters::UFT_Expression;
|
||||
ap.copyFilter = QString("^%1-.*\\.bin$").arg(fwFlavour);
|
||||
ap.copyFilter = QString("^%FWFLAVOUR%-.*\\.bin$");
|
||||
}
|
||||
|
||||
bool UpdateFirmware::asyncInstall()
|
||||
|
||||
@@ -61,6 +61,8 @@ UpdateParameters& UpdateParameters::operator=(const UpdateParameters& source)
|
||||
|
||||
if (this != &source) {
|
||||
data.flags = source.data.flags;
|
||||
data.fwFlavour = source.data.fwFlavour;
|
||||
data.language = source.data.language;
|
||||
data.currentRelease = source.data.currentRelease;
|
||||
data.updateRelease = source.data.updateRelease;
|
||||
data.downloadDir = source.data.downloadDir;
|
||||
@@ -94,10 +96,12 @@ UpdateParameters::AssetParams & UpdateParameters::addAsset()
|
||||
return data.assets[data.assets.size() - 1];
|
||||
}
|
||||
|
||||
// static
|
||||
QString UpdateParameters::buildFilterPattern(const UpdateParameters::UpdateFilterType filterType, const QString & filter)
|
||||
{
|
||||
QString pattern = filter;
|
||||
QString pattern(filter);
|
||||
|
||||
pattern.replace("%FWFLAVOUR%", data.fwFlavour);
|
||||
pattern.replace("%LANGUAGE%", data.language);
|
||||
|
||||
switch ((int)filterType) {
|
||||
case UpdateParameters::UFT_Exact:
|
||||
@@ -154,13 +158,9 @@ UpdateInterface::UpdateInterface(QWidget * parent) :
|
||||
dfltParams = new UpdateParameters(this);
|
||||
runParams = new UpdateParameters(this);
|
||||
|
||||
getRadioProfileSettings();
|
||||
|
||||
setReleasesNightlyName("");
|
||||
dfltParams->data.flags = UPDFLG_Common;
|
||||
resultsPerPage = -1;
|
||||
|
||||
initParamFolders(dfltParams);
|
||||
}
|
||||
|
||||
UpdateInterface::~UpdateInterface()
|
||||
@@ -381,6 +381,9 @@ void UpdateInterface::resetRunEnvironment()
|
||||
progress = nullptr;
|
||||
logLevel = g.updLogLevel();
|
||||
|
||||
initFlavourLanguage(dfltParams);
|
||||
initParamFolders(dfltParams);
|
||||
|
||||
*runParams = *dfltParams;
|
||||
runParams->data.flags &= ~UPDFLG_Update;
|
||||
|
||||
@@ -417,23 +420,26 @@ void UpdateInterface::setSettingsIdx()
|
||||
releases->setSettingsIndex(idx);
|
||||
}
|
||||
|
||||
void UpdateInterface::getRadioProfileSettings()
|
||||
void UpdateInterface::initFlavourLanguage(UpdateParameters * params)
|
||||
{
|
||||
// eg edgetx-ts16s-en
|
||||
QStringList strl = QStringList(g.currentProfile().fwType().split('-'));
|
||||
const Firmware * baseFw = getCurrentFirmware()->getFirmwareBase();
|
||||
const QStringList currVariant = getCurrentFirmware()->getId().split('-');
|
||||
|
||||
if (strl.size() < 1) {
|
||||
//reportProgress(tr("Settings radio profile firmware type unexpected format"), QtWarningMsg);
|
||||
return;
|
||||
params->data.fwFlavour = "";
|
||||
|
||||
if (currVariant.size() > 1) {
|
||||
params->data.fwFlavour = currVariant.at(1);
|
||||
params->data.fwFlavour = params->data.fwFlavour.replace('+', 'p');
|
||||
}
|
||||
|
||||
if (strl.size() > 1) {
|
||||
fwFlavour = strl.at(1);
|
||||
fwFlavour = fwFlavour.replace('+', 'p');
|
||||
}
|
||||
params->data.language = "";
|
||||
|
||||
if (strl.size() > 2)
|
||||
language = strl.at(2);
|
||||
for (const char *lang : baseFw->languageList()) {
|
||||
if (currVariant.last() == lang) {
|
||||
params->data.language = currVariant.last();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateInterface::clearRelease()
|
||||
@@ -818,20 +824,19 @@ bool UpdateInterface::convertDownloadToJson(QJsonDocument * json)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UpdateInterface::getSetAssets(const int flags, const UpdateParameters::UpdateFilterType assetsFilterType, const QString & assetsFilter, const int maxAssetsExpected,
|
||||
const QString & subDirectory, const UpdateParameters::UpdateFilterType copyFilterType, const QString & copyFilter)
|
||||
bool UpdateInterface::getSetAssets(const UpdateParameters::AssetParams & ap)
|
||||
{
|
||||
QString pattern(UpdateParameters::buildFilterPattern(assetsFilterType, assetsFilter));
|
||||
QString pattern(runParams->buildFilterPattern(ap.filterType, ap.filter));
|
||||
assets->setFilterPattern(pattern);
|
||||
//reportProgress(tr("Asset filter applied: %1").arg(pattern), QtDebugMsg);
|
||||
|
||||
if (assets->count() < 0) {
|
||||
reportProgress(tr("No assets not found in release '%1' using filter pattern '%2'").arg(releases->name().arg(assetsFilter)), QtCriticalMsg);
|
||||
reportProgress(tr("No assets not found in release '%1' using filter pattern '%2'").arg(releases->name().arg(pattern)), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
else if (maxAssetsExpected > -1 && assets->count() > maxAssetsExpected) {
|
||||
else if (ap.maxExpected > -1 && assets->count() > ap.maxExpected) {
|
||||
reportProgress(tr("%1 assets found when %2 expected in release '%3' using filter pattern '%4'")
|
||||
.arg(assets->count()).arg(maxAssetsExpected).arg(releases->name().arg(assetsFilter)), QtCriticalMsg);
|
||||
.arg(assets->count()).arg(ap.maxExpected).arg(releases->name().arg(pattern)), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -839,17 +844,17 @@ bool UpdateInterface::getSetAssets(const int flags, const UpdateParameters::Upda
|
||||
|
||||
for (int i = 0; i < assets->count(); i++) {
|
||||
assets->getSetId(i);
|
||||
if (!assets->setFlags(flags)) {
|
||||
if (!assets->setFlags(ap.flags)) {
|
||||
reportProgress(tr("Unable to set processing flags for asset %1").arg(assets->filename()), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!assets->setSubDirectory(subDirectory)) {
|
||||
if (!assets->setSubDirectory(ap.destSubDir)) {
|
||||
reportProgress(tr("Unable to set sub directory for asset %1").arg(assets->filename()), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!assets->setCopyFilter(UpdateParameters::buildFilterPattern(copyFilterType, copyFilter))) {
|
||||
if (!assets->setCopyFilter(runParams->buildFilterPattern(ap.copyFilterType, ap.copyFilter))) {
|
||||
reportProgress(tr("Unable to set copy filter for asset %1").arg(assets->filename()), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
@@ -914,8 +919,6 @@ void UpdateInterface::downloadBinaryToFile(const QString & url, const QString &
|
||||
download(DDT_SaveToFile, 0, url, GH_ACCEPT_HEADER_BINARY, f.absoluteFilePath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool UpdateInterface::decompressFlaggedAssets()
|
||||
{
|
||||
assets->setFilterFlags(UPDFLG_Decompress);
|
||||
@@ -1263,8 +1266,8 @@ bool UpdateInterface::flagAssets()
|
||||
progressMessage(tr("Flagging assets"));
|
||||
|
||||
for (int i = 0; i < runParams->data.assets.size(); i++) {
|
||||
const UpdateParameters::AssetParams &ap = runParams->data.assets.at(i);
|
||||
if (!getSetAssets(ap.flags, ap.filterType, ap.filter, ap.maxExpected, ap.destSubDir, ap.copyFilterType, ap.copyFilter))
|
||||
const UpdateParameters::AssetParams & ap = runParams->data.assets.at(i);
|
||||
if (!getSetAssets(ap))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ class UpdateParameters : public QWidget
|
||||
|
||||
struct GeneralParams{
|
||||
int flags;
|
||||
QString fwFlavour;
|
||||
QString language;
|
||||
QString currentRelease;
|
||||
QString updateRelease;
|
||||
QString downloadDir;
|
||||
@@ -76,7 +78,7 @@ class UpdateParameters : public QWidget
|
||||
virtual ~UpdateParameters() {}
|
||||
|
||||
AssetParams & addAsset();
|
||||
static QString buildFilterPattern(const UpdateFilterType filterType, const QString & filter);
|
||||
QString buildFilterPattern(const UpdateFilterType filterType, const QString & filter);
|
||||
|
||||
UpdateParameters& operator=(const UpdateParameters& source);
|
||||
};
|
||||
@@ -132,8 +134,6 @@ class UpdateInterface : public QWidget
|
||||
QString downloadDir;
|
||||
QString decompressDir;
|
||||
QString updateDir;
|
||||
QString fwFlavour;
|
||||
QString language;
|
||||
int logLevel;
|
||||
|
||||
virtual bool autoUpdate(ProgressWidget * progress = nullptr);
|
||||
@@ -179,9 +179,7 @@ class UpdateInterface : public QWidget
|
||||
|
||||
bool downloadReleaseAssetsMetaData(const int releaseId);
|
||||
bool downloadAssetMetaData(const int assetId);
|
||||
bool getSetAssets(const int flags, const UpdateParameters::UpdateFilterType assetFilterType, const QString & assetsFilter,
|
||||
const int maxAssetsExpected, const QString & subDirectory,
|
||||
const UpdateParameters::UpdateFilterType copyFilterType, const QString & copyFilter);
|
||||
bool getSetAssets(const UpdateParameters::AssetParams & ap);
|
||||
bool downloadAsset(int row);
|
||||
bool downloadFlaggedAssets();
|
||||
bool decompressAsset(int row);
|
||||
@@ -202,7 +200,7 @@ class UpdateInterface : public QWidget
|
||||
void criticalMsg(const QString & msg);
|
||||
static QString downloadDataTypeToString(DownloadDataType val);
|
||||
static QString updateFlagsToString(UpdateFlags val);
|
||||
void getRadioProfileSettings();
|
||||
void initFlavourLanguage(UpdateParameters * params);
|
||||
|
||||
private slots:
|
||||
void onDownloadFinished(QNetworkReply * reply, DownloadDataType ddt, int subtype);
|
||||
|
||||
@@ -33,7 +33,7 @@ UpdateSDCard::UpdateSDCard(QWidget * parent) :
|
||||
|
||||
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
|
||||
ap.filterType = UpdateParameters::UFT_Startswith;
|
||||
ap.filter = QString("%1-").arg(fwFlavour);
|
||||
ap.filter = QString("%FWFLAVOUR%-");
|
||||
ap.maxExpected = 1;
|
||||
ap.flags = dfltParams->data.flags | UPDFLG_CopyStructure;
|
||||
}
|
||||
@@ -60,9 +60,9 @@ bool UpdateSDCard::flagAssets()
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateParameters::AssetParams ap = runParams->data.assets.at(0);
|
||||
const UpdateParameters::AssetParams & ap = runParams->data.assets.at(0);
|
||||
|
||||
QRegularExpression filter(UpdateParameters::buildFilterPattern(ap.filterType, ap.filter), QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpression filter(runParams->buildFilterPattern(ap.filterType, ap.filter), QRegularExpression::CaseInsensitiveOption);
|
||||
bool found = false;
|
||||
QString sdimage;
|
||||
|
||||
@@ -89,13 +89,17 @@ bool UpdateSDCard::flagAssets()
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
reportProgress(tr("Radio flavour %1 not listed in %2").arg(fwFlavour).arg(mappingfile), QtCriticalMsg);
|
||||
reportProgress(tr("Radio flavour %1 not listed in %2").arg(runParams->data.fwFlavour).arg(mappingfile), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
delete json;
|
||||
|
||||
if (!getSetAssets(ap.flags, UpdateParameters::UFT_Startswith, sdimage, ap.maxExpected, ap.destSubDir, ap.copyFilterType, ap.copyFilter))
|
||||
UpdateParameters::AssetParams sd = ap;
|
||||
sd.filterType = UpdateParameters::UFT_Startswith;
|
||||
sd.filter = sdimage;
|
||||
|
||||
if (!getSetAssets(sd))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -46,7 +46,7 @@ UpdateSounds::UpdateSounds(QWidget * parent) :
|
||||
// only supports default for each language
|
||||
// eg edgetx-sdcard-sounds-en-2.7.0.zip
|
||||
ap.filterType = UpdateParameters::UFT_Startswith;
|
||||
ap.filter = QString("edgetx-sdcard-sounds-%1-").arg(language);
|
||||
ap.filter = QString("edgetx-sdcard-sounds-%LANGUAGE%-");
|
||||
// if user changes filter then more than one could be returned
|
||||
//ap.maxExpected = 1;
|
||||
ap.flags = dfltParams->data.flags | UPDFLG_CopyStructure;
|
||||
|
||||
Reference in New Issue
Block a user