From 8c55ce62b9e65533619870d1e5b72612a1a16406 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 16 Apr 2022 14:13:59 +0200 Subject: rbutil: Move bootloader file check to base class. Avoid constructing the bootloader file path in the caller. Pass filename list and mountpoint separately so it can directly fall back to the mountpoint. Change some functions to use references instead of creating temporary objects. Change-Id: I09c9d755553a32de3d02a42a8ce1fcb94f831b2a --- utils/rbutilqt/base/bootloaderinstallbase.cpp | 25 ++++++++++++++++--------- utils/rbutilqt/base/bootloaderinstallbase.h | 8 ++++---- utils/rbutilqt/gui/selectiveinstallwidget.cpp | 12 +----------- utils/rbutilqt/rbutilqt.cpp | 15 +++------------ 4 files changed, 24 insertions(+), 36 deletions(-) (limited to 'utils/rbutilqt') diff --git a/utils/rbutilqt/base/bootloaderinstallbase.cpp b/utils/rbutilqt/base/bootloaderinstallbase.cpp index 36a15c9e1a..b49a9b933b 100644 --- a/utils/rbutilqt/base/bootloaderinstallbase.cpp +++ b/utils/rbutilqt/base/bootloaderinstallbase.cpp @@ -203,21 +203,28 @@ void BootloaderInstallBase::checkRemount() //! @brief set list of possible bootloader files and pick the existing one. //! @param sl list of possible bootloader files. -void BootloaderInstallBase::setBlFile(QStringList sl) +void BootloaderInstallBase::setBlFile(const QString& mountpoint, const QStringList& sl) { - // figue which of the possible bootloader filenames is correct. - for(int a = 0; a < sl.size(); a++) { - if(!Utils::resolvePathCase(sl.at(a)).isEmpty()) { - m_blfile = sl.at(a); - } + if(sl.size() == 0) { + m_blfile = mountpoint; } - if(m_blfile.isEmpty() && sl.size() > 0) { - m_blfile = sl.at(0); + else { + for(int a = 0; a < sl.size(); a++) { + QString filename = mountpoint + sl.at(a); + if(!Utils::resolvePathCase(filename).isEmpty()) { + m_blfile = filename; + break; + } + } + // figue which of the possible bootloader filenames is correct. + if(m_blfile.isEmpty() && sl.size() > 0) { + m_blfile = mountpoint + sl.at(0); + } } } -bool BootloaderInstallBase::setOfFile(QString of, QStringList blfile) +bool BootloaderInstallBase::setOfFile(QString& of, const QStringList& blfile) { bool found = false; ArchiveUtil *util = nullptr; diff --git a/utils/rbutilqt/base/bootloaderinstallbase.h b/utils/rbutilqt/base/bootloaderinstallbase.h index 567b4e9093..32ca637288 100644 --- a/utils/rbutilqt/base/bootloaderinstallbase.h +++ b/utils/rbutilqt/base/bootloaderinstallbase.h @@ -55,17 +55,17 @@ class BootloaderInstallBase : public QObject bool backup(QString to); //! set the different filenames and paths - void setBlFile(QStringList f); + void setBlFile(const QString& mountpoint, const QStringList& f); void setBlUrl(QUrl u) { m_blurl = u; } - void setLogfile(QString f) + void setLogfile(const QString& f) { m_logfile = f; } - bool setOfFile(QString of, QStringList blfile); + bool setOfFile(QString& of, const QStringList& blfile); //! returns a port Install Hint or empty if there is none //! static and in the base class, so the installer classes dont need to // be modified for new targets - static QString postinstallHints(QString model); + static QString postinstallHints(const QString& model); protected slots: void downloadBlFinish(QNetworkReply::NetworkError error); diff --git a/utils/rbutilqt/gui/selectiveinstallwidget.cpp b/utils/rbutilqt/gui/selectiveinstallwidget.cpp index 4417a52a29..7ee7498d64 100644 --- a/utils/rbutilqt/gui/selectiveinstallwidget.cpp +++ b/utils/rbutilqt/gui/selectiveinstallwidget.cpp @@ -308,17 +308,7 @@ void SelectiveInstallWidget::installBootloader(void) // set bootloader filename. Do this now as installed() needs it. QStringList blfile = PlayerBuildInfo::instance()->value( PlayerBuildInfo::BootloaderFile).toStringList(); - QStringList blfilepath; - for(int a = 0; a < blfile.size(); a++) { - blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString() - + blfile.at(a)); - } - // on devices without a bootloader file we use the mointpoint. The - // installer will use that to determine the correct device. - if(blfile.isEmpty()) { - blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()); - } - bl->setBlFile(blfilepath); + bl->setBlFile(RbSettings::value(RbSettings::Mountpoint).toString(), blfile); QUrl url(PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderUrl).toString() + PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderName).toString()); bl->setBlUrl(url); diff --git a/utils/rbutilqt/rbutilqt.cpp b/utils/rbutilqt/rbutilqt.cpp index f3b12c63af..f5872f268e 100644 --- a/utils/rbutilqt/rbutilqt.cpp +++ b/utils/rbutilqt/rbutilqt.cpp @@ -507,18 +507,9 @@ void RbUtilQt::uninstallBootloader(void) logger->setFinished(); return; } - QStringList blfile = PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderFile).toStringList(); - QStringList blfilepath; - for(int a = 0; a < blfile.size(); a++) { - blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString() - + blfile.at(a)); - } - // on devices without a bootloader file we use the mointpoint. The - // installer will use that to determine the correct device. - if(blfile.isEmpty()) { - blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()); - } - bl->setBlFile(blfilepath); + QStringList blfile = PlayerBuildInfo::instance()->value( + PlayerBuildInfo::BootloaderFile).toStringList(); + bl->setBlFile(RbSettings::value(RbSettings::Mountpoint).toString(), blfile); bl->setLogfile(RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox/rbutil.log"); -- cgit v1.2.3