From 01fcfec95a52c1b28aaeaaeebd4b89375ee738eb Mon Sep 17 00:00:00 2001 From: Georgii Surkov Date: Mon, 27 Mar 2023 12:51:38 +0300 Subject: [PATCH] Simplify update bundle handling --- .../toplevel/fullupdateoperation.cpp | 38 +++++-------------- .../toplevel/fullupdateoperation.h | 2 - 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/backend/flipperzero/toplevel/fullupdateoperation.cpp b/backend/flipperzero/toplevel/fullupdateoperation.cpp index e81f1435..5945834e 100644 --- a/backend/flipperzero/toplevel/fullupdateoperation.cpp +++ b/backend/flipperzero/toplevel/fullupdateoperation.cpp @@ -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(); @@ -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; -} diff --git a/backend/flipperzero/toplevel/fullupdateoperation.h b/backend/flipperzero/toplevel/fullupdateoperation.h index f722eabf..27fdf7ff 100644 --- a/backend/flipperzero/toplevel/fullupdateoperation.h +++ b/backend/flipperzero/toplevel/fullupdateoperation.h @@ -53,8 +53,6 @@ private slots: void uploadUpdateFiles(); void startUpdate(); - bool findAndCdToUpdateDir(); - QFile *m_updateFile; QDir m_updateDirectory; QList m_fileUrls;