summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/ziputil.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-01-15 23:20:17 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-01-15 23:32:15 +0100
commitb45cc0a13a20e88546cd7a536f09979edf8353a1 (patch)
tree1189e5a6381c7f4a8ac770bafbb9a21f49d5e930 /rbutil/rbutilqt/base/ziputil.cpp
parent66c3086ae54c71413117f3de3dcfb5f0fe8b541d (diff)
downloadrockbox-b45cc0a13a20e88546cd7a536f09979edf8353a1.tar.gz
rockbox-b45cc0a13a20e88546cd7a536f09979edf8353a1.zip
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
Diffstat (limited to 'rbutil/rbutilqt/base/ziputil.cpp')
-rw-r--r--rbutil/rbutilqt/base/ziputil.cpp28
1 files changed, 25 insertions, 3 deletions
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)
70 70
71 71
72//! @brief extract currently opened archive 72//! @brief extract currently opened archive
73//! @brief dest path to extract archive to 73//! @brief dest path to extract archive to, can be filename when extracting a
74//! single file.
75//! @brief file file to extract from archive, full archive if empty.
74//! @return true on success, false otherwise 76//! @return true on success, false otherwise
75bool ZipUtil::extractArchive(QString& dest) 77bool ZipUtil::extractArchive(QString& dest, QString file)
76{ 78{
79 qDebug() << "[ZipUtil] extractArchive" << dest << file;
77 bool result = true; 80 bool result = true;
78 if(!m_zip) { 81 if(!m_zip) {
79 return false; 82 return false;
@@ -81,6 +84,16 @@ bool ZipUtil::extractArchive(QString& dest)
81 QuaZipFile *currentFile = new QuaZipFile(m_zip); 84 QuaZipFile *currentFile = new QuaZipFile(m_zip);
82 int entries = m_zip->getEntriesCount(); 85 int entries = m_zip->getEntriesCount();
83 int current = 0; 86 int current = 0;
87 // construct the filename when extracting a single file from an archive.
88 // if the given destination is a full path use it as output name,
89 // otherwise use it as path to place the file as named in the archive.
90 QString singleoutfile;
91 if(!file.isEmpty() && QFileInfo(dest).isDir()) {
92 singleoutfile = dest + "/" + file;
93 }
94 else if(!file.isEmpty()){
95 singleoutfile = dest;
96 }
84 for(bool more = m_zip->goToFirstFile(); more; more = m_zip->goToNextFile()) 97 for(bool more = m_zip->goToFirstFile(); more; more = m_zip->goToNextFile())
85 { 98 {
86 ++current; 99 ++current;
@@ -88,7 +101,16 @@ bool ZipUtil::extractArchive(QString& dest)
88 if(m_zip->getCurrentFileName().split("/").last() == "") 101 if(m_zip->getCurrentFileName().split("/").last() == "")
89 continue; 102 continue;
90 103
91 QString outfilename = dest + "/" + m_zip->getCurrentFileName(); 104 QString outfilename;
105 if(!singleoutfile.isEmpty()
106 && QFileInfo(m_zip->getCurrentFileName()).fileName() == file) {
107 outfilename = singleoutfile;
108 }
109 else if(singleoutfile.isEmpty()) {
110 outfilename = dest + "/" + m_zip->getCurrentFileName();
111 }
112 if(outfilename.isEmpty())
113 continue;
92 QFile outputFile(outfilename); 114 QFile outputFile(outfilename);
93 // make sure the output path exists 115 // make sure the output path exists
94 if(!QDir().mkpath(QFileInfo(outfilename).absolutePath())) { 116 if(!QDir().mkpath(QFileInfo(outfilename).absolutePath())) {