1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
22 #include "bootloaderinstallbase.h"
26 #if defined(Q_OS_MACX)
27 #include <sys/param.h>
28 #include <sys/ucred.h>
29 #include <sys/mount.h>
33 BootloaderInstallBase::BootloaderType
BootloaderInstallBase::installed(void)
35 return BootloaderUnknown
;
39 BootloaderInstallBase::Capabilities
BootloaderInstallBase::capabilities(void)
45 void BootloaderInstallBase::downloadBlStart(QUrl source
)
47 m_http
.setFile(&m_tempfile
);
48 m_http
.setCache(true);
49 connect(&m_http
, SIGNAL(done(bool)), this, SLOT(downloadBlFinish(bool)));
50 // connect the http read signal to our logProgess *signal*
51 // to immediately emit it without any helper function.
52 connect(&m_http
, SIGNAL(dataReadProgress(int, int)),
53 this, SIGNAL(logProgress(int, int)));
54 m_http
.getFile(source
);
58 void BootloaderInstallBase::downloadReqFinished(int id
, bool error
)
60 qDebug() << "[BootloaderInstallBase] Download Request" << id
61 << "finished, error:" << m_http
.errorString();
63 downloadBlFinish(error
);
67 void BootloaderInstallBase::downloadBlFinish(bool error
)
69 qDebug() << "[BootloaderInstallBase] Downloading bootloader finished, error:"
72 // update progress bar
73 emit
logProgress(100, 100);
75 if(m_http
.httpResponse() != 200) {
76 emit
logItem(tr("Download error: received HTTP error %1.")
77 .arg(m_http
.errorString()), LOGERROR
);
82 emit
logItem(tr("Download error: %1")
83 .arg(m_http
.error()), LOGERROR
);
87 else if(m_http
.isCached())
88 emit
logItem(tr("Download finished (cache used)."), LOGOK
);
90 emit
logItem(tr("Download finished."), LOGOK
);
92 QCoreApplication::processEvents();
93 m_blversion
= m_http
.timestamp();
98 void BootloaderInstallBase::installBlfile(void)
100 qDebug() << "[BootloaderInstallBase] installBlFile(void)";
104 //! @brief backup OF file.
105 //! @param to folder to write backup file to. Folder will get created.
106 //! @return true on success, false on error.
107 bool BootloaderInstallBase::backup(QString to
)
109 qDebug() << "[BootloaderInstallBase] Backing up bootloader file";
111 emit
logItem(tr("Creating backup of original firmware file."), LOGINFO
);
112 if(!targetDir
.mkpath(to
)) {
113 emit
logItem(tr("Creating backup folder failed"), LOGERROR
);
116 QString tofile
= to
+ "/" + QFileInfo(m_blfile
).fileName();
117 qDebug() << "[BootloaderInstallBase] trying to backup" << m_blfile
<< "to" << tofile
;
118 if(!QFile::copy(Utils::resolvePathCase(m_blfile
), tofile
)) {
119 emit
logItem(tr("Creating backup copy failed."), LOGERROR
);
122 emit
logItem(tr("Backup created."), LOGOK
);
127 //! @brief log installation to logfile.
128 //! @param mode action to perform. 0: add to log, 1: remove from log.
129 //! @return 0 on success
130 int BootloaderInstallBase::logInstall(LogMode mode
)
133 QString section
= m_blurl
.path().section('/', -1);
134 QSettings
s(m_logfile
, QSettings::IniFormat
, this);
135 emit
logItem(tr("Creating installation log"), LOGINFO
);
138 s
.setValue("Bootloader/" + section
, m_blversion
.toString(Qt::ISODate
));
139 qDebug() << "[BootloaderInstallBase] Writing log, version:"
140 << m_blversion
.toString(Qt::ISODate
);
143 s
.remove("Bootloader/" + section
);
147 emit
logItem(tr("Installation log created"), LOGOK
);
153 #if defined(Q_OS_MACX)
154 void BootloaderInstallBase::waitRemount()
156 m_remountTries
= 600;
157 emit
logItem(tr("Waiting for system to remount player"), LOGINFO
);
159 QTimer::singleShot(100, this, SLOT(checkRemount()));
164 void BootloaderInstallBase::checkRemount()
166 #if defined(Q_OS_MACX)
167 if(m_remountTries
--) {
169 // check if device has been remounted
170 QCoreApplication::processEvents();
172 struct statfs
*mntinf
;
174 num
= getmntinfo(&mntinf
, MNT_WAIT
);
176 if(QString(mntinf
->f_mntfromname
).startsWith(m_remountDevice
)
177 && QString(mntinf
->f_fstypename
).contains("msdos", Qt::CaseInsensitive
))
182 // still not remounted, restart timer.
183 QTimer::singleShot(500, this, SLOT(checkRemount()));
184 qDebug() << "[BootloaderInstallBase] Player not remounted yet" << m_remountDevice
;
187 emit
logItem(tr("Player remounted"), LOGINFO
);
188 emit
remounted(true);
192 emit
logItem(tr("Timeout on remount"), LOGERROR
);
193 emit
remounted(false);
199 //! @brief set list of possible bootloader files and pick the existing one.
200 //! @param sl list of possible bootloader files.
201 void BootloaderInstallBase::setBlFile(QStringList sl
)
203 // figue which of the possible bootloader filenames is correct.
204 for(int a
= 0; a
< sl
.size(); a
++) {
205 if(!Utils::resolvePathCase(sl
.at(a
)).isEmpty()) {
209 if(m_blfile
.isEmpty()) {
215 bool BootloaderInstallBase::setOfFile(QString of
, QStringList blfile
)
219 // check if the file set is in zip format
221 emit
logItem(tr("Zip file format detected"), LOGINFO
);
222 QStringList contents
= z
.files();
223 qDebug() << "[BootloaderInstallBase] archive contains:" << contents
;
224 for(int i
= 0; i
< blfile
.size(); ++i
) {
225 // strip any path, we don't know the structure in the zip
226 QString f
= QFileInfo(blfile
.at(i
)).fileName();
227 qDebug() << "[BootloaderInstallBase] searching archive for" << f
;
228 // contents.indexOf() works case sensitive. Since the filename
229 // casing is unknown (and might change) do this manually.
230 // FIXME: support files in folders
231 for(int j
= 0; j
< contents
.size(); ++j
) {
232 if(contents
.at(j
).compare(f
, Qt::CaseInsensitive
) == 0) {
234 emit
logItem(tr("Extracting firmware %1 from archive")
236 // store in class temporary file
238 m_offile
= m_tempof
.fileName();
240 if(!z
.extractArchive(m_offile
, contents
.at(j
))) {
241 emit
logItem(tr("Error extracting firmware from archive"), LOGERROR
);
250 emit
logItem(tr("Could not find firmware in archive"), LOGERROR
);