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-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-12-13 20:09:31 +00:00
|
|
|
#include "utils.h"
|
2011-03-25 22:16:12 +00:00
|
|
|
#include "ziputil.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2020-09-26 15:51:33 +00:00
|
|
|
ZipInstaller::ZipInstaller(QObject* parent) :
|
|
|
|
QObject(parent),
|
2020-11-19 19:36:57 +00:00
|
|
|
m_unzip(true), m_usecache(false), m_getter(nullptr)
|
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
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "initializing installation";
|
2009-05-02 18:50:31 +00:00
|
|
|
|
2020-09-26 15:51:33 +00:00
|
|
|
m_runner = 0;
|
2007-08-14 23:11:46 +00:00
|
|
|
connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
|
2020-09-26 15:51:33 +00:00
|
|
|
m_url = m_urllist.at(m_runner);
|
|
|
|
m_logsection = m_loglist.at(m_runner);
|
|
|
|
m_logver = m_verlist.at(m_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()
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Aborted";
|
2009-05-02 18:50:31 +00:00
|
|
|
emit internalAborted();
|
2007-08-14 23:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZipInstaller::installContinue()
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "continuing installation";
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2020-09-26 15:51:33 +00:00
|
|
|
m_runner++; // this gets called when a install finished, so increase first.
|
|
|
|
LOG_INFO() << "runner done:" << m_runner << "/" << m_urllist.size();
|
|
|
|
if(m_runner < m_urllist.size()) {
|
2010-01-10 17:13:32 +00:00
|
|
|
emit logItem(tr("done."), LOGOK);
|
2020-09-26 15:51:33 +00:00
|
|
|
m_url = m_urllist.at(m_runner);
|
|
|
|
m_logsection = m_loglist.at(m_runner);
|
|
|
|
if(m_runner < m_verlist.size()) m_logver = m_verlist.at(m_runner);
|
2012-05-23 19:05:28 +00:00
|
|
|
else m_logver = "";
|
2007-08-14 23:11:46 +00:00
|
|
|
installStart();
|
|
|
|
}
|
|
|
|
else {
|
2012-06-26 16:41:25 +00:00
|
|
|
emit logItem(tr("Package installation finished successfully."), LOGOK);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(false);
|
2007-08-14 23:11:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZipInstaller::installStart()
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "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.
|
2013-03-09 18:37:40 +00:00
|
|
|
m_downloadFile = new QTemporaryFile(this);
|
|
|
|
m_downloadFile->open();
|
|
|
|
m_file = m_downloadFile->fileName();
|
|
|
|
m_downloadFile->close();
|
2007-07-26 21:06:09 +00:00
|
|
|
// get the real file.
|
2020-11-19 19:36:57 +00:00
|
|
|
if(m_getter != nullptr) m_getter->deleteLater();
|
2013-03-09 18:37:40 +00:00
|
|
|
m_getter = new HttpGet(this);
|
2008-03-05 21:12:24 +00:00
|
|
|
if(m_usecache) {
|
2013-03-09 18:37:40 +00:00
|
|
|
m_getter->setCache(true);
|
2007-08-27 17:40:35 +00:00
|
|
|
}
|
2013-03-09 18:37:40 +00:00
|
|
|
m_getter->setFile(m_downloadFile);
|
2009-05-02 18:50:31 +00:00
|
|
|
|
2013-03-09 18:37:40 +00:00
|
|
|
connect(m_getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
|
|
|
connect(m_getter, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(logProgress(int, int)));
|
|
|
|
connect(this, SIGNAL(internalAborted()), m_getter, SLOT(abort()));
|
2009-05-02 18:50:31 +00:00
|
|
|
|
2013-03-09 18:37:40 +00:00
|
|
|
m_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
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "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);
|
2013-03-09 18:37:40 +00:00
|
|
|
if(m_getter->httpResponse() != 200 && !m_getter->isCached()) {
|
2020-11-13 21:02:28 +00:00
|
|
|
emit logItem(tr("Download error: received HTTP error %1\n%2")
|
|
|
|
.arg(m_getter->httpResponse()).arg(m_getter->errorString()),
|
|
|
|
LOGERROR);
|
2008-04-01 20:22:45 +00:00
|
|
|
emit done(true);
|
2007-07-26 21:06:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-09 18:37:40 +00:00
|
|
|
if(m_getter->isCached())
|
2010-01-10 17:13:32 +00:00
|
|
|
emit logItem(tr("Cached file used."), LOGINFO);
|
2007-07-26 21:06:09 +00:00
|
|
|
if(error) {
|
2013-03-09 18:37:40 +00:00
|
|
|
emit logItem(tr("Download error: %1").arg(m_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-10 17:13:32 +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
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "about to unzip" << m_file << "to" << m_mountpoint;
|
2007-08-09 16:06:27 +00:00
|
|
|
|
2010-01-10 17:13:32 +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
|
|
|
|
2011-03-25 22:16:12 +00:00
|
|
|
ZipUtil zip(this);
|
|
|
|
connect(&zip, SIGNAL(logProgress(int, int)), this, SIGNAL(logProgress(int, int)));
|
|
|
|
connect(&zip, SIGNAL(logItem(QString, int)), this, SIGNAL(logItem(QString, int)));
|
|
|
|
zip.open(m_file, QuaZip::mdUnzip);
|
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).
|
2011-04-02 19:03:50 +00:00
|
|
|
if((qint64)Utils::filesystemFree(m_mountpoint)
|
2020-10-04 09:26:40 +00:00
|
|
|
< (zip.totalUncompressedSize(
|
|
|
|
Utils::filesystemSize(m_mountpoint, Utils::FilesystemClusterSize))
|
2011-07-26 20:54:44 +00:00
|
|
|
+ 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;
|
|
|
|
}
|
2011-03-25 22:16:12 +00:00
|
|
|
zipContents = zip.files();
|
|
|
|
if(!zip.extractArchive(m_mountpoint)) {
|
|
|
|
emit logItem(tr("Extraction failed!"), 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;
|
|
|
|
}
|
2011-03-25 22:16:12 +00:00
|
|
|
zip.close();
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
2007-08-09 16:06:27 +00:00
|
|
|
else {
|
2020-09-26 15:51:33 +00:00
|
|
|
if (m_target.isEmpty())
|
|
|
|
m_target = QUrl(m_url).fileName();
|
|
|
|
QString destfile = m_mountpoint + "/" + m_target;
|
2007-08-09 16:06:27 +00:00
|
|
|
// only copy the downloaded file to the output location / name
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Installing file."), LOGINFO);
|
2020-09-26 15:51:33 +00:00
|
|
|
LOG_INFO() << "saving downloaded file (no extraction) to" << destfile;
|
2007-08-09 16:06:27 +00:00
|
|
|
|
2013-03-09 18:37:40 +00:00
|
|
|
m_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
|
2020-09-26 15:51:33 +00:00
|
|
|
QString path = QFileInfo(destfile).absolutePath();
|
2007-08-09 16:06:27 +00:00
|
|
|
QDir p;
|
|
|
|
p.mkpath(path);
|
|
|
|
// QFile::copy() doesn't overwrite files, so remove old one first
|
2020-09-26 15:51:33 +00:00
|
|
|
// TODO: compare old and new file and fail if those are different.
|
|
|
|
QFile(destfile).remove();
|
|
|
|
if(!m_downloadFile->copy(destfile)) {
|
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
|
2011-03-25 22:16:12 +00:00
|
|
|
zipContents.append(m_target);
|
2007-07-26 21:06:09 +00:00
|
|
|
}
|
2012-05-23 19:05:28 +00:00
|
|
|
if(m_logver.isEmpty()) {
|
|
|
|
// if no version info is set use the timestamp of the server file.
|
2013-03-09 18:37:40 +00:00
|
|
|
m_logver = m_getter->timestamp().toString(Qt::ISODate);
|
2012-05-23 19:05:28 +00:00
|
|
|
}
|
2007-07-26 21:06:09 +00:00
|
|
|
|
2009-05-02 18:50:31 +00:00
|
|
|
emit logItem(tr("Creating installation log"),LOGINFO);
|
2020-11-19 19:36:57 +00:00
|
|
|
QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, nullptr);
|
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
|
|
|
|