1
0
Fork 0
forked from len0rd/rockbox

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
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);

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.
//! @param model model string

View file

@ -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);
};

View file

@ -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));

View file

@ -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;

View file

@ -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("<b>%1 %2</b>").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);