diff options
Diffstat (limited to 'rbutil/rbutilqt/base/bootloaderinstallbase.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallbase.cpp | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/base/bootloaderinstallbase.cpp b/rbutil/rbutilqt/base/bootloaderinstallbase.cpp new file mode 100644 index 0000000000..d0abffa44d --- /dev/null +++ b/rbutil/rbutilqt/base/bootloaderinstallbase.cpp | |||
@@ -0,0 +1,184 @@ | |||
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 | |||
21 | #include <QtCore> | ||
22 | |||
23 | #include "bootloaderinstallbase.h" | ||
24 | #include "utils.h" | ||
25 | |||
26 | BootloaderInstallBase::BootloaderType BootloaderInstallBase::installed(void) | ||
27 | { | ||
28 | return BootloaderUnknown; | ||
29 | } | ||
30 | |||
31 | |||
32 | BootloaderInstallBase::Capabilities BootloaderInstallBase::capabilities(void) | ||
33 | { | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | |||
38 | void BootloaderInstallBase::downloadBlStart(QUrl source) | ||
39 | { | ||
40 | m_http.setFile(&m_tempfile); | ||
41 | m_http.setCache(true); | ||
42 | connect(&m_http, SIGNAL(done(bool)), this, SLOT(downloadBlFinish(bool))); | ||
43 | // connect the http read signal to our logProgess *signal* | ||
44 | // to immediately emit it without any helper function. | ||
45 | connect(&m_http, SIGNAL(dataReadProgress(int, int)), | ||
46 | this, SIGNAL(logProgress(int, int))); | ||
47 | m_http.getFile(source); | ||
48 | } | ||
49 | |||
50 | |||
51 | void BootloaderInstallBase::downloadReqFinished(int id, bool error) | ||
52 | { | ||
53 | qDebug() << __FILE__ << "::" << __func__ << id << error; | ||
54 | qDebug() << "error:" << m_http.errorString(); | ||
55 | |||
56 | downloadBlFinish(error); | ||
57 | } | ||
58 | |||
59 | |||
60 | void BootloaderInstallBase::downloadBlFinish(bool error) | ||
61 | { | ||
62 | qDebug() << __FILE__ << "::" << __func__ << ": error =" << error; | ||
63 | |||
64 | // update progress bar | ||
65 | emit logProgress(100, 100); | ||
66 | |||
67 | if(m_http.httpResponse() != 200) { | ||
68 | emit logItem(tr("Download error: received HTTP error %1.") | ||
69 | .arg(m_http.errorString()), LOGERROR); | ||
70 | emit done(true); | ||
71 | return; | ||
72 | } | ||
73 | if(error) { | ||
74 | emit logItem(tr("Download error: %1") | ||
75 | .arg(m_http.error()), LOGERROR); | ||
76 | emit done(true); | ||
77 | return; | ||
78 | } | ||
79 | else if(m_http.isCached()) | ||
80 | emit logItem(tr("Download finished (cache used)."), LOGOK); | ||
81 | else | ||
82 | emit logItem(tr("Download finished."), LOGOK); | ||
83 | |||
84 | m_blversion = m_http.timestamp(); | ||
85 | emit downloadDone(); | ||
86 | } | ||
87 | |||
88 | void BootloaderInstallBase::installBlfile(void) | ||
89 | { | ||
90 | qDebug() << __FILE__ << __func__; | ||
91 | } | ||
92 | |||
93 | |||
94 | //! @brief backup OF file. | ||
95 | //! @param to folder to write backup file to. Folder will get created. | ||
96 | //! @return true on success, false on error. | ||
97 | |||
98 | bool BootloaderInstallBase::backup(QString to) | ||
99 | { | ||
100 | qDebug() << __func__; | ||
101 | QDir targetDir("."); | ||
102 | emit logItem(tr("Creating backup of original firmware file."), LOGINFO); | ||
103 | if(!targetDir.mkpath(to)) { | ||
104 | emit logItem(tr("Creating backup folder failed"), LOGERROR); | ||
105 | return false; | ||
106 | } | ||
107 | QString tofile = to + "/" + QFileInfo(m_blfile).fileName(); | ||
108 | qDebug() << "trying to backup" << m_blfile << "to" << tofile; | ||
109 | if(!QFile::copy(resolvePathCase(m_blfile), tofile)) { | ||
110 | emit logItem(tr("Creating backup copy failed."), LOGERROR); | ||
111 | return false; | ||
112 | } | ||
113 | emit logItem(tr("Backup created."), LOGOK); | ||
114 | return true; | ||
115 | } | ||
116 | |||
117 | |||
118 | //! @brief log installation to logfile. | ||
119 | //! @param mode action to perform. 0: add to log, 1: remove from log. | ||
120 | //! @return 0 on success | ||
121 | int BootloaderInstallBase::logInstall(LogMode mode) | ||
122 | { | ||
123 | int result = 0; | ||
124 | QString section = m_blurl.path().section('/', -1); | ||
125 | QSettings s(m_logfile, QSettings::IniFormat, this); | ||
126 | emit logItem(tr("Creating installation log"), LOGINFO); | ||
127 | |||
128 | if(mode == LogAdd) { | ||
129 | s.setValue("Bootloader/" + section, m_blversion.toString(Qt::ISODate)); | ||
130 | qDebug() << m_blversion.toString(Qt::ISODate); | ||
131 | } | ||
132 | else { | ||
133 | s.remove("Bootloader/" + section); | ||
134 | } | ||
135 | s.sync(); | ||
136 | |||
137 | return result; | ||
138 | } | ||
139 | |||
140 | |||
141 | //! @brief Return post install hints string. | ||
142 | //! @param model model string | ||
143 | //! @return hints. | ||
144 | QString BootloaderInstallBase::postinstallHints(QString model) | ||
145 | { | ||
146 | bool hint = false; | ||
147 | QString msg = tr("Bootloader installation is almost complete. " | ||
148 | "Installation <b>requires</b> you to perform the " | ||
149 | "following steps manually:"); | ||
150 | |||
151 | msg += tr("<ol>"); | ||
152 | msg += tr("<li>Safely remove your player.</li>"); | ||
153 | if(model == "h100" || model == "h120" || model == "h300") { | ||
154 | hint = true; | ||
155 | msg += tr("<li>Reboot your player into the original firmware.</li>" | ||
156 | "<li>Perform a firmware upgrade using the update functionality " | ||
157 | "of the original firmware. Please refer to your player's manual " | ||
158 | "on details.</li>" | ||
159 | "<li>After the firmware has been updated reboot your player.</li>"); | ||
160 | } | ||
161 | if(model == "iaudiox5" || model == "iaudiom5" | ||
162 | || model == "iaudiox5v" || model == "iaudiom3") { | ||
163 | hint = true; | ||
164 | msg += tr("<li>Turn the player off</li>" | ||
165 | "<li>Insert the charger</li>"); | ||
166 | } | ||
167 | if(model == "gigabeatf") { | ||
168 | hint = true; | ||
169 | msg += tr("<li>Unplug USB and power adaptors</li>" | ||
170 | "<li>Hold <i>Power</i> to turn the player off</li>" | ||
171 | "<li>Toggle the battery switch on the player</li>" | ||
172 | "<li>Hold <i>Power</i> to boot into Rockbox</li>"); | ||
173 | } | ||
174 | |||
175 | msg += "</ol>"; | ||
176 | msg += tr("<p><b>Note:</b> You can safely install other parts first, but " | ||
177 | "the above steps are <b>required</b> to finish the installation!</p>"); | ||
178 | |||
179 | if(hint) | ||
180 | return msg; | ||
181 | else | ||
182 | return QString(""); | ||
183 | } | ||
184 | |||