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
|
|
|
|
* $Id: installzip.cpp 13990 2007-07-25 22:26:10Z 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-07-27 17:42:49 +00:00
|
|
|
#include "installzip.h"
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
#include "zip/zip.h"
|
2007-07-26 21:16:42 +00:00
|
|
|
#include "zip/unzip.h"
|
|
|
|
|
2007-07-27 17:42:49 +00:00
|
|
|
ZipInstaller::ZipInstaller(QObject* parent): QObject(parent)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-29 18:07:31 +00:00
|
|
|
void ZipInstaller::install(ProgressloggerInterface* dp)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
|
|
|
m_dp = dp;
|
|
|
|
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Downloading file %1.%2")
|
2007-07-26 21:06:09 +00:00
|
|
|
.arg(QFileInfo(m_url).baseName(), QFileInfo(m_url).completeSuffix()));
|
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
|
|
|
|
downloadFile.open();
|
|
|
|
m_file = downloadFile.fileName();
|
|
|
|
downloadFile.close();
|
|
|
|
// get the real file.
|
|
|
|
getter = new HttpGet(this);
|
2007-07-27 17:42:49 +00:00
|
|
|
getter->setProxy(m_proxy);
|
2007-07-26 21:16:42 +00:00
|
|
|
getter->setFile(&downloadFile);
|
2007-07-27 17:42:49 +00:00
|
|
|
getter->getFile(QUrl(m_url));
|
2007-07-26 21:16:42 +00:00
|
|
|
|
|
|
|
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
|
|
|
connect(getter, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool)));
|
|
|
|
connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
|
2007-07-29 18:07:31 +00:00
|
|
|
connect(m_dp, SIGNAL(aborted()), getter, SLOT(abort()));
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 17:42:49 +00:00
|
|
|
void ZipInstaller::downloadRequestFinished(int id, bool error)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
2007-07-26 21:06:09 +00:00
|
|
|
qDebug() << "Install::downloadRequestFinished" << id << error;
|
|
|
|
qDebug() << "error:" << getter->errorString();
|
|
|
|
|
2007-07-26 21:16:42 +00:00
|
|
|
downloadDone(error);
|
|
|
|
}
|
|
|
|
|
2007-07-27 17:42:49 +00:00
|
|
|
void ZipInstaller::downloadDone(bool error)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
2007-07-26 21:06:09 +00:00
|
|
|
qDebug() << "Install::downloadDone, error:" << error;
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
// update progress bar
|
2007-07-27 17:42:49 +00:00
|
|
|
|
2007-07-29 18:07:31 +00:00
|
|
|
int max = m_dp->getProgressMax();
|
2007-07-26 21:06:09 +00:00
|
|
|
if(max == 0) {
|
|
|
|
max = 100;
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->setProgressMax(max);
|
2007-07-26 21:06:09 +00:00
|
|
|
}
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->setProgressValue(max);
|
2007-07-26 21:06:09 +00:00
|
|
|
if(getter->httpResponse() != 200) {
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Download error: received HTTP error %1.").arg(getter->httpResponse()));
|
|
|
|
m_dp->abort();
|
2007-07-26 21:06:09 +00:00
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(error) {
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Download error: %1").arg(getter->errorString()));
|
|
|
|
m_dp->abort();
|
2007-07-26 21:06:09 +00:00
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-29 18:07:31 +00:00
|
|
|
else m_dp->addItem(tr("Download finished."));
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
// unzip downloaded file
|
|
|
|
qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint;
|
|
|
|
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Extracting file."));
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
qDebug() << "file to unzip: " << m_file;
|
|
|
|
UnZip::ErrorCode ec;
|
|
|
|
UnZip uz;
|
|
|
|
ec = uz.openArchive(m_file);
|
|
|
|
if(ec != UnZip::Ok) {
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Opening archive failed: %1.")
|
2007-07-26 21:06:09 +00:00
|
|
|
.arg(uz.formatError(ec)));
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->abort();
|
2007-07-26 21:06:09 +00:00
|
|
|
emit done(false);
|
|
|
|
return;
|
2007-07-26 21:16:42 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
ec = uz.extractAll(m_mountpoint);
|
|
|
|
if(ec != UnZip::Ok) {
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Extracting failed: %1.")
|
2007-07-26 21:06:09 +00:00
|
|
|
.arg(uz.formatError(ec)));
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->abort();
|
2007-07-26 21:06:09 +00:00
|
|
|
emit done(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("creating installation log"));
|
2007-07-26 21:16:42 +00:00
|
|
|
|
2007-07-26 21:06:09 +00:00
|
|
|
QStringList zipContents = uz.fileList();
|
|
|
|
|
|
|
|
QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1);
|
|
|
|
}
|
|
|
|
installlog.endGroup();
|
|
|
|
|
|
|
|
// remove temporary file
|
|
|
|
downloadFile.remove();
|
|
|
|
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->addItem(tr("Extraction finished successfully."));
|
|
|
|
m_dp->abort();
|
2007-07-26 21:16:42 +00:00
|
|
|
emit done(false);
|
|
|
|
}
|
|
|
|
|
2007-07-27 17:42:49 +00:00
|
|
|
void ZipInstaller::updateDataReadProgress(int read, int total)
|
2007-07-26 21:16:42 +00:00
|
|
|
{
|
2007-07-29 18:07:31 +00:00
|
|
|
m_dp->setProgressMax(total);
|
|
|
|
m_dp->setProgressValue(read);
|
2007-07-26 21:16:42 +00:00
|
|
|
qDebug() << "progress:" << read << "/" << total;
|
|
|
|
|
|
|
|
}
|
|
|
|
|