Voicefile: remove < and > from voice strings before speaking.
[maemo-rb.git] / rbutil / rbutilqt / base / bootloaderinstallmi4.cpp
blobb2d8d0c24b94098694a944049dcae829042dd904
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtCore>
20 #include <QtDebug>
21 #include <QtDebug>
22 #include "bootloaderinstallmi4.h"
23 #include "utils.h"
25 BootloaderInstallMi4::BootloaderInstallMi4(QObject *parent)
26 : BootloaderInstallBase(parent)
31 bool BootloaderInstallMi4::install(void)
33 emit logItem(tr("Downloading bootloader"), LOGINFO);
34 qDebug() << "[BootloaderInstallMi4] installing bootloader";
35 downloadBlStart(m_blurl);
36 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
37 return true;
40 void BootloaderInstallMi4::installStage2(void)
42 emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
43 QCoreApplication::processEvents();
45 // move old bootloader out of the way
46 QString fwfile(Utils::resolvePathCase(m_blfile));
47 QFile oldbl(fwfile);
48 QString moved = QFileInfo(Utils::resolvePathCase(m_blfile)).absolutePath()
49 + "/OF.mi4";
50 if(!QFileInfo(moved).exists()) {
51 qDebug() << "[BootloaderInstallMi4] renaming" << fwfile << "to" << moved;
52 oldbl.rename(moved);
54 else {
55 qDebug() << "[BootloaderInstallMi4] OF.mi4 already present, not renaming again.";
56 oldbl.remove();
59 // place new bootloader
60 m_tempfile.open();
61 qDebug() << "[BootloaderInstallMi4] renaming" << m_tempfile.fileName() << "to" << fwfile;
62 m_tempfile.close();
63 m_tempfile.copy(fwfile);
65 emit logItem(tr("Bootloader successful installed"), LOGOK);
66 logInstall(LogAdd);
68 emit done(false);
72 bool BootloaderInstallMi4::uninstall(void)
74 qDebug() << "[BootloaderInstallMi4] Uninstalling bootloader";
76 // check if it's actually a Rockbox bootloader
77 emit logItem(tr("Checking for Rockbox bootloader"), LOGINFO);
78 if(installed() != BootloaderRockbox) {
79 emit logItem(tr("No Rockbox bootloader found"), LOGERROR);
80 return false;
83 // check if OF file present
84 emit logItem(tr("Checking for original firmware file"), LOGINFO);
85 QString original = QFileInfo(Utils::resolvePathCase(m_blfile)).absolutePath()
86 + "/OF.mi4";
88 if(Utils::resolvePathCase(original).isEmpty()) {
89 emit logItem(tr("Error finding original firmware file"), LOGERROR);
90 return false;
93 // finally remove RB bootloader
94 QString resolved = Utils::resolvePathCase(m_blfile);
95 QFile blfile(resolved);
96 blfile.remove();
98 QFile::rename(Utils::resolvePathCase(original), m_blfile);
99 emit logItem(tr("Rockbox bootloader successful removed"), LOGINFO);
100 logInstall(LogRemove);
101 emit done(false);
103 return true;
107 //! check if a bootloader is installed and return its state.
108 BootloaderInstallBase::BootloaderType BootloaderInstallMi4::installed(void)
110 // for MI4 files we can check if we actually have a RB bootloader
111 // installed.
112 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
114 // make sure to resolve case to prevent case issues
115 QString resolved;
116 resolved = Utils::resolvePathCase(m_blfile);
117 if(resolved.isEmpty()) {
118 qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
119 return BootloaderNone;
122 QFile f(resolved);
123 f.open(QIODevice::ReadOnly);
124 f.seek(0x1f8);
125 char magic[4];
126 f.read(magic, 4);
127 f.close();
129 if(!memcmp(magic, "RBBL", 4)) {
130 qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
131 return BootloaderRockbox;
133 else {
134 qDebug() << "[BootloaderInstallMi4] installed: BootloaderOther";
135 return BootloaderOther;
140 BootloaderInstallBase::Capabilities BootloaderInstallMi4::capabilities(void)
142 qDebug() << "[BootloaderInstallMi4] getting capabilities";
143 return Install | Uninstall | Backup | IsFile | CanCheckInstalled | CanCheckVersion;