Skip to content

Commit

Permalink
Assets delivery (#26)
Browse files Browse the repository at this point in the history
* Add GZipUncompressor class

* Add skeleton for TarFile class

* Add zlib develpment package to Dockerfile

* Tar archive parser & indexer

* Set native text rendering

* Skeleton framework for CLI storage interface

* Serial port commands cleanup

* Add Failable and MOTDSkipper classes

* MOTDSkipper is now an operation

* Add libgl-dev package to docker

* Remove unnecessary symlink in Docker

* Add remove operation

* Saving a lot of work

* GZipUncompressor cleanup & improvements

* Better manifest parsing, verification & debug

* Fix error while upgrading FUS

* Working file tree operations

* Add WriteOperation

* Improved correctness

* Add MkDir operation

* Revert to chunk-based read operation

* Working asset update from file

* Improved error handling

* Add message feedback

* Fix compilation on Windows
  • Loading branch information
gsurkov authored Sep 21, 2021
1 parent 352da9e commit dc46b8e
Show file tree
Hide file tree
Showing 56 changed files with 2,566 additions and 167 deletions.
5 changes: 2 additions & 3 deletions application/application.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "application.h"

#include <QFile>
#include <QLocale>
#include <QBuffer>
#include <QTranslator>
#include <QQmlContext>
#include <QStandardPaths>
#include <QQuickWindow>
#include <QtQuickControls2/QQuickStyle>

#include "qflipperbackend.h"
Expand Down Expand Up @@ -39,6 +37,7 @@ AppUpdater *Application::updater()

void Application::initStyles()
{
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
QQuickStyle::setStyle("Universal");
}

Expand Down
6 changes: 6 additions & 0 deletions application/components/FlipperListDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Item {
signal localUpdateRequested(var device)
signal localRadioUpdateRequested(var device)
signal localFUSUpdateRequested(var device)
signal localAssetsUpdateRequested(var device)

signal fixOptionBytesRequested(var device)
signal fixBootRequested(var device)
Expand Down Expand Up @@ -185,6 +186,11 @@ Item {
Menu {
title: qsTr("Expert options")

MenuItem {
text: qsTr("Update Databases...")
onTriggered: localAssetsUpdateRequested(device)
}

MenuItem {
text: qsTr("Update Wireless stack...")
onTriggered: localRadioUpdateRequested(device)
Expand Down
11 changes: 11 additions & 0 deletions application/screens/homescreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ Item {
}, messageObj);
}

onLocalAssetsUpdateRequested: {
const messageObj = {
title : qsTr("Update the databases?"),
subtitle : qsTr("This will install the databases from a file.")
};

fileDialog.openWithConfirmation(["Database files (*.tgz)", "All files (*)"], function() {
downloader.downloadAssets(device, fileDialog.fileUrl);
}, messageObj);
}

onLocalRadioUpdateRequested: {
const messageObj = {
title : qsTr("Update the wireless stack?"),
Expand Down
23 changes: 3 additions & 20 deletions backend/abstractoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

AbstractOperation::AbstractOperation(QObject *parent):
QObject(parent),
m_isError(false),
m_errorString(QStringLiteral("No error")),
m_timeout(new QTimer(this)),
m_state(BasicState::Ready)
{
Expand All @@ -22,34 +20,19 @@ int AbstractOperation::state() const
return m_state;
}

bool AbstractOperation::isError() const
{
return m_isError;
}

const QString &AbstractOperation::errorString() const
{
return m_errorString;
}

void AbstractOperation::onOperationTimeout()
{
finishWithError(QStringLiteral("Operation timeout (generic)."));
finishWithError(QStringLiteral("Operation timeout (generic)"));
}

void AbstractOperation::setState(int state)
{
m_state = state;
}

void AbstractOperation::finishWithError(const QString &errorString)
void AbstractOperation::finishWithError(const QString &errorMsg)
{
error_msg(errorString);

m_isError = true;
m_errorString = errorString;

setState(BasicState::Finished);
setError(errorMsg);
finish();
}

Expand Down
16 changes: 7 additions & 9 deletions backend/abstractoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

#include <QObject>

#include "failable.h"

class QTimer;

class AbstractOperation: public QObject {
class AbstractOperation: public QObject, public Failable
{
Q_OBJECT

public:
Expand All @@ -17,14 +20,11 @@ class AbstractOperation: public QObject {
explicit AbstractOperation(QObject *parent = nullptr);
virtual ~AbstractOperation() {}

virtual const QString name() const = 0;
virtual const QString description() const = 0;
virtual void start() = 0;
virtual void finish() = 0;

int state() const;
bool isError() const;
const QString &errorString() const;

signals:
void started();
void finished();
Expand All @@ -34,14 +34,12 @@ protected slots:

protected:
void setState(int state);
void finishWithError(const QString &errorString);
void finishWithError(const QString &errorMsg);

void startTimeout(int msec = 10000);
void startTimeout(int msec = 5000);
void stopTimeout();

private:
bool m_isError;
QString m_errorString;
QTimer *m_timeout;
int m_state;
};
43 changes: 43 additions & 0 deletions backend/abstractserialoperation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "abstractserialoperation.h"

#include <QTimer>
#include <QSerialPort>

#include "macros.h"

AbstractSerialOperation::AbstractSerialOperation(QSerialPort *serialPort, QObject *parent):
AbstractOperation(parent),
m_serialPort(serialPort)
{}

AbstractSerialOperation::~AbstractSerialOperation()
{}

void AbstractSerialOperation::start()
{
connect(m_serialPort, &QSerialPort::readyRead, this, &AbstractSerialOperation::onSerialPortReadyRead);
connect(m_serialPort, &QSerialPort::errorOccurred, this, &AbstractSerialOperation::onSerialPortError);

QTimer::singleShot(0, this, &AbstractSerialOperation::begin);
}

void AbstractSerialOperation::finish()
{
stopTimeout();
setState(BasicState::Finished);

disconnect(m_serialPort, &QSerialPort::readyRead, this, &AbstractSerialOperation::onSerialPortReadyRead);
disconnect(m_serialPort, &QSerialPort::errorOccurred, this, &AbstractSerialOperation::onSerialPortError);

emit finished();
}

QSerialPort *AbstractSerialOperation::serialPort() const
{
return m_serialPort;
}

void AbstractSerialOperation::onSerialPortError()
{
finishWithError(m_serialPort->errorString());
}
29 changes: 29 additions & 0 deletions backend/abstractserialoperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "abstractoperation.h"

class QSerialPort;

class AbstractSerialOperation : public AbstractOperation
{
Q_OBJECT

public:
AbstractSerialOperation(QSerialPort *serialPort, QObject *parent = nullptr);
virtual ~AbstractSerialOperation();

void start() override;
void finish() override;

protected:
QSerialPort *serialPort() const;

private slots:
virtual void onSerialPortReadyRead() = 0;
void onSerialPortError();

private:
virtual bool begin() = 0;

QSerialPort *m_serialPort;
};
30 changes: 30 additions & 0 deletions backend/backend.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,73 @@ include(../qflipper_common.pri)

SOURCES += \
abstractoperation.cpp \
abstractserialoperation.cpp \
deviceregistry.cpp \
filenode.cpp \
firmwaredownloader.cpp \
flipperupdates.cpp \
flipperzero/assetmanifest.cpp \
flipperzero/common/skipmotdoperation.cpp \
flipperzero/deviceinfofetcher.cpp \
flipperzero/factoryinfo.cpp \
flipperzero/flipperzero.cpp \
flipperzero/operations/assetsdownloadoperation.cpp \
flipperzero/operations/firmwaredownloadoperation.cpp \
flipperzero/operations/fixbootissuesoperation.cpp \
flipperzero/operations/fixoptionbytesoperation.cpp \
flipperzero/operations/flipperzerooperation.cpp \
flipperzero/operations/wirelessstackdownloadoperation.cpp \
flipperzero/recoverycontroller.cpp \
flipperzero/remotecontroller.cpp \
flipperzero/storage/mkdiroperation.cpp \
flipperzero/storage/readoperation.cpp \
flipperzero/storage/removeoperation.cpp \
flipperzero/storage/statoperation.cpp \
flipperzero/storage/writeoperation.cpp \
flipperzero/storagecontroller.cpp \
gzipuncompressor.cpp \
qflipperbackend.cpp \
remotefilefetcher.cpp \
serialfinder.cpp \
simpleserialoperation.cpp \
tararchive.cpp \
updateregistry.cpp

HEADERS += \
abstractoperation.h \
abstractserialoperation.h \
deviceregistry.h \
failable.h \
filenode.h \
firmwaredownloader.h \
flipperupdates.h \
flipperzero/assetmanifest.h \
flipperzero/common/skipmotdoperation.h \
flipperzero/deviceinfo.h \
flipperzero/deviceinfofetcher.h \
flipperzero/factoryinfo.h \
flipperzero/flipperzero.h \
flipperzero/operations/assetsdownloadoperation.h \
flipperzero/operations/firmwaredownloadoperation.h \
flipperzero/operations/fixbootissuesoperation.h \
flipperzero/operations/fixoptionbytesoperation.h \
flipperzero/operations/flipperzerooperation.h \
flipperzero/operations/wirelessstackdownloadoperation.h \
flipperzero/recoverycontroller.h \
flipperzero/remotecontroller.h \
flipperzero/storage/mkdiroperation.h \
flipperzero/storage/readoperation.h \
flipperzero/storage/removeoperation.h \
flipperzero/storage/statoperation.h \
flipperzero/storage/writeoperation.h \
flipperzero/storagecontroller.h \
gzipuncompressor.h \
qflipperbackend.h \
remotefilefetcher.h \
serialfinder.h \
signalingfailable.h \
simpleserialoperation.h \
tararchive.h \
updateregistry.h

unix|win32 {
Expand Down
1 change: 0 additions & 1 deletion backend/deviceregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void DeviceRegistry::insertDevice(const USBDeviceInfo &info)
if(info.vendorID() == FLIPPER_ZERO_VID) {
auto *fetcher = Zero::AbstractDeviceInfoFetcher::create(info, this);
connect(fetcher, &Zero::AbstractDeviceInfoFetcher::finished, this, &DeviceRegistry::processDevice);
fetcher->fetch();

} else {
error_msg("Unexpected device VID and PID.");
Expand Down
28 changes: 28 additions & 0 deletions backend/failable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <QString>

class Failable
{
bool m_isError;
QString m_errorString;

public:
Failable() {
resetError();
}

bool isError() const { return m_isError; }
const QString &errorString() const { return m_errorString; }

virtual void setError(const QString &errorMessage) {
m_isError = true;
m_errorString = errorMessage;
}

void resetError() {
m_isError = false;
m_errorString = QStringLiteral("No Error");
}
};

Loading

0 comments on commit dc46b8e

Please sign in to comment.