Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstallmi4.cpp
blob8ae872d5ab5053e40396715dd248b23c43313b3b
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() << "[BootloaderInstallMi4] installing bootloader";
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);
44 QCoreApplication::processEvents();
46 // move old bootloader out of the way
47 QString fwfile(resolvePathCase(m_blfile));
48 QFile oldbl(fwfile);
49 QString moved = QFileInfo(resolvePathCase(m_blfile)).absolutePath()
50 + "/OF.mi4";
51 if(!QFileInfo(moved).exists()) {
52 qDebug() << "[BootloaderInstallMi4] renaming" << fwfile << "to" << moved;
53 oldbl.rename(moved);
55 else {
56 qDebug() << "[BootloaderInstallMi4] OF.mi4 already present, not renaming again.";
57 oldbl.remove();
60 // place new bootloader
61 m_tempfile.open();
62 qDebug() << "[BootloaderInstallMi4] renaming" << m_tempfile.fileName() << "to" << fwfile;
63 m_tempfile.close();
64 m_tempfile.rename(fwfile);
66 emit logItem(tr("Bootloader successful installed"), LOGOK);
67 logInstall(LogAdd);
69 emit done(false);
73 bool BootloaderInstallMi4::uninstall(void)
75 qDebug() << "[BootloaderInstallMi4] Uninstalling bootloader";
77 // check if it's actually a Rockbox bootloader
78 emit logItem(tr("Checking for Rockbox bootloader"), LOGINFO);
79 if(installed() != BootloaderRockbox) {
80 emit logItem(tr("No Rockbox bootloader found"), LOGERROR);
81 return false;
84 // check if OF file present
85 emit logItem(tr("Checking for original firmware file"), LOGINFO);
86 QString original = QFileInfo(resolvePathCase(m_blfile)).absolutePath()
87 + "/OF.mi4";
89 if(resolvePathCase(original).isEmpty()) {
90 emit logItem(tr("Error finding original firmware file"), LOGERROR);
91 return false;
94 // finally remove RB bootloader
95 QString resolved = resolvePathCase(m_blfile);
96 QFile blfile(resolved);
97 blfile.remove();
99 QFile oldbl(resolvePathCase(original));
100 oldbl.rename(m_blfile);
101 emit logItem(tr("Rockbox bootloader successful removed"), LOGINFO);
102 logInstall(LogRemove);
103 emit done(false);
105 return true;
109 //! check if a bootloader is installed and return its state.
110 BootloaderInstallBase::BootloaderType BootloaderInstallMi4::installed(void)
112 // for MI4 files we can check if we actually have a RB bootloader
113 // installed.
114 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
116 // make sure to resolve case to prevent case issues
117 QString resolved;
118 resolved = resolvePathCase(m_blfile);
119 if(resolved.isEmpty()) {
120 qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
121 return BootloaderNone;
124 QFile f(resolved);
125 f.open(QIODevice::ReadOnly);
126 f.seek(0x1f8);
127 char magic[4];
128 f.read(magic, 4);
129 f.close();
131 if(!memcmp(magic, "RBBL", 4)) {
132 qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
133 return BootloaderRockbox;
135 else {
136 qDebug() << "[BootloaderInstallMi4] installed: BootloaderOther";
137 return BootloaderOther;
142 BootloaderInstallBase::Capabilities BootloaderInstallMi4::capabilities(void)
144 qDebug() << "[BootloaderInstallMi4] getting capabilities";
145 return Install | Uninstall | Backup | IsFile | CanCheckInstalled | CanCheckVersion;