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 ****************************************************************************/
20 #include "installzip.h"
24 ZipInstaller::ZipInstaller(QObject
* parent
): QObject(parent
)
31 void ZipInstaller::install(ProgressloggerInterface
*dp
)
33 qDebug() << "install(ProgressloggerInterface*)";
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
);
45 void ZipInstaller::installContinue()
47 qDebug() << "installContinue()";
49 runner
++; // this gets called when a install finished, so increase first.
50 qDebug() << "runner is now at" << runner
<< "size is" << m_urllist
.size();
51 if(runner
< m_urllist
.size()) {
52 qDebug() << "==> runner at" << runner
;
53 m_dp
->addItem(tr("done."), LOGOK
);
54 m_url
= m_urllist
.at(runner
);
55 m_logsection
= m_loglist
.at(runner
);
56 if(runner
< m_verlist
.size()) m_logver
= m_verlist
.at(runner
);
61 m_dp
->addItem(tr("Installation finished successfully."),LOGOK
);
71 void ZipInstaller::installStart()
73 qDebug() << "installStart()";
75 m_dp
->addItem(tr("Downloading file %1.%2")
76 .arg(QFileInfo(m_url
).baseName(), QFileInfo(m_url
).completeSuffix()),LOGINFO
);
78 // temporary file needs to be opened to get the filename
79 // make sure to get a fresh one on each run.
80 // making this a parent of the temporary file ensures the file gets deleted
81 // after the class object gets destroyed.
82 downloadFile
= new QTemporaryFile(this);
84 m_file
= downloadFile
->fileName();
85 downloadFile
->close();
87 getter
= new HttpGet(this);
89 getter
->setCache(true);
91 getter
->setFile(downloadFile
);
93 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
94 connect(getter
, SIGNAL(dataReadProgress(int, int)), m_dp
, SLOT(setProgress(int, int)));
95 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
97 getter
->getFile(QUrl(m_url
));
101 void ZipInstaller::downloadDone(bool error
)
103 qDebug() << "Install::downloadDone, error:" << error
;
104 QStringList zipContents
; // needed later
105 // update progress bar
107 int max
= m_dp
->getProgressMax();
110 m_dp
->setProgressMax(max
);
112 m_dp
->setProgressValue(max
);
113 if(getter
->httpResponse() != 200 && !getter
->isCached()) {
114 m_dp
->addItem(tr("Download error: received HTTP error %1.").arg(getter
->httpResponse()),LOGERROR
);
119 if(getter
->isCached()) m_dp
->addItem(tr("Cached file used."), LOGINFO
);
121 m_dp
->addItem(tr("Download error: %1").arg(getter
->errorString()),LOGERROR
);
126 else m_dp
->addItem(tr("Download finished."),LOGOK
);
127 QCoreApplication::processEvents();
129 // unzip downloaded file
130 qDebug() << "about to unzip the downloaded file" << m_file
<< "to" << m_mountpoint
;
132 m_dp
->addItem(tr("Extracting file."),LOGINFO
);
133 QCoreApplication::processEvents();
135 qDebug() << "file to unzip: " << m_file
;
138 connect(&uz
, SIGNAL(unzipProgress(int, int)), m_dp
, SLOT(setProgress(int, int)));
139 connect(m_dp
, SIGNAL(aborted()), &uz
, SLOT(abortUnzip()));
140 ec
= uz
.openArchive(m_file
);
141 if(ec
!= UnZip::Ok
) {
142 m_dp
->addItem(tr("Opening archive failed: %1.")
143 .arg(uz
.formatError(ec
)),LOGERROR
);
144 m_dp
->setProgressMax(1);
145 m_dp
->setProgressValue(1);
151 ec
= uz
.extractArchive(m_mountpoint
);
152 // TODO: better handling of aborted unzip operation.
153 if(ec
!= UnZip::Ok
) {
154 m_dp
->addItem(tr("Extracting failed: %1.")
155 .arg(uz
.formatError(ec
)),LOGERROR
);
157 m_dp
->setProgressMax(1);
158 m_dp
->setProgressValue(1);
163 // prepare file list for log
164 zipContents
= uz
.fileList();
167 // only copy the downloaded file to the output location / name
168 m_dp
->addItem(tr("Installing file."), LOGINFO
);
169 qDebug() << "saving downloaded file (no extraction)";
171 downloadFile
->open(); // copy fails if file is not opened (filename issue?)
172 // make sure the required path is existing
173 QString path
= QFileInfo(m_mountpoint
+ m_target
).absolutePath();
176 // QFile::copy() doesn't overwrite files, so remove old one first
177 QFile(m_mountpoint
+ m_target
).remove();
178 if(!downloadFile
->copy(m_mountpoint
+ m_target
)) {
179 m_dp
->addItem(tr("Installing file failed."), LOGERROR
);
186 zipContents
.append( m_target
);
189 m_dp
->addItem(tr("Creating installation log"),LOGINFO
);
190 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
192 installlog
.beginGroup(m_logsection
);
193 for(int i
= 0; i
< zipContents
.size(); i
++)
195 installlog
.setValue(zipContents
.at(i
), m_logver
);
197 installlog
.endGroup();