From cbb57fe714b633cd5b91850eae9cfd326dee2eeb Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Wed, 29 Dec 2021 00:26:47 +0000 Subject: rbutil: allow checking bootloader installer capabilities Instead of checking for certain hardcoded strings, fetch the actual capability bitmask by instantiating an installer and querying it. Change-Id: I7883d9c1e90da37ee7c0189732ac626685adbfa1 --- utils/rbutilqt/base/bootloaderinstallbase.h | 2 -- utils/rbutilqt/base/bootloaderinstallhelper.cpp | 20 ++++++++++++++++++++ utils/rbutilqt/base/bootloaderinstallhelper.h | 1 + utils/rbutilqt/base/bootloaderinstallipod.cpp | 11 +++++++---- utils/rbutilqt/base/bootloaderinstallsansa.cpp | 10 ++++++---- utils/rbutilqt/rbutilqt.cpp | 22 ++++++++++------------ 6 files changed, 44 insertions(+), 22 deletions(-) (limited to 'utils/rbutilqt') diff --git a/utils/rbutilqt/base/bootloaderinstallbase.h b/utils/rbutilqt/base/bootloaderinstallbase.h index 9a216a632c..0d9423a06f 100644 --- a/utils/rbutilqt/base/bootloaderinstallbase.h +++ b/utils/rbutilqt/base/bootloaderinstallbase.h @@ -67,8 +67,6 @@ class BootloaderInstallBase : public QObject // be modified for new targets static QString postinstallHints(QString model); - //! returns the correct BootloaderInstaller object for the requested type - static BootloaderInstallBase* createBootloaderInstaller(QObject* parent,QString type); protected slots: void downloadReqFinished(int id, bool error); void downloadBlFinish(bool error); diff --git a/utils/rbutilqt/base/bootloaderinstallhelper.cpp b/utils/rbutilqt/base/bootloaderinstallhelper.cpp index c94ed29140..4a1b24883b 100644 --- a/utils/rbutilqt/base/bootloaderinstallhelper.cpp +++ b/utils/rbutilqt/base/bootloaderinstallhelper.cpp @@ -77,6 +77,26 @@ BootloaderInstallBase* BootloaderInstallHelper::createBootloaderInstaller(QObjec } } +BootloaderInstallBase::Capabilities + BootloaderInstallHelper::bootloaderInstallerCapabilities(QObject *parent, QString type) +{ + /* Note - this is a terrible pattern in general, but in this case + * it is a much simpler option to just allocate a class instance. + * This operation is rarely used, anyway. */ + + BootloaderInstallBase* bootloaderInstaller = + createBootloaderInstaller(parent, type); + + BootloaderInstallBase::Capabilities caps = BootloaderInstallBase::Capabilities(); + + if(bootloaderInstaller) { + caps = bootloaderInstaller->capabilities(); + delete bootloaderInstaller; + } + + return caps; +} + //! @brief Return post install hints string. //! @param model model string diff --git a/utils/rbutilqt/base/bootloaderinstallhelper.h b/utils/rbutilqt/base/bootloaderinstallhelper.h index c89444d7a7..9b6fed0866 100644 --- a/utils/rbutilqt/base/bootloaderinstallhelper.h +++ b/utils/rbutilqt/base/bootloaderinstallhelper.h @@ -29,6 +29,7 @@ class BootloaderInstallHelper : public QObject Q_OBJECT public: static BootloaderInstallBase* createBootloaderInstaller(QObject* parent, QString type); + static BootloaderInstallBase::Capabilities bootloaderInstallerCapabilities(QObject *parent, QString type); static QString postinstallHints(QString model); }; diff --git a/utils/rbutilqt/base/bootloaderinstallipod.cpp b/utils/rbutilqt/base/bootloaderinstallipod.cpp index f94813f99f..d08cc22339 100644 --- a/utils/rbutilqt/base/bootloaderinstallipod.cpp +++ b/utils/rbutilqt/base/bootloaderinstallipod.cpp @@ -28,10 +28,6 @@ BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent) : BootloaderInstallBase(parent) { - (void)parent; - // initialize sector buffer. The sector buffer is part of the ipod_t - // structure, so a second instance of this class will have its own buffer. - ipod_alloc_buffer(&ipod, BUFFER_SIZE); } @@ -45,11 +41,18 @@ BootloaderInstallIpod::~BootloaderInstallIpod() bool BootloaderInstallIpod::install(void) { + // initialize sector buffer. The sector buffer is part of the ipod_t + // structure, so a second instance of this class will have its own buffer. + if(ipod.sectorbuf == nullptr) { + ipod_alloc_buffer(&ipod, BUFFER_SIZE); + } + if(ipod.sectorbuf == nullptr) { emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR); emit done(true); return false; } + // save buffer pointer before cleaning up ipod_t structure unsigned char* sb = ipod.sectorbuf; memset(&ipod, 0, sizeof(struct ipod_t)); diff --git a/utils/rbutilqt/base/bootloaderinstallsansa.cpp b/utils/rbutilqt/base/bootloaderinstallsansa.cpp index d4a2799f73..568bb82afa 100644 --- a/utils/rbutilqt/base/bootloaderinstallsansa.cpp +++ b/utils/rbutilqt/base/bootloaderinstallsansa.cpp @@ -27,10 +27,6 @@ BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent) : BootloaderInstallBase(parent) { - (void)parent; - // initialize sector buffer. The sector buffer is part of the sansa_t - // structure, so a second instance of this class will have its own buffer. - sansa_alloc_buffer(&sansa, BUFFER_SIZE); } @@ -46,6 +42,12 @@ BootloaderInstallSansa::~BootloaderInstallSansa() */ bool BootloaderInstallSansa::install(void) { + // initialize sector buffer. The sector buffer is part of the sansa_t + // structure, so a second instance of this class will have its own buffer. + if(sansa.sectorbuf == nullptr) { + sansa_alloc_buffer(&sansa, BUFFER_SIZE); + } + if(sansa.sectorbuf == nullptr) { emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR); return false; diff --git a/utils/rbutilqt/rbutilqt.cpp b/utils/rbutilqt/rbutilqt.cpp index d0ff9f2799..aa405418be 100644 --- a/utils/rbutilqt/rbutilqt.cpp +++ b/utils/rbutilqt/rbutilqt.cpp @@ -359,16 +359,14 @@ void RbUtilQt::updateSettings() void RbUtilQt::updateDevice() { - /* TODO: We should check the flags of the bootloaderinstall classes, and not - * just check if its != none or != "fwpatcher" */ + PlayerBuildInfo* playerBuildInfo = PlayerBuildInfo::instance(); - /* Enable bootloader installation, if possible */ - bool bootloaderInstallable = - PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderMethod).toString() != "none"; + BootloaderInstallBase::Capabilities bootloaderCapabilities = + BootloaderInstallHelper::bootloaderInstallerCapabilities(this, + playerBuildInfo->value(PlayerBuildInfo::BootloaderMethod).toString()); - /* Enable bootloader uninstallation, if possible */ - bool bootloaderUninstallable = bootloaderInstallable && - PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderMethod) != "fwpatcher"; + /* Disable uninstallation actions if they are not supported. */ + bool bootloaderUninstallable = !(bootloaderCapabilities & BootloaderInstallBase::Uninstall); ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable); ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable); ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable); @@ -379,11 +377,11 @@ void RbUtilQt::updateDevice() ui.menuA_ctions->setEnabled(configurationValid); // displayed device info - QString brand = PlayerBuildInfo::instance()->value(PlayerBuildInfo::Brand).toString(); + QString brand = playerBuildInfo->value(PlayerBuildInfo::Brand).toString(); QString name = QString("%1 (%2)").arg( - PlayerBuildInfo::instance()->value(PlayerBuildInfo::DisplayName).toString(), - PlayerBuildInfo::instance()->statusAsString()); + playerBuildInfo->value(PlayerBuildInfo::DisplayName).toString(), + playerBuildInfo->statusAsString()); ui.labelDevice->setText(QString("%1 %2").arg(brand, name)); QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString(); @@ -398,7 +396,7 @@ void RbUtilQt::updateDevice() } QPixmap pm; - QString m = PlayerBuildInfo::instance()->value(PlayerBuildInfo::PlayerPicture).toString(); + QString m = playerBuildInfo->value(PlayerBuildInfo::PlayerPicture).toString(); pm.load(":/icons/players/" + m + "-small.png"); pm = pm.scaledToHeight(QFontMetrics(QApplication::font()).height() * 3); ui.labelPlayerPic->setPixmap(pm); -- cgit v1.2.3