Support reading OF files from zip.

Several devices require the original firmware to be able installing the
bootloader. Most vendors distribute the firmware file in zip format. Extend
reading the original firmware file to support reading the file from the zip
directly instead of requiring the user to separately extract it.

Change-Id: Ic4e89053456d8f7d6adc294f6657aceddbc354ba
This commit is contained in:
Dominik Riebeling 2012-01-15 23:20:17 +01:00
parent 66c3086ae5
commit b45cc0a13a
5 changed files with 84 additions and 16 deletions

View file

@ -70,10 +70,13 @@ bool ZipUtil::close(void)
//! @brief extract currently opened archive
//! @brief dest path to extract archive to
//! @brief dest path to extract archive to, can be filename when extracting a
//! single file.
//! @brief file file to extract from archive, full archive if empty.
//! @return true on success, false otherwise
bool ZipUtil::extractArchive(QString& dest)
bool ZipUtil::extractArchive(QString& dest, QString file)
{
qDebug() << "[ZipUtil] extractArchive" << dest << file;
bool result = true;
if(!m_zip) {
return false;
@ -81,6 +84,16 @@ bool ZipUtil::extractArchive(QString& dest)
QuaZipFile *currentFile = new QuaZipFile(m_zip);
int entries = m_zip->getEntriesCount();
int current = 0;
// construct the filename when extracting a single file from an archive.
// if the given destination is a full path use it as output name,
// otherwise use it as path to place the file as named in the archive.
QString singleoutfile;
if(!file.isEmpty() && QFileInfo(dest).isDir()) {
singleoutfile = dest + "/" + file;
}
else if(!file.isEmpty()){
singleoutfile = dest;
}
for(bool more = m_zip->goToFirstFile(); more; more = m_zip->goToNextFile())
{
++current;
@ -88,7 +101,16 @@ bool ZipUtil::extractArchive(QString& dest)
if(m_zip->getCurrentFileName().split("/").last() == "")
continue;
QString outfilename = dest + "/" + m_zip->getCurrentFileName();
QString outfilename;
if(!singleoutfile.isEmpty()
&& QFileInfo(m_zip->getCurrentFileName()).fileName() == file) {
outfilename = singleoutfile;
}
else if(singleoutfile.isEmpty()) {
outfilename = dest + "/" + m_zip->getCurrentFileName();
}
if(outfilename.isEmpty())
continue;
QFile outputFile(outfilename);
// make sure the output path exists
if(!QDir().mkpath(QFileInfo(outfilename).absolutePath())) {