diff options
Diffstat (limited to 'rbutil/rbutilqt/bootloaderinstallfile.cpp')
-rw-r--r-- | rbutil/rbutilqt/bootloaderinstallfile.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/bootloaderinstallfile.cpp b/rbutil/rbutilqt/bootloaderinstallfile.cpp new file mode 100644 index 0000000000..7e4d6e81ea --- /dev/null +++ b/rbutil/rbutilqt/bootloaderinstallfile.cpp | |||
@@ -0,0 +1,145 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2008 by Dominik Riebeling | ||
10 | * $Id:$ | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <QtCore> | ||
21 | #include <QtDebug> | ||
22 | #include <QtDebug> | ||
23 | #include "bootloaderinstallfile.h" | ||
24 | #include "utils.h" | ||
25 | |||
26 | |||
27 | BootloaderInstallFile::BootloaderInstallFile(QObject *parent) | ||
28 | : BootloaderInstallBase(parent) | ||
29 | { | ||
30 | } | ||
31 | |||
32 | |||
33 | bool BootloaderInstallFile::install(void) | ||
34 | { | ||
35 | emit logItem(tr("Downloading bootloader"), LOGINFO); | ||
36 | qDebug() << __func__; | ||
37 | downloadBlStart(m_blurl); | ||
38 | connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2())); | ||
39 | return true; | ||
40 | } | ||
41 | |||
42 | void BootloaderInstallFile::installStage2(void) | ||
43 | { | ||
44 | emit logItem(tr("Installing Rockbox bootloader"), LOGINFO); | ||
45 | |||
46 | // if an old bootloader is present (Gigabeat) move it out of the way. | ||
47 | QString fwfile(resolvePathCase(m_blfile)); | ||
48 | if(!fwfile.isEmpty()) { | ||
49 | QString moved = resolvePathCase(m_blfile) + ".ORIG"; | ||
50 | qDebug() << "renaming" << fwfile << "->" << 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 = 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 = resolvePathCase(basePath); | ||
70 | QDir d(absPath); | ||
71 | d.mkpath(lastElement); | ||
72 | absPath = 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 | qDebug() << "renaming" << m_tempfile.fileName() << "->" << fwfile; | ||
85 | m_tempfile.close(); | ||
86 | m_tempfile.rename(fwfile); | ||
87 | |||
88 | emit logItem(tr("Bootloader successful installed"), LOGOK); | ||
89 | logInstall(LogAdd); | ||
90 | |||
91 | emit done(false); | ||
92 | } | ||
93 | |||
94 | |||
95 | bool BootloaderInstallFile::uninstall(void) | ||
96 | { | ||
97 | qDebug() << __func__; | ||
98 | emit logItem(tr("Removing Rockbox bootloader"), LOGINFO); | ||
99 | // check if a .ORIG file is present, and allow moving it back. | ||
100 | QString origbl = resolvePathCase(m_blfile + ".ORIG"); | ||
101 | if(origbl.isEmpty()) { | ||
102 | emit logItem(tr("No original firmware file found."), LOGERROR); | ||
103 | emit done(true); | ||
104 | return false; | ||
105 | } | ||
106 | QString fwfile = resolvePathCase(m_blfile); | ||
107 | if(!QFile::remove(fwfile)) { | ||
108 | emit logItem(tr("Can't remove Rockbox bootloader file."), LOGERROR); | ||
109 | emit done(true); | ||
110 | return false; | ||
111 | } | ||
112 | if(!QFile::rename(origbl, fwfile)) { | ||
113 | emit logItem(tr("Can't restore bootloader file."), LOGERROR); | ||
114 | emit done(true); | ||
115 | return false; | ||
116 | } | ||
117 | emit logItem(tr("Original bootloader restored successfully."), LOGOK); | ||
118 | logInstall(LogRemove); | ||
119 | emit done(false); | ||
120 | |||
121 | return true; | ||
122 | } | ||
123 | |||
124 | |||
125 | //! @brief check if bootloader is installed. | ||
126 | //! @return BootloaderRockbox, BootloaderOther or BootloaderUnknown. | ||
127 | BootloaderInstallBase::BootloaderType BootloaderInstallFile::installed(void) | ||
128 | { | ||
129 | qDebug("%s()", __func__); | ||
130 | if(!resolvePathCase(m_blfile).isEmpty() | ||
131 | && !resolvePathCase(m_blfile + ".ORIG").isEmpty()) | ||
132 | return BootloaderRockbox; | ||
133 | else if(!resolvePathCase(m_blfile).isEmpty()) | ||
134 | return BootloaderOther; | ||
135 | else | ||
136 | return BootloaderUnknown; | ||
137 | } | ||
138 | |||
139 | |||
140 | BootloaderInstallBase::Capabilities BootloaderInstallFile::capabilities(void) | ||
141 | { | ||
142 | qDebug() << __func__; | ||
143 | return Install | IsFile | CanCheckInstalled | Backup; | ||
144 | } | ||
145 | |||