From b45cc0a13a20e88546cd7a536f09979edf8353a1 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 15 Jan 2012 23:20:17 +0100 Subject: 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 --- rbutil/rbutilqt/base/ziputil.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'rbutil/rbutilqt/base/ziputil.cpp') diff --git a/rbutil/rbutilqt/base/ziputil.cpp b/rbutil/rbutilqt/base/ziputil.cpp index 481ad4c2ae..b9218a70bc 100644 --- a/rbutil/rbutilqt/base/ziputil.cpp +++ b/rbutil/rbutilqt/base/ziputil.cpp @@ -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())) { -- cgit v1.2.3