2008-09-28 17:02:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Dominik Riebeling
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include "bootloaderinstallfile.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
BootloaderInstallFile::BootloaderInstallFile(QObject *parent)
|
|
|
|
: BootloaderInstallBase(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BootloaderInstallFile::install(void)
|
|
|
|
{
|
|
|
|
emit logItem(tr("Downloading bootloader"), LOGINFO);
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallFile] installing bootloader";
|
2008-09-28 17:02:36 +00:00
|
|
|
downloadBlStart(m_blurl);
|
|
|
|
connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BootloaderInstallFile::installStage2(void)
|
|
|
|
{
|
|
|
|
emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
|
2009-01-08 17:16:53 +00:00
|
|
|
QCoreApplication::processEvents();
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
// if an old bootloader is present (Gigabeat) move it out of the way.
|
2010-04-02 21:24:19 +00:00
|
|
|
QString fwfile(Utils::resolvePathCase(m_blfile));
|
2008-09-28 17:02:36 +00:00
|
|
|
if(!fwfile.isEmpty()) {
|
2010-04-02 21:24:19 +00:00
|
|
|
QString moved = Utils::resolvePathCase(m_blfile) + ".ORIG";
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallFile] renaming" << fwfile << "to" << moved;
|
2008-09-28 17:02:36 +00:00
|
|
|
QFile::rename(fwfile, moved);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no old file found resolve path without basename
|
|
|
|
QFileInfo fi(m_blfile);
|
2010-04-02 21:24:19 +00:00
|
|
|
QString absPath = Utils::resolvePathCase(fi.absolutePath());
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
// if it's not possible to locate the base path try to create it
|
|
|
|
if(absPath.isEmpty()) {
|
|
|
|
QStringList pathElements = m_blfile.split("/");
|
|
|
|
// remove filename from list and save last path element
|
|
|
|
pathElements.removeLast();
|
|
|
|
QString lastElement = pathElements.last();
|
|
|
|
// remove last path element for base
|
|
|
|
pathElements.removeLast();
|
|
|
|
QString basePath = pathElements.join("/");
|
|
|
|
|
|
|
|
// check for base and bail out if not found. Otherwise create folder.
|
2010-04-02 21:24:19 +00:00
|
|
|
absPath = Utils::resolvePathCase(basePath);
|
2008-09-28 17:02:36 +00:00
|
|
|
QDir d(absPath);
|
|
|
|
d.mkpath(lastElement);
|
2010-04-02 21:24:19 +00:00
|
|
|
absPath = Utils::resolvePathCase(fi.absolutePath());
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
if(absPath.isEmpty()) {
|
|
|
|
emit logItem(tr("Error accessing output folder"), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fwfile = absPath + "/" + fi.fileName();
|
|
|
|
|
|
|
|
// place (new) bootloader
|
|
|
|
m_tempfile.open();
|
2012-04-26 19:17:00 +00:00
|
|
|
qDebug() << "[BootloaderInstallFile] renaming" << m_tempfile.fileName()
|
|
|
|
<< "to" << fwfile;
|
2008-09-28 17:02:36 +00:00
|
|
|
m_tempfile.close();
|
|
|
|
|
2012-04-26 19:17:00 +00:00
|
|
|
if(!Utils::resolvePathCase(fwfile).isEmpty()) {
|
|
|
|
emit logItem(tr("A firmware file is already present on player"), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_tempfile.copy(fwfile)) {
|
|
|
|
emit logItem(tr("Bootloader successful installed"), LOGOK);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit logItem(tr("Copying modified firmware file failed"), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
logInstall(LogAdd);
|
|
|
|
|
|
|
|
emit done(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BootloaderInstallFile::uninstall(void)
|
|
|
|
{
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallFile] Uninstalling bootloader";
|
2008-09-28 17:02:36 +00:00
|
|
|
emit logItem(tr("Removing Rockbox bootloader"), LOGINFO);
|
|
|
|
// check if a .ORIG file is present, and allow moving it back.
|
2010-04-02 21:24:19 +00:00
|
|
|
QString origbl = Utils::resolvePathCase(m_blfile + ".ORIG");
|
2008-09-28 17:02:36 +00:00
|
|
|
if(origbl.isEmpty()) {
|
|
|
|
emit logItem(tr("No original firmware file found."), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-02 21:24:19 +00:00
|
|
|
QString fwfile = Utils::resolvePathCase(m_blfile);
|
2008-09-28 17:02:36 +00:00
|
|
|
if(!QFile::remove(fwfile)) {
|
|
|
|
emit logItem(tr("Can't remove Rockbox bootloader file."), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!QFile::rename(origbl, fwfile)) {
|
|
|
|
emit logItem(tr("Can't restore bootloader file."), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
emit logItem(tr("Original bootloader restored successfully."), LOGOK);
|
|
|
|
logInstall(LogRemove);
|
|
|
|
emit done(false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! @brief check if bootloader is installed.
|
|
|
|
//! @return BootloaderRockbox, BootloaderOther or BootloaderUnknown.
|
|
|
|
BootloaderInstallBase::BootloaderType BootloaderInstallFile::installed(void)
|
|
|
|
{
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallFile] checking installed bootloader";
|
2010-04-02 21:24:19 +00:00
|
|
|
if(!Utils::resolvePathCase(m_blfile).isEmpty()
|
|
|
|
&& !Utils::resolvePathCase(m_blfile + ".ORIG").isEmpty())
|
2008-09-28 17:02:36 +00:00
|
|
|
return BootloaderRockbox;
|
2010-04-02 21:24:19 +00:00
|
|
|
else if(!Utils::resolvePathCase(m_blfile).isEmpty())
|
2008-09-28 17:02:36 +00:00
|
|
|
return BootloaderOther;
|
|
|
|
else
|
|
|
|
return BootloaderUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BootloaderInstallBase::Capabilities BootloaderInstallFile::capabilities(void)
|
|
|
|
{
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallFile] getting capabilities";
|
2011-06-25 17:21:01 +00:00
|
|
|
return Install | Uninstall | IsFile | CanCheckInstalled | Backup;
|
2008-09-28 17:02:36 +00:00
|
|
|
}
|
|
|
|
|