2007-07-26 21:16:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
2007-07-26 21:06:09 +00:00
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
2007-07-27 17:42:49 +00:00
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
2007-08-23 22:11:50 +00:00
|
|
|
* $Id$
|
2007-07-26 21:06:09 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2007-07-26 21:16:42 +00:00
|
|
|
****************************************************************************/
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
#include <QtCore>
|
2009-04-27 19:37:34 +00:00
|
|
|
#include "zipinstaller.h"
|
2008-04-06 18:12:56 +00:00
|
|
|
#include "rbunzip.h"
|
2008-12-13 20:09:31 +00:00
|
|
|
#include "utils.h"
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-09-15 22:57:07 +00:00
|
|
|
ZipInstaller::ZipInstaller(QObject* parent): QObject(parent)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
2007-08-09 16:06:27 +00:00
|
|
|
m_unzip = true;
|
2008-03-05 21:12:24 +00:00
|
|
|
m_usecache = false;
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
void ZipInstaller::install()
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
2009-06-16 18:45:20 +00:00
|
|
|
qDebug() << "[ZipInstall] initializing installation";
|
2009-05-02 18:50:31 +00:00
|
|
|
|
2007-08-14 23:11:46 +00:00
|
|
|
runner = 0;
|
|
|
|
connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
|
|
|
|
m_url = m_urllist.at(runner);
|
|
|
|
m_logsection = m_loglist.at(runner);
|
2007-08-26 16:03:56 +00:00
|
|
|
m_logver = m_verlist.at(runner);
|
2007-08-14 23:11:46 +00:00
|
|
|
installStart();
|
2009-05-02 18:50:31 +00:00
|
|
|
}
|
2007-08-14 23:11:46 +00:00
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
|
|
|
|
void ZipInstaller::abort()
|
|
|
|
{
|
|
|
|
qDebug() << "[ZipInstall] Aborted";
|
|
|
|
emit internalAborted();
|
2007-08-14 23:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZipInstaller::installContinue()
|
|
|
|
{
|
2009-06-16 18:45:20 +00:00
|
|
|
qDebug() << "[ZipInstall] continuing installation";
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-14 23:11:46 +00:00
|
|
|
runner++; // this gets called when a install finished, so increase first.
|
2009-05-02 18:50:31 +00:00
|
|
|
qDebug() << "[ZipInstall] runner done:" << runner << "/" << m_urllist.size();
|
2007-08-14 23:11:46 +00:00
|
|
|
if(runner < m_urllist.size()) {
|
2010-01-03 20:17:36 +00:00
|
|
|
emit logItem(tr("Done"), LOGOK);
|
2007-08-14 23:11:46 +00:00
|
|
|
m_url = m_urllist.at(runner);
|
|
|
|
m_logsection = m_loglist.at(runner);
|
2007-08-26 16:03:56 +00:00
|
|
|
if(runner < m_verlist.size()) m_logver = m_verlist.at(runner);
|
|
|
|
else m_logver = "0";
|
2007-08-14 23:11:46 +00:00
|
|
|
installStart();
|
|
|
|
}
|
|
|
|
else {
|
2010-01-03 20:17:36 +00:00
|
|
|
emit logItem(tr("Installation finished successfully"), LOGOK);
|
2007-08-14 23:11:46 +00:00
|
|
|
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(false);
|
2007-08-14 23:11:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZipInstaller::installStart()
|
|
|
|
{
|
2009-06-16 18:45:20 +00:00
|
|
|
qDebug() << "[ZipInstall] starting installation";
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Downloading file %1.%2").arg(QFileInfo(m_url).baseName(),
|
|
|
|
QFileInfo(m_url).completeSuffix()),LOGINFO);
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
// temporary file needs to be opened to get the filename
|
2007-08-14 23:11:46 +00:00
|
|
|
// make sure to get a fresh one on each run.
|
|
|
|
// making this a parent of the temporary file ensures the file gets deleted
|
|
|
|
// after the class object gets destroyed.
|
|
|
|
downloadFile = new QTemporaryFile(this);
|
|
|
|
downloadFile->open();
|
|
|
|
m_file = downloadFile->fileName();
|
|
|
|
downloadFile->close();
|
2007-07-26 21:06:09 +00:00
|
|
|
// get the real file.
|
|
|
|
getter = new HttpGet(this);
|
2008-03-05 21:12:24 +00:00
|
|
|
if(m_usecache) {
|
|
|
|
getter->setCache(true);
|
2007-08-27 17:40:35 +00:00
|
|
|
}
|
2007-08-14 23:11:46 +00:00
|
|
|
getter->setFile(downloadFile);
|
2009-05-02 18:50:31 +00:00
|
|
|
|
2007-07-26 21:16:42 +00:00
|
|
|
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
2009-05-02 18:50:31 +00:00
|
|
|
connect(getter, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(logProgress(int, int)));
|
|
|
|
connect(this, SIGNAL(internalAborted()), getter, SLOT(abort()));
|
|
|
|
|
2008-04-01 18:02:56 +00:00
|
|
|
getter->getFile(QUrl(m_url));
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
|
|
|
|
2007-08-14 23:11:46 +00:00
|
|
|
|
2007-07-27 17:42:49 +00:00
|
|
|
void ZipInstaller::downloadDone(bool error)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
2009-06-16 18:45:20 +00:00
|
|
|
qDebug() << "[ZipInstall] download done, error:" << error;
|
2007-08-09 16:06:27 +00:00
|
|
|
QStringList zipContents; // needed later
|
2007-07-26 21:06:09 +00:00
|
|
|
// update progress bar
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logProgress(1, 1);
|
2007-08-27 17:40:35 +00:00
|
|
|
if(getter->httpResponse() != 200 && !getter->isCached()) {
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Download error: received HTTP error %1.")
|
|
|
|
.arg(getter->httpResponse()),LOGERROR);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(true);
|
2007-07-26 21:06:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-05-02 18:50:31 +00:00
|
|
|
if(getter->isCached())
|
2010-01-03 20:17:36 +00:00
|
|
|
emit logItem(tr("Cached file used"), LOGINFO);
|
2007-07-26 21:06:09 +00:00
|
|
|
if(error) {
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Download error: %1").arg(getter->errorString()), LOGERROR);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(true);
|
2007-07-26 21:06:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-03 20:17:36 +00:00
|
|
|
else emit logItem(tr("Download finished"),LOGOK);
|
2008-02-10 18:25:49 +00:00
|
|
|
QCoreApplication::processEvents();
|
2007-08-09 16:06:27 +00:00
|
|
|
if(m_unzip) {
|
|
|
|
// unzip downloaded file
|
2009-05-02 18:50:31 +00:00
|
|
|
qDebug() << "[ZipInstall] about to unzip " << m_file << "to" << m_mountpoint;
|
2007-08-09 16:06:27 +00:00
|
|
|
|
2010-01-03 20:17:36 +00:00
|
|
|
emit logItem(tr("Extracting file"), LOGINFO);
|
2008-02-10 18:25:49 +00:00
|
|
|
QCoreApplication::processEvents();
|
2007-08-30 19:37:18 +00:00
|
|
|
|
2007-08-09 16:06:27 +00:00
|
|
|
UnZip::ErrorCode ec;
|
2008-04-06 18:12:56 +00:00
|
|
|
RbUnZip uz;
|
2009-05-02 18:50:31 +00:00
|
|
|
connect(&uz, SIGNAL(unzipProgress(int, int)), this, SIGNAL(logProgress(int, int)));
|
|
|
|
connect(this, SIGNAL(internalAborted()), &uz, SLOT(abortUnzip()));
|
2007-08-09 16:06:27 +00:00
|
|
|
ec = uz.openArchive(m_file);
|
|
|
|
if(ec != UnZip::Ok) {
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Opening archive failed: %1.")
|
2007-08-09 16:06:27 +00:00
|
|
|
.arg(uz.formatError(ec)),LOGERROR);
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logProgress(1, 1);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(true);
|
2007-08-09 16:06:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2008-12-13 20:09:31 +00:00
|
|
|
// check for free space. Make sure after installation will still be
|
|
|
|
// some room for operating (also includes calculation mistakes due to
|
|
|
|
// cluster sizes on the player).
|
|
|
|
if(filesystemFree(m_mountpoint) < (uz.totalSize() + 1000000)) {
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Not enough disk space! Aborting."), LOGERROR);
|
|
|
|
emit logProgress(1, 1);
|
2008-12-13 20:09:31 +00:00
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-06 18:12:56 +00:00
|
|
|
ec = uz.extractArchive(m_mountpoint);
|
|
|
|
// TODO: better handling of aborted unzip operation.
|
2007-08-09 16:06:27 +00:00
|
|
|
if(ec != UnZip::Ok) {
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Extracting failed: %1.")
|
2007-08-09 16:06:27 +00:00
|
|
|
.arg(uz.formatError(ec)),LOGERROR);
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logProgress(1, 1);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(true);
|
2007-08-09 16:06:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// prepare file list for log
|
|
|
|
zipContents = uz.fileList();
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
2007-08-09 16:06:27 +00:00
|
|
|
else {
|
|
|
|
// only copy the downloaded file to the output location / name
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Installing file."), LOGINFO);
|
|
|
|
qDebug() << "[ZipInstall] saving downloaded file (no extraction)";
|
2007-08-09 16:06:27 +00:00
|
|
|
|
2007-08-14 23:11:46 +00:00
|
|
|
downloadFile->open(); // copy fails if file is not opened (filename issue?)
|
2007-08-09 16:06:27 +00:00
|
|
|
// make sure the required path is existing
|
|
|
|
QString path = QFileInfo(m_mountpoint + m_target).absolutePath();
|
|
|
|
QDir p;
|
|
|
|
p.mkpath(path);
|
|
|
|
// QFile::copy() doesn't overwrite files, so remove old one first
|
|
|
|
QFile(m_mountpoint + m_target).remove();
|
2007-08-14 23:11:46 +00:00
|
|
|
if(!downloadFile->copy(m_mountpoint + m_target)) {
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Installing file failed."), LOGERROR);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(true);
|
2007-08-09 16:06:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-09 16:06:27 +00:00
|
|
|
// add file to log
|
2007-08-10 22:17:43 +00:00
|
|
|
zipContents.append( m_target);
|
2007-07-26 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Creating installation log"),LOGINFO);
|
2007-08-09 16:06:27 +00:00
|
|
|
QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
|
2007-07-26 21:06:09 +00:00
|
|
|
|
2007-07-27 17:42:49 +00:00
|
|
|
installlog.beginGroup(m_logsection);
|
2007-07-26 21:06:09 +00:00
|
|
|
for(int i = 0; i < zipContents.size(); i++)
|
|
|
|
{
|
2007-08-26 16:03:56 +00:00
|
|
|
installlog.setValue(zipContents.at(i), m_logver);
|
2007-07-26 21:06:09 +00:00
|
|
|
}
|
|
|
|
installlog.endGroup();
|
2007-08-26 16:44:23 +00:00
|
|
|
installlog.sync();
|
2007-07-26 21:06:09 +00:00
|
|
|
|
2007-08-14 23:11:46 +00:00
|
|
|
emit cont();
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
|