1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
20 #include "zipinstaller.h"
24 ZipInstaller::ZipInstaller(QObject
* parent
): QObject(parent
)
31 void ZipInstaller::install()
33 qDebug() << "[ZipInstall] initializing installation";
36 connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
37 m_url
= m_urllist
.at(runner
);
38 m_logsection
= m_loglist
.at(runner
);
39 m_logver
= m_verlist
.at(runner
);
44 void ZipInstaller::abort()
46 qDebug() << "[ZipInstall] Aborted";
47 emit
internalAborted();
51 void ZipInstaller::installContinue()
53 qDebug() << "[ZipInstall] continuing installation";
55 runner
++; // this gets called when a install finished, so increase first.
56 qDebug() << "[ZipInstall] runner done:" << runner
<< "/" << m_urllist
.size();
57 if(runner
< m_urllist
.size()) {
58 emit
logItem(tr("done."), LOGOK
);
59 m_url
= m_urllist
.at(runner
);
60 m_logsection
= m_loglist
.at(runner
);
61 if(runner
< m_verlist
.size()) m_logver
= m_verlist
.at(runner
);
66 emit
logItem(tr("Installation finished successfully."), LOGOK
);
75 void ZipInstaller::installStart()
77 qDebug() << "[ZipInstall] starting installation";
79 emit
logItem(tr("Downloading file %1.%2").arg(QFileInfo(m_url
).baseName(),
80 QFileInfo(m_url
).completeSuffix()),LOGINFO
);
82 // temporary file needs to be opened to get the filename
83 // make sure to get a fresh one on each run.
84 // making this a parent of the temporary file ensures the file gets deleted
85 // after the class object gets destroyed.
86 downloadFile
= new QTemporaryFile(this);
88 m_file
= downloadFile
->fileName();
89 downloadFile
->close();
91 getter
= new HttpGet(this);
93 getter
->setCache(true);
95 getter
->setFile(downloadFile
);
97 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
98 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(logProgress(int, int)));
99 connect(this, SIGNAL(internalAborted()), getter
, SLOT(abort()));
101 getter
->getFile(QUrl(m_url
));
105 void ZipInstaller::downloadDone(bool error
)
107 qDebug() << "[ZipInstall] download done, error:" << error
;
108 QStringList zipContents
; // needed later
109 // update progress bar
111 emit
logProgress(1, 1);
112 if(getter
->httpResponse() != 200 && !getter
->isCached()) {
113 emit
logItem(tr("Download error: received HTTP error %1.")
114 .arg(getter
->httpResponse()),LOGERROR
);
118 if(getter
->isCached())
119 emit
logItem(tr("Cached file used."), LOGINFO
);
121 emit
logItem(tr("Download error: %1").arg(getter
->errorString()), LOGERROR
);
125 else emit
logItem(tr("Download finished."),LOGOK
);
126 QCoreApplication::processEvents();
128 // unzip downloaded file
129 qDebug() << "[ZipInstall] about to unzip " << m_file
<< "to" << m_mountpoint
;
131 emit
logItem(tr("Extracting file."), LOGINFO
);
132 QCoreApplication::processEvents();
135 connect(&zip
, SIGNAL(logProgress(int, int)), this, SIGNAL(logProgress(int, int)));
136 connect(&zip
, SIGNAL(logItem(QString
, int)), this, SIGNAL(logItem(QString
, int)));
137 zip
.open(m_file
, QuaZip::mdUnzip
);
138 // check for free space. Make sure after installation will still be
139 // some room for operating (also includes calculation mistakes due to
140 // cluster sizes on the player).
141 if((qint64
)Utils::filesystemFree(m_mountpoint
)
142 < (zip
.totalUncompressedSize(Utils::filesystemClusterSize(m_mountpoint
))
144 emit
logItem(tr("Not enough disk space! Aborting."), LOGERROR
);
145 emit
logProgress(1, 1);
149 zipContents
= zip
.files();
150 if(!zip
.extractArchive(m_mountpoint
)) {
151 emit
logItem(tr("Extraction failed!"), LOGERROR
);
152 emit
logProgress(1, 1);
159 // only copy the downloaded file to the output location / name
160 emit
logItem(tr("Installing file."), LOGINFO
);
161 qDebug() << "[ZipInstall] saving downloaded file (no extraction)";
163 downloadFile
->open(); // copy fails if file is not opened (filename issue?)
164 // make sure the required path is existing
165 QString path
= QFileInfo(m_mountpoint
+ m_target
).absolutePath();
168 // QFile::copy() doesn't overwrite files, so remove old one first
169 QFile(m_mountpoint
+ m_target
).remove();
170 if(!downloadFile
->copy(m_mountpoint
+ m_target
)) {
171 emit
logItem(tr("Installing file failed."), LOGERROR
);
177 zipContents
.append(m_target
);
180 emit
logItem(tr("Creating installation log"),LOGINFO
);
181 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
183 installlog
.beginGroup(m_logsection
);
184 for(int i
= 0; i
< zipContents
.size(); i
++)
186 installlog
.setValue(zipContents
.at(i
), m_logver
);
188 installlog
.endGroup();