From f1f72ff8df68e190a43a56d14dfc820d1e58d96b Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 26 Sep 2020 17:51:33 +0200 Subject: 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 --- rbutil/rbutilqt/base/zipinstaller.cpp | 40 ++++++++++++++++++----------------- rbutil/rbutilqt/base/zipinstaller.h | 16 ++++++++------ 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'rbutil/rbutilqt/base') diff --git a/rbutil/rbutilqt/base/zipinstaller.cpp b/rbutil/rbutilqt/base/zipinstaller.cpp index b2c8e09178..caf1b52945 100644 --- a/rbutil/rbutilqt/base/zipinstaller.cpp +++ b/rbutil/rbutilqt/base/zipinstaller.cpp @@ -22,11 +22,10 @@ #include "ziputil.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"; - runner = 0; + m_runner = 0; connect(this, SIGNAL(cont()), this, SLOT(installContinue())); - m_url = m_urllist.at(runner); - m_logsection = m_loglist.at(runner); - m_logver = m_verlist.at(runner); + m_url = m_urllist.at(m_runner); + m_logsection = m_loglist.at(m_runner); + m_logver = m_verlist.at(m_runner); installStart(); } @@ -54,13 +53,13 @@ void ZipInstaller::installContinue() { LOG_INFO() << "continuing installation"; - runner++; // this gets called when a install finished, so increase first. - LOG_INFO() << "runner done:" << runner << "/" << m_urllist.size(); - if(runner < m_urllist.size()) { + 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()) { emit logItem(tr("done."), LOGOK); - m_url = m_urllist.at(runner); - m_logsection = m_loglist.at(runner); - if(runner < m_verlist.size()) m_logver = m_verlist.at(runner); + 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); else m_logver = ""; installStart(); } @@ -69,7 +68,6 @@ void ZipInstaller::installContinue() emit done(false); return; } - } @@ -158,18 +156,22 @@ void ZipInstaller::downloadDone(bool error) zip.close(); } 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 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?) // make sure the required path is existing - QString path = QFileInfo(m_mountpoint + m_target).absolutePath(); + QString path = QFileInfo(destfile).absolutePath(); QDir p; p.mkpath(path); // QFile::copy() doesn't overwrite files, so remove old one first - QFile(m_mountpoint + m_target).remove(); - if(!m_downloadFile->copy(m_mountpoint + m_target)) { + // TODO: compare old and new file and fail if those are different. + QFile(destfile).remove(); + if(!m_downloadFile->copy(destfile)) { emit logItem(tr("Installing file failed."), LOGERROR); emit done(true); return; diff --git a/rbutil/rbutilqt/base/zipinstaller.h b/rbutil/rbutilqt/base/zipinstaller.h index 97a5156ee8..59a0f785d9 100644 --- a/rbutil/rbutilqt/base/zipinstaller.h +++ b/rbutil/rbutilqt/base/zipinstaller.h @@ -28,11 +28,15 @@ #include "httpget.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 { Q_OBJECT public: - ZipInstaller(QObject* parent) ; + ZipInstaller(QObject* parent); ~ZipInstaller(){} void install(void); void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;} @@ -44,11 +48,12 @@ public: { m_verlist = QStringList(v); LOG_INFO() << m_verlist;} void setLogVersion(QStringList v) { m_verlist = v; LOG_INFO() << m_verlist;} + /** Change between copy and unzip mode. */ 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 setCache(QDir c) { m_cache = c; m_usecache = true; }; - void setCache(bool c) { m_usecache = c; }; - void setCache(QString c) { m_cache = QDir(c); m_usecache = true; } + void setCache(bool c) { m_usecache = c; } public slots: void abort(void); @@ -70,8 +75,7 @@ private: QStringList m_urllist, m_loglist, m_verlist; bool m_unzip; QString m_target; - int runner; - QDir m_cache; + int m_runner; bool m_usecache; HttpGet *m_getter; -- cgit v1.2.3