Skip to content

Commit

Permalink
Simplify update bundle handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gsurkov committed Mar 27, 2023
1 parent 0bcc9ed commit 01fcfec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
38 changes: 9 additions & 29 deletions backend/flipperzero/toplevel/fullupdateoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,19 @@ void FullUpdateOperation::readUpdateFiles()
deviceState()->setStatusString(QStringLiteral("Reading firmware update ..."));
deviceState()->setProgress(-1.0);

if(!findAndCdToUpdateDir()) {
const auto subdirNames = m_updateDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
if(subdirNames.isEmpty()) {
finishWithError(BackendError::DataError, QStringLiteral("Cannot find update directory"));
return;
}

QDirIterator it(m_updateDirectory, QDirIterator::Subdirectories);
} else if(!m_updateDirectory.cd(subdirNames.first())) {
finishWithError(BackendError::DataError, QStringLiteral("Cannot enter update directory"));
return;
}

while(it.hasNext()) {
const QFileInfo fileInfo(it.next());
if(fileInfo.isFile()) {
m_fileUrls.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath()));
}
const auto fileNames = m_updateDirectory.entryList(QDir::Files);
for(const auto &fileName : fileNames) {
m_fileUrls.append(QUrl::fromLocalFile(m_updateDirectory.absoluteFilePath(fileName)));
}

advanceOperationState();
Expand Down Expand Up @@ -299,24 +300,3 @@ void FullUpdateOperation::startUpdate()
}
});
}

bool FullUpdateOperation::findAndCdToUpdateDir()
{
m_updateDirectory.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);

QDirIterator it(m_updateDirectory);

while(it.hasNext()) {
it.next();

const auto &fileInfo = it.fileInfo();
const auto fileName = fileInfo.fileName();

if(fileInfo.isDir()) {
m_updateDirectory.cd(fileName);
return true;
}
}

return false;
}
2 changes: 0 additions & 2 deletions backend/flipperzero/toplevel/fullupdateoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ private slots:
void uploadUpdateFiles();
void startUpdate();

bool findAndCdToUpdateDir();

QFile *m_updateFile;
QDir m_updateDirectory;
QList<QUrl> m_fileUrls;
Expand Down

0 comments on commit 01fcfec

Please sign in to comment.