-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Skeleton implementation for user data backup * Get flipper file tree * Support file names with spaces * Working implementation of backup save * Skeleton implementation of backup restore * Working implementation of backup restore
- Loading branch information
Showing
22 changed files
with
716 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <QList> | ||
#include <QByteArray> | ||
|
||
enum class FileType { | ||
Directory, | ||
RegularFile, | ||
Storage, | ||
Unknown | ||
}; | ||
|
||
struct FileInfo { | ||
QByteArray name; | ||
QByteArray absolutePath; | ||
FileType type; | ||
qint64 size; | ||
}; | ||
|
||
using FileInfoList = QList<FileInfo>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "getfiletreeoperation.h" | ||
|
||
#include <QTimer> | ||
|
||
#include "flipperzero/flipperzero.h" | ||
#include "flipperzero/storagecontroller.h" | ||
#include "flipperzero/storage/listoperation.h" | ||
|
||
#include "macros.h" | ||
|
||
using namespace Flipper; | ||
using namespace Zero; | ||
|
||
GetFileTreeOperation::GetFileTreeOperation(FlipperZero *device, const QByteArray &rootPath, QObject *parent): | ||
Operation(device, parent), | ||
m_rootPath(rootPath), | ||
m_pendingCount(0) | ||
{} | ||
|
||
const QString GetFileTreeOperation::description() const | ||
{ | ||
return QStringLiteral("Get File Tree @%1").arg(QString(m_rootPath)); | ||
} | ||
|
||
const FileInfoList &GetFileTreeOperation::result() const | ||
{ | ||
return m_result; | ||
} | ||
|
||
void GetFileTreeOperation::transitionToNextState() | ||
{ | ||
if(state() == BasicState::Ready) { | ||
setState(State::Running); | ||
listDirectory(m_rootPath); | ||
|
||
} else if(state() == State::Running) { | ||
--m_pendingCount; | ||
auto *op = qobject_cast<ListOperation*>(sender()); | ||
|
||
if(op->isError()) { | ||
finishWithError(op->errorString()); | ||
return; | ||
} | ||
|
||
for(const auto &fileInfo : qAsConst(op->result())) { | ||
if(fileInfo.type == FileType::Directory) { | ||
listDirectory(fileInfo.absolutePath); | ||
} | ||
|
||
m_result.push_back(fileInfo); | ||
} | ||
|
||
op->deleteLater(); | ||
|
||
if(!m_pendingCount) { | ||
finish(); | ||
} | ||
} | ||
} | ||
|
||
void GetFileTreeOperation::listDirectory(const QByteArray &path) | ||
{ | ||
++m_pendingCount; | ||
auto *op = device()->storage()->list(path); | ||
connect(op, &AbstractOperation::finished, this, &GetFileTreeOperation::transitionToNextState); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include "flipperzerooperation.h" | ||
#include "fileinfo.h" | ||
|
||
class QSerialPort; | ||
|
||
namespace Flipper { | ||
namespace Zero { | ||
|
||
class GetFileTreeOperation : public Operation | ||
{ | ||
Q_OBJECT | ||
|
||
enum State { | ||
Running = BasicState::User | ||
}; | ||
|
||
public: | ||
GetFileTreeOperation(FlipperZero *device, const QByteArray &rootPath, QObject *parent = nullptr); | ||
const QString description() const override; | ||
const FileInfoList &result() const; | ||
|
||
private slots: | ||
void transitionToNextState() override; | ||
|
||
private: | ||
void listDirectory(const QByteArray &path); | ||
|
||
QByteArray m_rootPath; | ||
QByteArray m_currentPath; | ||
FileInfoList m_result; | ||
int m_pendingCount; | ||
}; | ||
|
||
} | ||
} |
Oops, something went wrong.