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();
136 connect(&zip
, SIGNAL(logProgress(int, int)), this, SIGNAL(logProgress(int, int)));
137 connect(&zip
, SIGNAL(logItem(QString
, int)), this, SIGNAL(logItem(QString
, int)));
138 zip
.open(m_file
, QuaZip::mdUnzip
);
139 // check for free space. Make sure after installation will still be
140 // some room for operating (also includes calculation mistakes due to
141 // cluster sizes on the player).
142 if((qint64
)Utils::filesystemFree(m_mountpoint
)
143 < (zip
.totalUncompressedSize(Utils::filesystemClusterSize(m_mountpoint
))
145 emit
logItem(tr("Not enough disk space! Aborting."), LOGERROR
);
146 emit
logProgress(1, 1);
150 zipContents
= zip
.files();
151 if(!zip
.extractArchive(m_mountpoint
)) {
152 emit
logItem(tr("Extraction failed!"), LOGERROR
);
153 emit
logProgress(1, 1);
160 // only copy the downloaded file to the output location / name
161 emit
logItem(tr("Installing file."), LOGINFO
);
162 qDebug() << "[ZipInstall] saving downloaded file (no extraction)";
164 downloadFile
->open(); // copy fails if file is not opened (filename issue?)
165 // make sure the required path is existing
166 QString path
= QFileInfo(m_mountpoint
+ m_target
).absolutePath();
169 // QFile::copy() doesn't overwrite files, so remove old one first
170 QFile(m_mountpoint
+ m_target
).remove();
171 if(!downloadFile
->copy(m_mountpoint
+ m_target
)) {
172 emit
logItem(tr("Installing file failed."), LOGERROR
);
178 zipContents
.append(m_target
);
181 emit
logItem(tr("Creating installation log"),LOGINFO
);
182 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
184 installlog
.beginGroup(m_logsection
);
185 for(int i
= 0; i
< zipContents
.size(); i
++)
187 installlog
.setValue(zipContents
.at(i
), m_logver
);
189 installlog
.endGroup();