2008-09-28 17:02:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Dominik Riebeling
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
|
|
|
#include "bootloaderinstallbase.h"
|
|
|
|
#include "utils.h"
|
2012-01-15 22:20:17 +00:00
|
|
|
#include "ziputil.h"
|
2013-03-11 17:57:11 +00:00
|
|
|
#include "mspackutil.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2008-09-28 17:02:36 +00:00
|
|
|
|
2009-11-22 22:13:25 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#endif
|
|
|
|
|
2010-05-07 18:18:43 +00:00
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
BootloaderInstallBase::BootloaderType BootloaderInstallBase::installed(void)
|
|
|
|
{
|
|
|
|
return BootloaderUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BootloaderInstallBase::Capabilities BootloaderInstallBase::capabilities(void)
|
|
|
|
{
|
2020-07-27 18:42:16 +00:00
|
|
|
return Capabilities();
|
2008-09-28 17:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BootloaderInstallBase::downloadBlStart(QUrl source)
|
|
|
|
{
|
|
|
|
m_http.setFile(&m_tempfile);
|
|
|
|
m_http.setCache(true);
|
2020-11-21 09:21:31 +00:00
|
|
|
connect(&m_http, &HttpGet::done, this, &BootloaderInstallBase::downloadBlFinish);
|
2008-09-28 17:02:36 +00:00
|
|
|
// connect the http read signal to our logProgess *signal*
|
|
|
|
// to immediately emit it without any helper function.
|
2020-11-21 09:21:31 +00:00
|
|
|
connect(&m_http, &HttpGet::dataReadProgress,
|
|
|
|
this, &BootloaderInstallBase::logProgress);
|
2008-09-28 17:02:36 +00:00
|
|
|
m_http.getFile(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BootloaderInstallBase::downloadReqFinished(int id, bool error)
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Download Request" << id
|
|
|
|
<< "finished, error:" << m_http.errorString();
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
downloadBlFinish(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BootloaderInstallBase::downloadBlFinish(bool error)
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Downloading bootloader finished, error:"
|
|
|
|
<< error;
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
// update progress bar
|
|
|
|
emit logProgress(100, 100);
|
|
|
|
|
|
|
|
if(m_http.httpResponse() != 200) {
|
|
|
|
emit logItem(tr("Download error: received HTTP error %1.")
|
|
|
|
.arg(m_http.errorString()), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(error) {
|
|
|
|
emit logItem(tr("Download error: %1")
|
2013-01-13 17:42:11 +00:00
|
|
|
.arg(m_http.errorString()), LOGERROR);
|
2008-09-28 17:02:36 +00:00
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(m_http.isCached())
|
2010-01-10 17:13:32 +00:00
|
|
|
emit logItem(tr("Download finished (cache used)."), LOGOK);
|
2008-09-28 17:02:36 +00:00
|
|
|
else
|
2010-01-10 17:13:32 +00:00
|
|
|
emit logItem(tr("Download finished."), LOGOK);
|
2008-09-28 17:02:36 +00:00
|
|
|
|
2009-01-08 17:16:53 +00:00
|
|
|
QCoreApplication::processEvents();
|
2008-09-28 17:02:36 +00:00
|
|
|
m_blversion = m_http.timestamp();
|
|
|
|
emit downloadDone();
|
|
|
|
}
|
|
|
|
|
2012-05-01 08:09:14 +00:00
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
void BootloaderInstallBase::installBlfile(void)
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "installBlFile(void)";
|
2008-09-28 17:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-08 22:56:27 +00:00
|
|
|
void BootloaderInstallBase::progressAborted(void)
|
|
|
|
{
|
|
|
|
LOG_INFO() << "progressAborted(void)";
|
|
|
|
emit installAborted();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
//! @brief backup OF file.
|
|
|
|
//! @param to folder to write backup file to. Folder will get created.
|
|
|
|
//! @return true on success, false on error.
|
|
|
|
bool BootloaderInstallBase::backup(QString to)
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Backing up bootloader file";
|
2008-09-28 17:02:36 +00:00
|
|
|
QDir targetDir(".");
|
|
|
|
emit logItem(tr("Creating backup of original firmware file."), LOGINFO);
|
|
|
|
if(!targetDir.mkpath(to)) {
|
|
|
|
emit logItem(tr("Creating backup folder failed"), LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QString tofile = to + "/" + QFileInfo(m_blfile).fileName();
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "trying to backup" << m_blfile << "to" << tofile;
|
2010-04-02 21:24:19 +00:00
|
|
|
if(!QFile::copy(Utils::resolvePathCase(m_blfile), tofile)) {
|
2008-09-28 17:02:36 +00:00
|
|
|
emit logItem(tr("Creating backup copy failed."), LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
emit logItem(tr("Backup created."), LOGOK);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! @brief log installation to logfile.
|
|
|
|
//! @param mode action to perform. 0: add to log, 1: remove from log.
|
|
|
|
//! @return 0 on success
|
|
|
|
int BootloaderInstallBase::logInstall(LogMode mode)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
QString section = m_blurl.path().section('/', -1);
|
|
|
|
QSettings s(m_logfile, QSettings::IniFormat, this);
|
|
|
|
emit logItem(tr("Creating installation log"), LOGINFO);
|
|
|
|
|
|
|
|
if(mode == LogAdd) {
|
|
|
|
s.setValue("Bootloader/" + section, m_blversion.toString(Qt::ISODate));
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Writing log, version:"
|
|
|
|
<< m_blversion.toString(Qt::ISODate);
|
2008-09-28 17:02:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
s.remove("Bootloader/" + section);
|
|
|
|
}
|
|
|
|
s.sync();
|
|
|
|
|
2009-01-08 17:16:53 +00:00
|
|
|
emit logItem(tr("Installation log created"), LOGOK);
|
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-22 22:13:25 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
void BootloaderInstallBase::waitRemount()
|
|
|
|
{
|
|
|
|
m_remountTries = 600;
|
|
|
|
emit logItem(tr("Waiting for system to remount player"), LOGINFO);
|
|
|
|
|
|
|
|
QTimer::singleShot(100, this, SLOT(checkRemount()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void BootloaderInstallBase::checkRemount()
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
if(m_remountTries--) {
|
|
|
|
int status = 0;
|
|
|
|
// check if device has been remounted
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
int num;
|
|
|
|
struct statfs *mntinf;
|
|
|
|
|
|
|
|
num = getmntinfo(&mntinf, MNT_WAIT);
|
|
|
|
while(num--) {
|
|
|
|
if(QString(mntinf->f_mntfromname).startsWith(m_remountDevice)
|
|
|
|
&& QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive))
|
|
|
|
status = 1;
|
|
|
|
mntinf++;
|
|
|
|
}
|
|
|
|
if(!status) {
|
|
|
|
// still not remounted, restart timer.
|
|
|
|
QTimer::singleShot(500, this, SLOT(checkRemount()));
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Player not remounted yet" << m_remountDevice;
|
2009-11-22 22:13:25 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit logItem(tr("Player remounted"), LOGINFO);
|
|
|
|
emit remounted(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit logItem(tr("Timeout on remount"), LOGERROR);
|
|
|
|
emit remounted(false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-09 10:57:39 +00:00
|
|
|
//! @brief set list of possible bootloader files and pick the existing one.
|
|
|
|
//! @param sl list of possible bootloader files.
|
|
|
|
void BootloaderInstallBase::setBlFile(QStringList sl)
|
|
|
|
{
|
|
|
|
// figue which of the possible bootloader filenames is correct.
|
|
|
|
for(int a = 0; a < sl.size(); a++) {
|
2010-04-02 21:24:19 +00:00
|
|
|
if(!Utils::resolvePathCase(sl.at(a)).isEmpty()) {
|
2009-08-09 10:57:39 +00:00
|
|
|
m_blfile = sl.at(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_blfile.isEmpty()) {
|
|
|
|
m_blfile = sl.at(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 08:09:14 +00:00
|
|
|
|
2012-01-15 22:20:17 +00:00
|
|
|
bool BootloaderInstallBase::setOfFile(QString of, QStringList blfile)
|
|
|
|
{
|
|
|
|
bool found = false;
|
2020-08-23 14:51:44 +00:00
|
|
|
ArchiveUtil *util = nullptr;
|
|
|
|
|
|
|
|
// check if we're actually looking for a zip file. If so we must avoid
|
|
|
|
// trying to unzip it.
|
|
|
|
bool wantZip = false;
|
|
|
|
for (int i = 0; i < blfile.size(); i++)
|
|
|
|
{
|
|
|
|
if (blfile.at(i).endsWith(".zip"))
|
|
|
|
wantZip = true;
|
|
|
|
}
|
2013-03-11 17:57:11 +00:00
|
|
|
|
|
|
|
// try ZIP first
|
|
|
|
ZipUtil *zu = new ZipUtil(this);
|
2020-08-23 14:51:44 +00:00
|
|
|
if(zu->open(of) && !wantZip)
|
2013-03-11 17:57:11 +00:00
|
|
|
{
|
2012-01-15 22:20:17 +00:00
|
|
|
emit logItem(tr("Zip file format detected"), LOGINFO);
|
2013-03-11 17:57:11 +00:00
|
|
|
util = zu;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete zu;
|
|
|
|
|
|
|
|
// if ZIP failed, try CAB
|
2020-11-19 19:36:57 +00:00
|
|
|
if(util == nullptr)
|
2013-03-11 17:57:11 +00:00
|
|
|
{
|
|
|
|
MsPackUtil *msu = new MsPackUtil(this);
|
|
|
|
if(msu->open(of))
|
|
|
|
{
|
|
|
|
emit logItem(tr("CAB file format detected"), LOGINFO);
|
|
|
|
util = msu;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete msu;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the file set is in zip format
|
|
|
|
if(util) {
|
|
|
|
QStringList contents = util->files();
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "archive contains:" << contents;
|
2012-01-15 22:20:17 +00:00
|
|
|
for(int i = 0; i < blfile.size(); ++i) {
|
|
|
|
// strip any path, we don't know the structure in the zip
|
|
|
|
QString f = QFileInfo(blfile.at(i)).fileName();
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "searching archive for" << f;
|
2012-06-23 09:53:02 +00:00
|
|
|
// contents.indexOf() works case sensitive. Since the filename
|
|
|
|
// casing is unknown (and might change) do this manually.
|
|
|
|
// FIXME: support files in folders
|
|
|
|
for(int j = 0; j < contents.size(); ++j) {
|
|
|
|
if(contents.at(j).compare(f, Qt::CaseInsensitive) == 0) {
|
|
|
|
found = true;
|
|
|
|
emit logItem(tr("Extracting firmware %1 from archive")
|
|
|
|
.arg(f), LOGINFO);
|
|
|
|
// store in class temporary file
|
|
|
|
m_tempof.open();
|
|
|
|
m_offile = m_tempof.fileName();
|
|
|
|
m_tempof.close();
|
2013-03-11 17:57:11 +00:00
|
|
|
if(!util->extractArchive(m_offile, contents.at(j))) {
|
2012-06-23 09:53:02 +00:00
|
|
|
emit logItem(tr("Error extracting firmware from archive"), LOGERROR);
|
|
|
|
found = false;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-15 22:20:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found) {
|
|
|
|
emit logItem(tr("Could not find firmware in archive"), LOGERROR);
|
|
|
|
}
|
2013-03-11 17:57:11 +00:00
|
|
|
delete util;
|
2012-01-15 22:20:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_offile = of;
|
|
|
|
found = true;
|
|
|
|
}
|
2013-03-11 17:57:11 +00:00
|
|
|
|
2012-01-15 22:20:17 +00:00
|
|
|
return found;
|
|
|
|
}
|
2012-05-01 08:09:14 +00:00
|
|
|
|