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
This commit is contained in:
Aidan MacDonald 2021-12-29 00:26:47 +00:00
parent 42999913ba
commit cbb57fe714
6 changed files with 44 additions and 22 deletions

View file

@ -67,8 +67,6 @@ class BootloaderInstallBase : public QObject
// be modified for new targets // be modified for new targets
static QString postinstallHints(QString model); static QString postinstallHints(QString model);
//! returns the correct BootloaderInstaller object for the requested type
static BootloaderInstallBase* createBootloaderInstaller(QObject* parent,QString type);
protected slots: protected slots:
void downloadReqFinished(int id, bool error); void downloadReqFinished(int id, bool error);
void downloadBlFinish(bool error); void downloadBlFinish(bool error);

View file

@ -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. //! @brief Return post install hints string.
//! @param model model string //! @param model model string

View file

@ -29,6 +29,7 @@ class BootloaderInstallHelper : public QObject
Q_OBJECT Q_OBJECT
public: public:
static BootloaderInstallBase* createBootloaderInstaller(QObject* parent, QString type); static BootloaderInstallBase* createBootloaderInstaller(QObject* parent, QString type);
static BootloaderInstallBase::Capabilities bootloaderInstallerCapabilities(QObject *parent, QString type);
static QString postinstallHints(QString model); static QString postinstallHints(QString model);
}; };

View file

@ -28,10 +28,6 @@
BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent) BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent)
: BootloaderInstallBase(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) 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) { if(ipod.sectorbuf == nullptr) {
emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR); emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR);
emit done(true); emit done(true);
return false; return false;
} }
// save buffer pointer before cleaning up ipod_t structure // save buffer pointer before cleaning up ipod_t structure
unsigned char* sb = ipod.sectorbuf; unsigned char* sb = ipod.sectorbuf;
memset(&ipod, 0, sizeof(struct ipod_t)); memset(&ipod, 0, sizeof(struct ipod_t));

View file

@ -27,10 +27,6 @@
BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent) BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent)
: BootloaderInstallBase(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) 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) { if(sansa.sectorbuf == nullptr) {
emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR); emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR);
return false; return false;

View file

@ -359,16 +359,14 @@ void RbUtilQt::updateSettings()
void RbUtilQt::updateDevice() void RbUtilQt::updateDevice()
{ {
/* TODO: We should check the flags of the bootloaderinstall classes, and not PlayerBuildInfo* playerBuildInfo = PlayerBuildInfo::instance();
* just check if its != none or != "fwpatcher" */
/* Enable bootloader installation, if possible */ BootloaderInstallBase::Capabilities bootloaderCapabilities =
bool bootloaderInstallable = BootloaderInstallHelper::bootloaderInstallerCapabilities(this,
PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderMethod).toString() != "none"; playerBuildInfo->value(PlayerBuildInfo::BootloaderMethod).toString());
/* Enable bootloader uninstallation, if possible */ /* Disable uninstallation actions if they are not supported. */
bool bootloaderUninstallable = bootloaderInstallable && bool bootloaderUninstallable = !(bootloaderCapabilities & BootloaderInstallBase::Uninstall);
PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderMethod) != "fwpatcher";
ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable); ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable); ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable); ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
@ -379,11 +377,11 @@ void RbUtilQt::updateDevice()
ui.menuA_ctions->setEnabled(configurationValid); ui.menuA_ctions->setEnabled(configurationValid);
// displayed device info // displayed device info
QString brand = PlayerBuildInfo::instance()->value(PlayerBuildInfo::Brand).toString(); QString brand = playerBuildInfo->value(PlayerBuildInfo::Brand).toString();
QString name QString name
= QString("%1 (%2)").arg( = QString("%1 (%2)").arg(
PlayerBuildInfo::instance()->value(PlayerBuildInfo::DisplayName).toString(), playerBuildInfo->value(PlayerBuildInfo::DisplayName).toString(),
PlayerBuildInfo::instance()->statusAsString()); playerBuildInfo->statusAsString());
ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name)); ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name));
QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString(); QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
@ -398,7 +396,7 @@ void RbUtilQt::updateDevice()
} }
QPixmap pm; 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.load(":/icons/players/" + m + "-small.png");
pm = pm.scaledToHeight(QFontMetrics(QApplication::font()).height() * 3); pm = pm.scaledToHeight(QFontMetrics(QApplication::font()).height() * 3);
ui.labelPlayerPic->setPixmap(pm); ui.labelPlayerPic->setPixmap(pm);