mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
extend ZipInstaller to support installing of multiple files at once (for use by the theme installation).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14348 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
07e4ddb79d
commit
498bae30b7
3 changed files with 62 additions and 22 deletions
|
|
@ -110,7 +110,6 @@ void Install::accept()
|
||||||
userSettings->sync();
|
userSettings->sync();
|
||||||
|
|
||||||
installer = new ZipInstaller(this);
|
installer = new ZipInstaller(this);
|
||||||
installer->setFilename(fileName);
|
|
||||||
installer->setUrl(file);
|
installer->setUrl(file);
|
||||||
installer->setProxy(proxy);
|
installer->setProxy(proxy);
|
||||||
installer->setLogSection("rockboxbase");
|
installer->setLogSection("rockboxbase");
|
||||||
|
|
|
||||||
|
|
@ -28,21 +28,61 @@ ZipInstaller::ZipInstaller(QObject* parent): QObject(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ZipInstaller::install(ProgressloggerInterface* dp)
|
void ZipInstaller::install(ProgressloggerInterface *dp)
|
||||||
{
|
{
|
||||||
|
qDebug() << "install(ProgressloggerInterface*)";
|
||||||
m_dp = dp;
|
m_dp = dp;
|
||||||
|
runner = 0;
|
||||||
|
connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
|
||||||
|
m_url = m_urllist.at(runner);
|
||||||
|
m_logsection = m_loglist.at(runner);
|
||||||
|
installStart();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ZipInstaller::installContinue()
|
||||||
|
{
|
||||||
|
qDebug() << "installContinue()";
|
||||||
|
|
||||||
|
runner++; // this gets called when a install finished, so increase first.
|
||||||
|
if(runner < m_urllist.size()) {
|
||||||
|
qDebug() << "==> runner at" << runner;
|
||||||
|
m_dp->addItem(tr("done."), LOGOK);
|
||||||
|
m_url = m_urllist.at(runner);
|
||||||
|
m_logsection = m_loglist.at(runner);
|
||||||
|
installStart();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_dp->addItem(tr("Installation finished successfully."),LOGOK);
|
||||||
|
m_dp->abort();
|
||||||
|
|
||||||
|
emit done(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ZipInstaller::installStart()
|
||||||
|
{
|
||||||
|
qDebug() << "installStart()";
|
||||||
|
|
||||||
m_dp->addItem(tr("Downloading file %1.%2")
|
m_dp->addItem(tr("Downloading file %1.%2")
|
||||||
.arg(QFileInfo(m_url).baseName(), QFileInfo(m_url).completeSuffix()),LOGINFO);
|
.arg(QFileInfo(m_url).baseName(), QFileInfo(m_url).completeSuffix()),LOGINFO);
|
||||||
|
|
||||||
// temporary file needs to be opened to get the filename
|
// temporary file needs to be opened to get the filename
|
||||||
downloadFile.open();
|
// make sure to get a fresh one on each run.
|
||||||
m_file = downloadFile.fileName();
|
// making this a parent of the temporary file ensures the file gets deleted
|
||||||
downloadFile.close();
|
// after the class object gets destroyed.
|
||||||
|
downloadFile = new QTemporaryFile(this);
|
||||||
|
downloadFile->open();
|
||||||
|
m_file = downloadFile->fileName();
|
||||||
|
downloadFile->close();
|
||||||
// get the real file.
|
// get the real file.
|
||||||
getter = new HttpGet(this);
|
getter = new HttpGet(this);
|
||||||
getter->setProxy(m_proxy);
|
getter->setProxy(m_proxy);
|
||||||
getter->setFile(&downloadFile);
|
getter->setFile(downloadFile);
|
||||||
getter->getFile(QUrl(m_url));
|
getter->getFile(QUrl(m_url));
|
||||||
|
|
||||||
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
||||||
|
|
@ -51,6 +91,7 @@ void ZipInstaller::install(ProgressloggerInterface* dp)
|
||||||
connect(m_dp, SIGNAL(aborted()), getter, SLOT(abort()));
|
connect(m_dp, SIGNAL(aborted()), getter, SLOT(abort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ZipInstaller::downloadRequestFinished(int id, bool error)
|
void ZipInstaller::downloadRequestFinished(int id, bool error)
|
||||||
{
|
{
|
||||||
qDebug() << "Install::downloadRequestFinished" << id << error;
|
qDebug() << "Install::downloadRequestFinished" << id << error;
|
||||||
|
|
@ -59,6 +100,7 @@ void ZipInstaller::downloadRequestFinished(int id, bool error)
|
||||||
downloadDone(error);
|
downloadDone(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ZipInstaller::downloadDone(bool error)
|
void ZipInstaller::downloadDone(bool error)
|
||||||
{
|
{
|
||||||
qDebug() << "Install::downloadDone, error:" << error;
|
qDebug() << "Install::downloadDone, error:" << error;
|
||||||
|
|
@ -99,7 +141,6 @@ void ZipInstaller::downloadDone(bool error)
|
||||||
m_dp->addItem(tr("Opening archive failed: %1.")
|
m_dp->addItem(tr("Opening archive failed: %1.")
|
||||||
.arg(uz.formatError(ec)),LOGERROR);
|
.arg(uz.formatError(ec)),LOGERROR);
|
||||||
m_dp->abort();
|
m_dp->abort();
|
||||||
downloadFile.remove();
|
|
||||||
emit done(false);
|
emit done(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +150,6 @@ void ZipInstaller::downloadDone(bool error)
|
||||||
m_dp->addItem(tr("Extracting failed: %1.")
|
m_dp->addItem(tr("Extracting failed: %1.")
|
||||||
.arg(uz.formatError(ec)),LOGERROR);
|
.arg(uz.formatError(ec)),LOGERROR);
|
||||||
m_dp->abort();
|
m_dp->abort();
|
||||||
downloadFile.remove();
|
|
||||||
emit done(false);
|
emit done(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -121,17 +161,16 @@ void ZipInstaller::downloadDone(bool error)
|
||||||
m_dp->addItem(tr("Installing file."), LOGINFO);
|
m_dp->addItem(tr("Installing file."), LOGINFO);
|
||||||
qDebug() << "saving downloaded file (no extraction)";
|
qDebug() << "saving downloaded file (no extraction)";
|
||||||
|
|
||||||
downloadFile.open(); // copy fails if file is not opened (filename issue?)
|
downloadFile->open(); // copy fails if file is not opened (filename issue?)
|
||||||
// make sure the required path is existing
|
// make sure the required path is existing
|
||||||
QString path = QFileInfo(m_mountpoint + m_target).absolutePath();
|
QString path = QFileInfo(m_mountpoint + m_target).absolutePath();
|
||||||
QDir p;
|
QDir p;
|
||||||
p.mkpath(path);
|
p.mkpath(path);
|
||||||
// QFile::copy() doesn't overwrite files, so remove old one first
|
// QFile::copy() doesn't overwrite files, so remove old one first
|
||||||
QFile(m_mountpoint + m_target).remove();
|
QFile(m_mountpoint + m_target).remove();
|
||||||
if(!downloadFile.copy(m_mountpoint + m_target)) {
|
if(!downloadFile->copy(m_mountpoint + m_target)) {
|
||||||
m_dp->addItem(tr("Installing file failed."), LOGERROR);
|
m_dp->addItem(tr("Installing file failed."), LOGERROR);
|
||||||
m_dp->abort();
|
m_dp->abort();
|
||||||
downloadFile.remove();
|
|
||||||
emit done(false);
|
emit done(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -149,13 +188,8 @@ void ZipInstaller::downloadDone(bool error)
|
||||||
installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1);
|
installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1);
|
||||||
}
|
}
|
||||||
installlog.endGroup();
|
installlog.endGroup();
|
||||||
|
|
||||||
// remove temporary file
|
|
||||||
downloadFile.remove();
|
|
||||||
|
|
||||||
m_dp->addItem(tr("Installation finished successfully."),LOGOK);
|
emit cont();
|
||||||
m_dp->abort();
|
|
||||||
emit done(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipInstaller::updateDataReadProgress(int read, int total)
|
void ZipInstaller::updateDataReadProgress(int read, int total)
|
||||||
|
|
|
||||||
|
|
@ -37,29 +37,36 @@ public:
|
||||||
~ZipInstaller(){}
|
~ZipInstaller(){}
|
||||||
void install(ProgressloggerInterface* dp);
|
void install(ProgressloggerInterface* dp);
|
||||||
void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;}
|
void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;}
|
||||||
void setFilename(QString filename){m_file = filename;}
|
void setUrl(QString url){m_urllist = QStringList(url);}
|
||||||
void setUrl(QString url){m_url = url;}
|
void setUrl(QStringList url) { m_urllist = url; }
|
||||||
void setProxy(QUrl proxy) {m_proxy= proxy;}
|
void setProxy(QUrl proxy) {m_proxy= proxy;}
|
||||||
void setLogSection(QString name) {m_logsection = name;}
|
void setLogSection(QString name) {m_loglist = QStringList(name);}
|
||||||
|
void setLogSection(QStringList name) { m_loglist = name; }
|
||||||
void setUnzip(bool i) { m_unzip = i; }
|
void setUnzip(bool i) { m_unzip = i; }
|
||||||
void setTarget(QString t) { m_target = t; }
|
void setTarget(QString t) { m_target = t; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void done(bool error);
|
void done(bool error);
|
||||||
|
void cont();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateDataReadProgress(int, int);
|
void updateDataReadProgress(int, int);
|
||||||
void downloadDone(bool);
|
void downloadDone(bool);
|
||||||
void downloadRequestFinished(int, bool);
|
void downloadRequestFinished(int, bool);
|
||||||
|
void installStart(void);
|
||||||
|
void installContinue(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_url,m_file,m_mountpoint,m_logsection;
|
void installSingle(ProgressloggerInterface *dp);
|
||||||
|
QString m_url, m_file, m_mountpoint, m_logsection;
|
||||||
|
QStringList m_urllist, m_loglist;
|
||||||
QUrl m_proxy;
|
QUrl m_proxy;
|
||||||
bool m_unzip;
|
bool m_unzip;
|
||||||
QString m_target;
|
QString m_target;
|
||||||
|
int runner;
|
||||||
|
|
||||||
HttpGet *getter;
|
HttpGet *getter;
|
||||||
QTemporaryFile downloadFile;
|
QTemporaryFile *downloadFile;
|
||||||
|
|
||||||
ProgressloggerInterface* m_dp;
|
ProgressloggerInterface* m_dp;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue