1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: installzip.cpp 13990 2007-07-25 22:26:10Z 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"
23 #include "zip/unzip.h"
25 ZipInstaller::ZipInstaller(QObject
* parent
): QObject(parent
)
31 void ZipInstaller::install(ProgressloggerInterface
* dp
)
35 m_dp
->addItem(tr("Downloading file %1.%2")
36 .arg(QFileInfo(m_url
).baseName(), QFileInfo(m_url
).completeSuffix()),LOGINFO
);
38 // temporary file needs to be opened to get the filename
40 m_file
= downloadFile
.fileName();
43 getter
= new HttpGet(this);
44 getter
->setProxy(m_proxy
);
45 getter
->setFile(&downloadFile
);
46 getter
->getFile(QUrl(m_url
));
48 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
49 connect(getter
, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool)));
50 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
51 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
54 void ZipInstaller::downloadRequestFinished(int id
, bool error
)
56 qDebug() << "Install::downloadRequestFinished" << id
<< error
;
57 qDebug() << "error:" << getter
->errorString();
62 void ZipInstaller::downloadDone(bool error
)
64 qDebug() << "Install::downloadDone, error:" << error
;
66 // update progress bar
68 int max
= m_dp
->getProgressMax();
71 m_dp
->setProgressMax(max
);
73 m_dp
->setProgressValue(max
);
74 if(getter
->httpResponse() != 200) {
75 m_dp
->addItem(tr("Download error: received HTTP error %1.").arg(getter
->httpResponse()),LOGERROR
);
81 m_dp
->addItem(tr("Download error: %1").arg(getter
->errorString()),LOGERROR
);
86 else m_dp
->addItem(tr("Download finished."),LOGOK
);
88 // unzip downloaded file
89 qDebug() << "about to unzip the downloaded file" << m_file
<< "to" << m_mountpoint
;
91 m_dp
->addItem(tr("Extracting file."),LOGINFO
);
93 qDebug() << "file to unzip: " << m_file
;
96 ec
= uz
.openArchive(m_file
);
98 m_dp
->addItem(tr("Opening archive failed: %1.")
99 .arg(uz
.formatError(ec
)),LOGERROR
);
105 ec
= uz
.extractAll(m_mountpoint
);
106 if(ec
!= UnZip::Ok
) {
107 m_dp
->addItem(tr("Extracting failed: %1.")
108 .arg(uz
.formatError(ec
)),LOGERROR
);
114 m_dp
->addItem(tr("creating installation log"),LOGINFO
);
116 QStringList zipContents
= uz
.fileList();
118 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
120 installlog
.beginGroup(m_logsection
);
121 for(int i
= 0; i
< zipContents
.size(); i
++)
123 installlog
.setValue(zipContents
.at(i
),installlog
.value(zipContents
.at(i
),0).toInt()+1);
125 installlog
.endGroup();
127 // remove temporary file
128 downloadFile
.remove();
130 m_dp
->addItem(tr("Extraction finished successfully."),LOGOK
);
135 void ZipInstaller::updateDataReadProgress(int read
, int total
)
137 m_dp
->setProgressMax(total
);
138 m_dp
->setProgressValue(read
);
139 qDebug() << "progress:" << read
<< "/" << total
;