1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "zipinstaller.h"
25 ZipInstaller::ZipInstaller(QObject
* parent
): QObject(parent
)
32 void ZipInstaller::install()
34 qDebug() << "[ZipInstall] initializing installation";
37 connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
38 m_url
= m_urllist
.at(runner
);
39 m_logsection
= m_loglist
.at(runner
);
40 m_logver
= m_verlist
.at(runner
);
45 void ZipInstaller::abort()
47 qDebug() << "[ZipInstall] Aborted";
48 emit
internalAborted();
52 void ZipInstaller::installContinue()
54 qDebug() << "[ZipInstall] continuing installation";
56 runner
++; // this gets called when a install finished, so increase first.
57 qDebug() << "[ZipInstall] runner done:" << runner
<< "/" << m_urllist
.size();
58 if(runner
< m_urllist
.size()) {
59 emit
logItem(tr("done."), LOGOK
);
60 m_url
= m_urllist
.at(runner
);
61 m_logsection
= m_loglist
.at(runner
);
62 if(runner
< m_verlist
.size()) m_logver
= m_verlist
.at(runner
);
67 emit
logItem(tr("Installation finished successfully."), LOGOK
);
76 void ZipInstaller::installStart()
78 qDebug() << "[ZipInstall] starting installation";
80 emit
logItem(tr("Downloading file %1.%2").arg(QFileInfo(m_url
).baseName(),
81 QFileInfo(m_url
).completeSuffix()),LOGINFO
);
83 // temporary file needs to be opened to get the filename
84 // make sure to get a fresh one on each run.
85 // making this a parent of the temporary file ensures the file gets deleted
86 // after the class object gets destroyed.
87 downloadFile
= new QTemporaryFile(this);
89 m_file
= downloadFile
->fileName();
90 downloadFile
->close();
92 getter
= new HttpGet(this);
94 getter
->setCache(true);
96 getter
->setFile(downloadFile
);
98 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
99 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(logProgress(int, int)));
100 connect(this, SIGNAL(internalAborted()), getter
, SLOT(abort()));
102 getter
->getFile(QUrl(m_url
));
106 void ZipInstaller::downloadDone(bool error
)
108 qDebug() << "[ZipInstall] download done, error:" << error
;
109 QStringList zipContents
; // needed later
110 // update progress bar
112 emit
logProgress(1, 1);
113 if(getter
->httpResponse() != 200 && !getter
->isCached()) {
114 emit
logItem(tr("Download error: received HTTP error %1.")
115 .arg(getter
->httpResponse()),LOGERROR
);
119 if(getter
->isCached())
120 emit
logItem(tr("Cached file used."), LOGINFO
);
122 emit
logItem(tr("Download error: %1").arg(getter
->errorString()), LOGERROR
);
126 else emit
logItem(tr("Download finished."),LOGOK
);
127 QCoreApplication::processEvents();
129 // unzip downloaded file
130 qDebug() << "[ZipInstall] about to unzip " << m_file
<< "to" << m_mountpoint
;
132 emit
logItem(tr("Extracting file."), LOGINFO
);
133 QCoreApplication::processEvents();
137 connect(&uz
, SIGNAL(unzipProgress(int, int)), this, SIGNAL(logProgress(int, int)));
138 connect(this, SIGNAL(internalAborted()), &uz
, SLOT(abortUnzip()));
139 ec
= uz
.openArchive(m_file
);
140 if(ec
!= UnZip::Ok
) {
141 emit
logItem(tr("Opening archive failed: %1.")
142 .arg(uz
.formatError(ec
)),LOGERROR
);
143 emit
logProgress(1, 1);
148 // check for free space. Make sure after installation will still be
149 // some room for operating (also includes calculation mistakes due to
150 // cluster sizes on the player).
151 if(Utils::filesystemFree(m_mountpoint
) < (uz
.totalSize() + 1000000)) {
152 emit
logItem(tr("Not enough disk space! Aborting."), LOGERROR
);
153 emit
logProgress(1, 1);
157 ec
= uz
.extractArchive(m_mountpoint
);
158 // TODO: better handling of aborted unzip operation.
159 if(ec
!= UnZip::Ok
) {
160 emit
logItem(tr("Extracting failed: %1.")
161 .arg(uz
.formatError(ec
)),LOGERROR
);
162 emit
logProgress(1, 1);
166 // prepare file list for log
167 zipContents
= uz
.fileList();
170 // only copy the downloaded file to the output location / name
171 emit
logItem(tr("Installing file."), LOGINFO
);
172 qDebug() << "[ZipInstall] saving downloaded file (no extraction)";
174 downloadFile
->open(); // copy fails if file is not opened (filename issue?)
175 // make sure the required path is existing
176 QString path
= QFileInfo(m_mountpoint
+ m_target
).absolutePath();
179 // QFile::copy() doesn't overwrite files, so remove old one first
180 QFile(m_mountpoint
+ m_target
).remove();
181 if(!downloadFile
->copy(m_mountpoint
+ m_target
)) {
182 emit
logItem(tr("Installing file failed."), LOGERROR
);
188 zipContents
.append( m_target
);
191 emit
logItem(tr("Creating installation log"),LOGINFO
);
192 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
194 installlog
.beginGroup(m_logsection
);
195 for(int i
= 0; i
< zipContents
.size(); i
++)
197 installlog
.setValue(zipContents
.at(i
), m_logver
);
199 installlog
.endGroup();