summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base
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
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')
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstallbase.cpp41
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstallbase.h4
-rw-r--r--rbutil/rbutilqt/base/ziputil.cpp28
-rw-r--r--rbutil/rbutilqt/base/ziputil.h4
4 files changed, 70 insertions, 7 deletions
diff --git a/rbutil/rbutilqt/base/bootloaderinstallbase.cpp b/rbutil/rbutilqt/base/bootloaderinstallbase.cpp
index 750e33bef8..7941f24309 100644
--- a/rbutil/rbutilqt/base/bootloaderinstallbase.cpp
+++ b/rbutil/rbutilqt/base/bootloaderinstallbase.cpp
@@ -31,6 +31,7 @@
31#include "bootloaderinstallmpio.h" 31#include "bootloaderinstallmpio.h"
32#include "bootloaderinstallimx.h" 32#include "bootloaderinstallimx.h"
33#include "utils.h" 33#include "utils.h"
34#include "ziputil.h"
34 35
35#if defined(Q_OS_MACX) 36#if defined(Q_OS_MACX)
36#include <sys/param.h> 37#include <sys/param.h>
@@ -320,3 +321,43 @@ void BootloaderInstallBase::setBlFile(QStringList sl)
320 } 321 }
321} 322}
322 323
324bool BootloaderInstallBase::setOfFile(QString of, QStringList blfile)
325{
326 bool found = false;
327 ZipUtil z(this);
328 // check if the file set is in zip format
329 if(z.open(of)) {
330 emit logItem(tr("Zip file format detected"), LOGINFO);
331 QStringList contents = z.files();
332 qDebug() << "[BootloaderInstallBase] archive contains:" << contents;
333 for(int i = 0; i < blfile.size(); ++i) {
334 // strip any path, we don't know the structure in the zip
335 QString f = QFileInfo(blfile.at(i)).fileName();
336 qDebug() << "[BootloaderInstallBase] searching archive for" << f;
337 int index = contents.indexOf(f); // FIXME: support files in folders
338 if(index >= 0) {
339 found = true;
340 emit logItem(tr("Extracting firmware %1 from archive")
341 .arg(f), LOGINFO);
342 // store in class temporary file
343 m_tempof.open();
344 m_offile = m_tempof.fileName();
345 m_tempof.close();
346 if(!z.extractArchive(m_offile, contents.at(index))) {
347 emit logItem(tr("Error extracting firmware from archive"), LOGERROR);
348 found = false;
349 break;
350 }
351 }
352 }
353 if(!found) {
354 emit logItem(tr("Could not find firmware in archive"), LOGERROR);
355 }
356
357 }
358 else {
359 m_offile = of;
360 found = true;
361 }
362 return found;
363}
diff --git a/rbutil/rbutilqt/base/bootloaderinstallbase.h b/rbutil/rbutilqt/base/bootloaderinstallbase.h
index 8198d54e76..0e970c4af6 100644
--- a/rbutil/rbutilqt/base/bootloaderinstallbase.h
+++ b/rbutil/rbutilqt/base/bootloaderinstallbase.h
@@ -60,8 +60,7 @@ class BootloaderInstallBase : public QObject
60 { m_blurl = u; } 60 { m_blurl = u; }
61 void setLogfile(QString f) 61 void setLogfile(QString f)
62 { m_logfile = f; } 62 { m_logfile = f; }
63 void setOfFile(QString f) 63 bool setOfFile(QString of, QStringList blfile);
64 {m_offile = f;}
65 64
66 //! returns a port Install Hint or empty if there is none 65 //! returns a port Install Hint or empty if there is none
67 //! static and in the base class, so the installer classes dont need to 66 //! static and in the base class, so the installer classes dont need to
@@ -90,6 +89,7 @@ class BootloaderInstallBase : public QObject
90 QString m_logfile; //! file for installation log 89 QString m_logfile; //! file for installation log
91 QUrl m_blurl; //! bootloader download URL 90 QUrl m_blurl; //! bootloader download URL
92 QTemporaryFile m_tempfile; //! temporary file for download 91 QTemporaryFile m_tempfile; //! temporary file for download
92 QTemporaryFile m_tempof; //! temporary file for OF extracted from archive
93 QDateTime m_blversion; //! download timestamp used for version information 93 QDateTime m_blversion; //! download timestamp used for version information
94 QString m_offile; //! path to the offile 94 QString m_offile; //! path to the offile
95#if defined(Q_OS_MACX) 95#if defined(Q_OS_MACX)
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())) {
diff --git a/rbutil/rbutilqt/base/ziputil.h b/rbutil/rbutilqt/base/ziputil.h
index 9cbb67488a..a6b0a8ca9c 100644
--- a/rbutil/rbutilqt/base/ziputil.h
+++ b/rbutil/rbutilqt/base/ziputil.h
@@ -31,9 +31,9 @@ class ZipUtil : public QObject
31 public: 31 public:
32 ZipUtil(QObject* parent); 32 ZipUtil(QObject* parent);
33 ~ZipUtil(); 33 ~ZipUtil();
34 bool open(QString& zipfile, QuaZip::Mode mode); 34 bool open(QString& zipfile, QuaZip::Mode mode = QuaZip::mdUnzip);
35 bool close(void); 35 bool close(void);
36 bool extractArchive(QString& dest); 36 bool extractArchive(QString& dest, QString file = "");
37 bool appendDirToArchive(QString& source, QString& basedir); 37 bool appendDirToArchive(QString& source, QString& basedir);
38 bool appendFileToArchive(QString& file, QString& basedir); 38 bool appendFileToArchive(QString& file, QString& basedir);
39 qint64 totalUncompressedSize(unsigned int clustersize = 0); 39 qint64 totalUncompressedSize(unsigned int clustersize = 0);