Don't accept 0 for the width or height of a progress bar in the %pb tag. A zero...
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstallmi4.cpp
blobfa0ebb2f02880e715124aefe44523749d4bc35d7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Riebeling
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <QtCore>
21 #include <QtDebug>
22 #include <QtDebug>
23 #include "bootloaderinstallmi4.h"
24 #include "utils.h"
26 BootloaderInstallMi4::BootloaderInstallMi4(QObject *parent)
27 : BootloaderInstallBase(parent)
32 bool BootloaderInstallMi4::install(void)
34 emit logItem(tr("Downloading bootloader"), LOGINFO);
35 qDebug() << __func__;
36 downloadBlStart(m_blurl);
37 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
38 return true;
41 void BootloaderInstallMi4::installStage2(void)
43 emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
45 // move old bootloader out of the way
46 QString fwfile(resolvePathCase(m_blfile));
47 QFile oldbl(fwfile);
48 QString moved = QFileInfo(resolvePathCase(m_blfile)).absolutePath()
49 + "/OF.mi4";
50 qDebug() << "renaming" << fwfile << "->" << moved;
51 oldbl.rename(moved);
53 // place new bootloader
54 m_tempfile.open();
55 qDebug() << "renaming" << m_tempfile.fileName() << "->" << fwfile;
56 m_tempfile.close();
57 m_tempfile.rename(fwfile);
59 emit logItem(tr("Bootloader successful installed"), LOGOK);
60 logInstall(LogAdd);
62 emit done(true);
66 bool BootloaderInstallMi4::uninstall(void)
68 qDebug() << __func__;
70 // check if it's actually a Rockbox bootloader
71 emit logItem(tr("Checking for Rockbox bootloader"), LOGINFO);
72 if(installed() != BootloaderRockbox) {
73 emit logItem(tr("No Rockbox bootloader found"), LOGERROR);
74 return false;
77 // check if OF file present
78 emit logItem(tr("Checking for original firmware file"), LOGINFO);
79 QString original = QFileInfo(resolvePathCase(m_blfile)).absolutePath()
80 + "/OF.mi4";
82 if(resolvePathCase(original).isEmpty()) {
83 emit logItem(tr("Error finding original firmware file"), LOGERROR);
84 return false;
87 // finally remove RB bootloader
88 QString resolved = resolvePathCase(m_blfile);
89 QFile blfile(resolved);
90 blfile.remove();
92 QFile oldbl(resolvePathCase(original));
93 oldbl.rename(m_blfile);
94 emit logItem(tr("Rockbox bootloader successful removed"), LOGINFO);
95 logInstall(LogRemove);
96 emit done(false);
98 return true;
102 //! check if a bootloader is installed and return its state.
103 BootloaderInstallBase::BootloaderType BootloaderInstallMi4::installed(void)
105 // for MI4 files we can check if we actually have a RB bootloader
106 // installed.
107 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
109 // make sure to resolve case to prevent case issues
110 QString resolved;
111 resolved = resolvePathCase(m_blfile);
112 if(resolved.isEmpty()) {
113 qDebug("%s: BootloaderNone", __func__);
114 return BootloaderNone;
117 QFile f(resolved);
118 f.open(QIODevice::ReadOnly);
119 f.seek(0x1f8);
120 char magic[4];
121 f.read(magic, 4);
122 f.close();
124 if(!memcmp(magic, "RBBL", 4)) {
125 qDebug("%s: BootloaderRockbox", __func__);
126 return BootloaderRockbox;
128 else {
129 qDebug("%s: BootloaderOther", __func__);
130 return BootloaderOther;
135 BootloaderInstallBase::Capabilities BootloaderInstallMi4::capabilities(void)
137 qDebug() << __func__;
138 return Install | Uninstall | Backup | IsFile | CanCheckInstalled | CanCheckVersion;