diff --git a/application/screens/homescreen.qml b/application/screens/homescreen.qml index a4625d38..c352eb29 100644 --- a/application/screens/homescreen.qml +++ b/application/screens/homescreen.qml @@ -96,7 +96,6 @@ Item { delegate: FlipperListDelegate { onUpdateRequested: { const channelName = "release"; - const firmwareType = "full_dfu"; const latestVersion = firmwareUpdates.channel(channelName).latestVersion; const messageObj = { @@ -105,7 +104,7 @@ Item { }; confirmationDialog.openWithMessage(function() { - downloader.downloadRemoteFile(device, latestVersion.fileInfo(firmwareType, device.target)); + downloader.downloadRemoteFile(device, latestVersion); }, messageObj); } diff --git a/application/screens/versionscreen.qml b/application/screens/versionscreen.qml index 318b1fe7..a6a4d7b1 100644 --- a/application/screens/versionscreen.qml +++ b/application/screens/versionscreen.qml @@ -60,10 +60,7 @@ Item { delegate: VersionListDelegate { onInstallRequested: { screen.homeRequested(); - - const firmwareType = "full_dfu"; - const fileInfo = versionInfo.fileInfo(firmwareType, device.target); - downloader.downloadRemoteFile(screen.device, fileInfo); + downloader.downloadRemoteFile(screen.device, versionInfo); } onChangelogRequested: { diff --git a/backend/firmwaredownloader.cpp b/backend/firmwaredownloader.cpp index e21afd56..e56d0b9f 100644 --- a/backend/firmwaredownloader.cpp +++ b/backend/firmwaredownloader.cpp @@ -28,16 +28,17 @@ void FirmwareDownloader::downloadLocalFile(FlipperZero *device, const QString &f enqueueOperation(new Flipper::Zero::FirmwareDownloadOperation(device, file)); } -void FirmwareDownloader::downloadRemoteFile(FlipperZero *device, const Updates::FileInfo &fileInfo) +void FirmwareDownloader::downloadRemoteFile(FlipperZero *device, const Flipper::Updates::VersionInfo &versionInfo) { // TODO: Local cache on hard disk? + const auto fileInfo = versionInfo.fileInfo(QStringLiteral("full_dfu"), device->target()); + auto *fetcher = new RemoteFileFetcher(this); + auto *buf = new QBuffer(this); - connect(fetcher, &RemoteFileFetcher::finished, this, [=](const QByteArray &data) { - auto *buf = new QBuffer(this); + check_return_void(buf->open(QIODevice::ReadWrite), "Failed to create intermediate buffer."); - buf->open(QIODevice::ReadWrite); - buf->write(data); + connect(fetcher, &RemoteFileFetcher::finished, this, [=]() { buf->seek(0); buf->close(); @@ -47,7 +48,7 @@ void FirmwareDownloader::downloadRemoteFile(FlipperZero *device, const Updates:: }); device->setStatusMessage(tr("Fetching the update file...")); - fetcher->fetch(fileInfo); + fetcher->fetch(fileInfo, buf); } void FirmwareDownloader::downloadLocalFUS(FlipperZero *device, const QString &filePath) diff --git a/backend/firmwaredownloader.h b/backend/firmwaredownloader.h index 7edcc4b8..29e711f7 100644 --- a/backend/firmwaredownloader.h +++ b/backend/firmwaredownloader.h @@ -26,7 +26,7 @@ class FirmwareDownloader : public QObject public slots: void downloadLocalFile(Flipper::FlipperZero *device, const QString &filePath); - void downloadRemoteFile(Flipper::FlipperZero *device, const Flipper::Updates::FileInfo &fileInfo); + void downloadRemoteFile(Flipper::FlipperZero *device, const Flipper::Updates::VersionInfo &versionInfo); void downloadLocalFUS(Flipper::FlipperZero *device, const QString &filePath); void downloadLocalWirelessStack(Flipper::FlipperZero *device, const QString &filePath);