summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/bootloaderinstallfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstallfile.cpp')
-rw-r--r--utils/rbutilqt/base/bootloaderinstallfile.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstallfile.cpp b/utils/rbutilqt/base/bootloaderinstallfile.cpp
new file mode 100644
index 0000000000..bf3d5e449d
--- /dev/null
+++ b/utils/rbutilqt/base/bootloaderinstallfile.cpp
@@ -0,0 +1,159 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2008 by Dominik Riebeling
10 *
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.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19#include <QtCore>
20#include <QtDebug>
21#include "bootloaderinstallfile.h"
22#include "utils.h"
23#include "Logger.h"
24
25
26BootloaderInstallFile::BootloaderInstallFile(QObject *parent)
27 : BootloaderInstallBase(parent)
28{
29}
30
31
32bool BootloaderInstallFile::install(void)
33{
34 emit logItem(tr("Downloading bootloader"), LOGINFO);
35 LOG_INFO() << "installing bootloader";
36 downloadBlStart(m_blurl);
37 connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallFile::installStage2);
38 return true;
39}
40
41void BootloaderInstallFile::installStage2(void)
42{
43 emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
44 QCoreApplication::processEvents();
45
46 // if an old bootloader is present (Gigabeat) move it out of the way.
47 QString fwfile(Utils::resolvePathCase(m_blfile));
48 if(!fwfile.isEmpty()) {
49 QString moved = Utils::resolvePathCase(m_blfile) + ".ORIG";
50 LOG_INFO() << "renaming" << fwfile << "to" << moved;
51 QFile::rename(fwfile, moved);
52 }
53
54 // if no old file found resolve path without basename
55 QFileInfo fi(m_blfile);
56 QString absPath = Utils::resolvePathCase(fi.absolutePath());
57
58 // if it's not possible to locate the base path try to create it
59 if(absPath.isEmpty()) {
60 QStringList pathElements = m_blfile.split("/");
61 // remove filename from list and save last path element
62 pathElements.removeLast();
63 QString lastElement = pathElements.last();
64 // remove last path element for base
65 pathElements.removeLast();
66 QString basePath = pathElements.join("/");
67
68 // check for base and bail out if not found. Otherwise create folder.
69 absPath = Utils::resolvePathCase(basePath);
70 QDir d(absPath);
71 d.mkpath(lastElement);
72 absPath = Utils::resolvePathCase(fi.absolutePath());
73
74 if(absPath.isEmpty()) {
75 emit logItem(tr("Error accessing output folder"), LOGERROR);
76 emit done(true);
77 return;
78 }
79 }
80 fwfile = absPath + "/" + fi.fileName();
81
82 // place (new) bootloader
83 m_tempfile.open();
84 LOG_INFO() << "renaming" << m_tempfile.fileName()
85 << "to" << fwfile;
86 m_tempfile.close();
87
88 if(!Utils::resolvePathCase(fwfile).isEmpty()) {
89 emit logItem(tr("A firmware file is already present on player"), LOGERROR);
90 emit done(true);
91 return;
92 }
93 if(m_tempfile.copy(fwfile)) {
94 emit logItem(tr("Bootloader successful installed"), LOGOK);
95 }
96 else {
97 emit logItem(tr("Copying modified firmware file failed"), LOGERROR);
98 emit done(true);
99 return;
100 }
101
102 logInstall(LogAdd);
103
104 emit done(false);
105}
106
107
108bool BootloaderInstallFile::uninstall(void)
109{
110 LOG_INFO() << "Uninstalling bootloader";
111 emit logItem(tr("Removing Rockbox bootloader"), LOGINFO);
112 // check if a .ORIG file is present, and allow moving it back.
113 QString origbl = Utils::resolvePathCase(m_blfile + ".ORIG");
114 if(origbl.isEmpty()) {
115 emit logItem(tr("No original firmware file found."), LOGERROR);
116 emit done(true);
117 return false;
118 }
119 QString fwfile = Utils::resolvePathCase(m_blfile);
120 if(!QFile::remove(fwfile)) {
121 emit logItem(tr("Can't remove Rockbox bootloader file."), LOGERROR);
122 emit done(true);
123 return false;
124 }
125 if(!QFile::rename(origbl, fwfile)) {
126 emit logItem(tr("Can't restore bootloader file."), LOGERROR);
127 emit done(true);
128 return false;
129 }
130 emit logItem(tr("Original bootloader restored successfully."), LOGOK);
131 logInstall(LogRemove);
132 emit logProgress(1, 1);
133 emit done(false);
134
135 return true;
136}
137
138
139//! @brief check if bootloader is installed.
140//! @return BootloaderRockbox, BootloaderOther or BootloaderUnknown.
141BootloaderInstallBase::BootloaderType BootloaderInstallFile::installed(void)
142{
143 LOG_INFO() << "checking installed bootloader";
144 if(!Utils::resolvePathCase(m_blfile).isEmpty()
145 && !Utils::resolvePathCase(m_blfile + ".ORIG").isEmpty())
146 return BootloaderRockbox;
147 else if(!Utils::resolvePathCase(m_blfile).isEmpty())
148 return BootloaderOther;
149 else
150 return BootloaderUnknown;
151}
152
153
154BootloaderInstallBase::Capabilities BootloaderInstallFile::capabilities(void)
155{
156 LOG_INFO() << "getting capabilities";
157 return Install | Uninstall | IsFile | CanCheckInstalled | Backup;
158}
159