fix(cpn): multi protocol and sd card updates (#4774)

This commit is contained in:
Neil Horne
2024-03-24 11:29:13 +10:00
committed by GitHub
parent dea0eb2d5a
commit 8adca4c041
5 changed files with 29 additions and 6 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ Repo::~Repo()
bool Repo::getJson(const QString filename, QJsonDocument * json)
{
m_network->downloadJson(m_releases->urlContent(filename), json);
m_network->downloadJsonContent(m_releases->urlContent(filename), json);
if (!m_network->isSuccess()) {
m_status->reportProgress("Unable to download json data", QtDebugMsg);
+1 -1
View File
@@ -153,7 +153,7 @@ void RepoAssets::dumpItemModel(const QString modelName, const QAbstractItemModel
bool RepoAssets::getJson(QJsonDocument * json)
{
network()->downloadJson(urlAsset(id()), json);
network()->downloadJsonAsset(urlAsset(id()), json);
if (!network()->isSuccess()) {
status()->reportProgress("Unable to download json data", QtDebugMsg);
@@ -25,7 +25,7 @@ UpdateMultiProtocol::UpdateMultiProtocol(QWidget * parent) :
UpdateInterface(parent, CID_MultiProtocol, tr("Multiprotocol"))
{
// GitHub REST API default ResultsPerPage = 30
init(QString(GH_API_REPOS).append("/pascallanger/DIY-Multiprotocol-TX-Module"), "", 50);
init(QString(GH_API_REPOS).append("/pascallanger/DIY-Multiprotocol-TX-Module"), "", 100);
}
void UpdateMultiProtocol::assetSettingsInit()
+23 -3
View File
@@ -26,9 +26,9 @@
#include <QtNetwork/QNetworkProxyFactory>
constexpr char GH_API_VERSION[] {"2022-11-28"};
constexpr char GH_ACCEPT_HEADER_CONTENT[] {"application/octet-stream"};
constexpr char GH_ACCEPT_HEADER_CONTENT[] {"application/octet-stream"};
constexpr char GH_ACCEPT_HEADER_METADATA[] {"application/vnd.github+json"};
// constexpr char GH_ACCEPT_HEADER_RAW[] {"application/vnd.github.raw"};
constexpr char GH_ACCEPT_HEADER_RAW[] {"application/vnd.github.raw+json"};
UpdateNetwork::UpdateNetwork(QObject * parent, UpdateStatus * status) :
QObject(parent),
@@ -59,6 +59,8 @@ QString UpdateNetwork::downloadDataTypeToString(const DownloadDataType val)
return "Content";
case DDT_MetaData:
return "Meta Data";
case DDT_Raw:
return "Raw";
default:
return CPN_STR_UNKNOWN_ITEM;
}
@@ -78,10 +80,28 @@ void UpdateNetwork::downloadJson(const QString & url, QJsonDocument * json)
convertBufferToJson(json);
}
void UpdateNetwork::downloadJsonAsset(const QString & url, QJsonDocument * json)
{
downloadToBuffer(DDT_Content, url);
if (m_success)
convertBufferToJson(json);
}
void UpdateNetwork::downloadJsonContent(const QString & url, QJsonDocument * json)
{
downloadToBuffer(DDT_Raw, url);
if (m_success)
convertBufferToJson(json);
}
void UpdateNetwork::downloadToBuffer(const DownloadDataType type, const QString & url)
{
m_success = false;
download(type, url, type == DDT_MetaData ? GH_ACCEPT_HEADER_METADATA : GH_ACCEPT_HEADER_CONTENT, QString());
download(type,
url,
type == DDT_MetaData ? GH_ACCEPT_HEADER_METADATA :
type == DDT_Raw ? GH_ACCEPT_HEADER_RAW : GH_ACCEPT_HEADER_CONTENT,
QString());
}
void UpdateNetwork::downloadToFile(const QString & url, const QString & filePath)
+3
View File
@@ -39,6 +39,7 @@ class UpdateNetwork : public QObject
DDT_Content,
DDT_SaveToFile,
DDT_MetaData,
DDT_Raw,
};
Q_ENUM(DownloadDataType)
@@ -48,6 +49,8 @@ class UpdateNetwork : public QObject
void convertBufferToJson(QJsonDocument * json);
void downloadMetaData(const QString & url, QJsonDocument * json);
void downloadJson(const QString & url, QJsonDocument * json);
void downloadJsonAsset(const QString & url, QJsonDocument * json);
void downloadJsonContent(const QString & url, QJsonDocument * json);
void downloadToFile(const QString & url, const QString & filePath);
void downloadToBuffer(const DownloadDataType type, const QString & url);
void download(const DownloadDataType type, const QString & urlStr, const char * header, const QString & filePath);