forked from len0rd/rockbox
rbutil: Code cleanup.
- Fix naming. - Remove non-functional functionality to set cache folder. - Use URL filename part when copying the file if target filename is not set. Change-Id: Ic9af59300f06d4309c6a4c9542d4f6079dd841c3
This commit is contained in:
parent
9d8bcbeb2a
commit
f1f72ff8df
2 changed files with 31 additions and 25 deletions
|
|
@ -22,11 +22,10 @@
|
||||||
#include "ziputil.h"
|
#include "ziputil.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
ZipInstaller::ZipInstaller(QObject* parent): QObject(parent)
|
ZipInstaller::ZipInstaller(QObject* parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_unzip(true), m_usecache(false), m_getter(0)
|
||||||
{
|
{
|
||||||
m_unzip = true;
|
|
||||||
m_usecache = false;
|
|
||||||
m_getter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -34,11 +33,11 @@ void ZipInstaller::install()
|
||||||
{
|
{
|
||||||
LOG_INFO() << "initializing installation";
|
LOG_INFO() << "initializing installation";
|
||||||
|
|
||||||
runner = 0;
|
m_runner = 0;
|
||||||
connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
|
connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
|
||||||
m_url = m_urllist.at(runner);
|
m_url = m_urllist.at(m_runner);
|
||||||
m_logsection = m_loglist.at(runner);
|
m_logsection = m_loglist.at(m_runner);
|
||||||
m_logver = m_verlist.at(runner);
|
m_logver = m_verlist.at(m_runner);
|
||||||
installStart();
|
installStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,13 +53,13 @@ void ZipInstaller::installContinue()
|
||||||
{
|
{
|
||||||
LOG_INFO() << "continuing installation";
|
LOG_INFO() << "continuing installation";
|
||||||
|
|
||||||
runner++; // this gets called when a install finished, so increase first.
|
m_runner++; // this gets called when a install finished, so increase first.
|
||||||
LOG_INFO() << "runner done:" << runner << "/" << m_urllist.size();
|
LOG_INFO() << "runner done:" << m_runner << "/" << m_urllist.size();
|
||||||
if(runner < m_urllist.size()) {
|
if(m_runner < m_urllist.size()) {
|
||||||
emit logItem(tr("done."), LOGOK);
|
emit logItem(tr("done."), LOGOK);
|
||||||
m_url = m_urllist.at(runner);
|
m_url = m_urllist.at(m_runner);
|
||||||
m_logsection = m_loglist.at(runner);
|
m_logsection = m_loglist.at(m_runner);
|
||||||
if(runner < m_verlist.size()) m_logver = m_verlist.at(runner);
|
if(m_runner < m_verlist.size()) m_logver = m_verlist.at(m_runner);
|
||||||
else m_logver = "";
|
else m_logver = "";
|
||||||
installStart();
|
installStart();
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +68,6 @@ void ZipInstaller::installContinue()
|
||||||
emit done(false);
|
emit done(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -158,18 +156,22 @@ void ZipInstaller::downloadDone(bool error)
|
||||||
zip.close();
|
zip.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (m_target.isEmpty())
|
||||||
|
m_target = QUrl(m_url).fileName();
|
||||||
|
QString destfile = m_mountpoint + "/" + m_target;
|
||||||
// only copy the downloaded file to the output location / name
|
// only copy the downloaded file to the output location / name
|
||||||
emit logItem(tr("Installing file."), LOGINFO);
|
emit logItem(tr("Installing file."), LOGINFO);
|
||||||
LOG_INFO() << "saving downloaded file (no extraction)";
|
LOG_INFO() << "saving downloaded file (no extraction) to" << destfile;
|
||||||
|
|
||||||
m_downloadFile->open(); // copy fails if file is not opened (filename issue?)
|
m_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(destfile).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();
|
// TODO: compare old and new file and fail if those are different.
|
||||||
if(!m_downloadFile->copy(m_mountpoint + m_target)) {
|
QFile(destfile).remove();
|
||||||
|
if(!m_downloadFile->copy(destfile)) {
|
||||||
emit logItem(tr("Installing file failed."), LOGERROR);
|
emit logItem(tr("Installing file failed."), LOGERROR);
|
||||||
emit done(true);
|
emit done(true);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,15 @@
|
||||||
#include "httpget.h"
|
#include "httpget.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
|
/** Install a file or zip.
|
||||||
|
* Downloads file(s) from a given URL, and installs by either extracting or
|
||||||
|
* copying it to the target path set by setMountpoint().
|
||||||
|
*/
|
||||||
class ZipInstaller : public QObject
|
class ZipInstaller : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ZipInstaller(QObject* parent) ;
|
ZipInstaller(QObject* parent);
|
||||||
~ZipInstaller(){}
|
~ZipInstaller(){}
|
||||||
void install(void);
|
void install(void);
|
||||||
void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;}
|
void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;}
|
||||||
|
|
@ -44,11 +48,12 @@ public:
|
||||||
{ m_verlist = QStringList(v); LOG_INFO() << m_verlist;}
|
{ m_verlist = QStringList(v); LOG_INFO() << m_verlist;}
|
||||||
void setLogVersion(QStringList v)
|
void setLogVersion(QStringList v)
|
||||||
{ m_verlist = v; LOG_INFO() << m_verlist;}
|
{ m_verlist = v; LOG_INFO() << m_verlist;}
|
||||||
|
/** Change between copy and unzip mode. */
|
||||||
void setUnzip(bool i) { m_unzip = i; }
|
void setUnzip(bool i) { m_unzip = i; }
|
||||||
|
/** Set target filename for copy mode.
|
||||||
|
* If not set the filename part of the download URL is used. */
|
||||||
void setTarget(QString t) { m_target = t; }
|
void setTarget(QString t) { m_target = t; }
|
||||||
void setCache(QDir c) { m_cache = c; m_usecache = true; };
|
void setCache(bool c) { m_usecache = c; }
|
||||||
void setCache(bool c) { m_usecache = c; };
|
|
||||||
void setCache(QString c) { m_cache = QDir(c); m_usecache = true; }
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void abort(void);
|
void abort(void);
|
||||||
|
|
@ -70,8 +75,7 @@ private:
|
||||||
QStringList m_urllist, m_loglist, m_verlist;
|
QStringList m_urllist, m_loglist, m_verlist;
|
||||||
bool m_unzip;
|
bool m_unzip;
|
||||||
QString m_target;
|
QString m_target;
|
||||||
int runner;
|
int m_runner;
|
||||||
QDir m_cache;
|
|
||||||
bool m_usecache;
|
bool m_usecache;
|
||||||
|
|
||||||
HttpGet *m_getter;
|
HttpGet *m_getter;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue