summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-09-26 17:51:33 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-09-27 09:28:21 +0200
commitf1f72ff8df68e190a43a56d14dfc820d1e58d96b (patch)
treec6859d79e193b6ab71c33546c9a3409f473e25db /rbutil
parent9d8bcbeb2abf0593ae9d804d038c3821693e7131 (diff)
downloadrockbox-f1f72ff8df68e190a43a56d14dfc820d1e58d96b.tar.gz
rockbox-f1f72ff8df68e190a43a56d14dfc820d1e58d96b.zip
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
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/base/zipinstaller.cpp40
-rw-r--r--rbutil/rbutilqt/base/zipinstaller.h16
2 files changed, 31 insertions, 25 deletions
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 @@
22#include "ziputil.h" 22#include "ziputil.h"
23#include "Logger.h" 23#include "Logger.h"
24 24
25ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) 25ZipInstaller::ZipInstaller(QObject* parent) :
26 QObject(parent),
27 m_unzip(true), m_usecache(false), m_getter(0)
26{ 28{
27 m_unzip = true;
28 m_usecache = false;
29 m_getter = 0;
30} 29}
31 30
32 31
@@ -34,11 +33,11 @@ void ZipInstaller::install()
34{ 33{
35 LOG_INFO() << "initializing installation"; 34 LOG_INFO() << "initializing installation";
36 35
37 runner = 0; 36 m_runner = 0;
38 connect(this, SIGNAL(cont()), this, SLOT(installContinue())); 37 connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
39 m_url = m_urllist.at(runner); 38 m_url = m_urllist.at(m_runner);
40 m_logsection = m_loglist.at(runner); 39 m_logsection = m_loglist.at(m_runner);
41 m_logver = m_verlist.at(runner); 40 m_logver = m_verlist.at(m_runner);
42 installStart(); 41 installStart();
43} 42}
44 43
@@ -54,13 +53,13 @@ void ZipInstaller::installContinue()
54{ 53{
55 LOG_INFO() << "continuing installation"; 54 LOG_INFO() << "continuing installation";
56 55
57 runner++; // this gets called when a install finished, so increase first. 56 m_runner++; // this gets called when a install finished, so increase first.
58 LOG_INFO() << "runner done:" << runner << "/" << m_urllist.size(); 57 LOG_INFO() << "runner done:" << m_runner << "/" << m_urllist.size();
59 if(runner < m_urllist.size()) { 58 if(m_runner < m_urllist.size()) {
60 emit logItem(tr("done."), LOGOK); 59 emit logItem(tr("done."), LOGOK);
61 m_url = m_urllist.at(runner); 60 m_url = m_urllist.at(m_runner);
62 m_logsection = m_loglist.at(runner); 61 m_logsection = m_loglist.at(m_runner);
63 if(runner < m_verlist.size()) m_logver = m_verlist.at(runner); 62 if(m_runner < m_verlist.size()) m_logver = m_verlist.at(m_runner);
64 else m_logver = ""; 63 else m_logver = "";
65 installStart(); 64 installStart();
66 } 65 }
@@ -69,7 +68,6 @@ void ZipInstaller::installContinue()
69 emit done(false); 68 emit done(false);
70 return; 69 return;
71 } 70 }
72
73} 71}
74 72
75 73
@@ -158,18 +156,22 @@ void ZipInstaller::downloadDone(bool error)
158 zip.close(); 156 zip.close();
159 } 157 }
160 else { 158 else {
159 if (m_target.isEmpty())
160 m_target = QUrl(m_url).fileName();
161 QString destfile = m_mountpoint + "/" + m_target;
161 // only copy the downloaded file to the output location / name 162 // only copy the downloaded file to the output location / name
162 emit logItem(tr("Installing file."), LOGINFO); 163 emit logItem(tr("Installing file."), LOGINFO);
163 LOG_INFO() << "saving downloaded file (no extraction)"; 164 LOG_INFO() << "saving downloaded file (no extraction) to" << destfile;
164 165
165 m_downloadFile->open(); // copy fails if file is not opened (filename issue?) 166 m_downloadFile->open(); // copy fails if file is not opened (filename issue?)
166 // make sure the required path is existing 167 // make sure the required path is existing
167 QString path = QFileInfo(m_mountpoint + m_target).absolutePath(); 168 QString path = QFileInfo(destfile).absolutePath();
168 QDir p; 169 QDir p;
169 p.mkpath(path); 170 p.mkpath(path);
170 // QFile::copy() doesn't overwrite files, so remove old one first 171 // QFile::copy() doesn't overwrite files, so remove old one first
171 QFile(m_mountpoint + m_target).remove(); 172 // TODO: compare old and new file and fail if those are different.
172 if(!m_downloadFile->copy(m_mountpoint + m_target)) { 173 QFile(destfile).remove();
174 if(!m_downloadFile->copy(destfile)) {
173 emit logItem(tr("Installing file failed."), LOGERROR); 175 emit logItem(tr("Installing file failed."), LOGERROR);
174 emit done(true); 176 emit done(true);
175 return; 177 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 @@
28#include "httpget.h" 28#include "httpget.h"
29#include "Logger.h" 29#include "Logger.h"
30 30
31/** Install a file or zip.
32 * Downloads file(s) from a given URL, and installs by either extracting or
33 * copying it to the target path set by setMountpoint().
34 */
31class ZipInstaller : public QObject 35class ZipInstaller : public QObject
32{ 36{
33 Q_OBJECT 37 Q_OBJECT
34public: 38public:
35 ZipInstaller(QObject* parent) ; 39 ZipInstaller(QObject* parent);
36 ~ZipInstaller(){} 40 ~ZipInstaller(){}
37 void install(void); 41 void install(void);
38 void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;} 42 void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;}
@@ -44,11 +48,12 @@ public:
44 { m_verlist = QStringList(v); LOG_INFO() << m_verlist;} 48 { m_verlist = QStringList(v); LOG_INFO() << m_verlist;}
45 void setLogVersion(QStringList v) 49 void setLogVersion(QStringList v)
46 { m_verlist = v; LOG_INFO() << m_verlist;} 50 { m_verlist = v; LOG_INFO() << m_verlist;}
51 /** Change between copy and unzip mode. */
47 void setUnzip(bool i) { m_unzip = i; } 52 void setUnzip(bool i) { m_unzip = i; }
53 /** Set target filename for copy mode.
54 * If not set the filename part of the download URL is used. */
48 void setTarget(QString t) { m_target = t; } 55 void setTarget(QString t) { m_target = t; }
49 void setCache(QDir c) { m_cache = c; m_usecache = true; }; 56 void setCache(bool c) { m_usecache = c; }
50 void setCache(bool c) { m_usecache = c; };
51 void setCache(QString c) { m_cache = QDir(c); m_usecache = true; }
52 57
53public slots: 58public slots:
54 void abort(void); 59 void abort(void);
@@ -70,8 +75,7 @@ private:
70 QStringList m_urllist, m_loglist, m_verlist; 75 QStringList m_urllist, m_loglist, m_verlist;
71 bool m_unzip; 76 bool m_unzip;
72 QString m_target; 77 QString m_target;
73 int runner; 78 int m_runner;
74 QDir m_cache;
75 bool m_usecache; 79 bool m_usecache;
76 80
77 HttpGet *m_getter; 81 HttpGet *m_getter;