diff options
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallbase.cpp | 41 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallbase.h | 4 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/ziputil.cpp | 28 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/ziputil.h | 4 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.cpp | 23 |
5 files changed, 84 insertions, 16 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 | ||
324 | bool 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 |
75 | bool ZipUtil::extractArchive(QString& dest) | 77 | bool 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); |
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index 403d13a760..958550e880 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp | |||
@@ -708,7 +708,14 @@ void RbUtilQt::installBootloader() | |||
708 | logger->setFinished(); | 708 | logger->setFinished(); |
709 | return; | 709 | return; |
710 | } | 710 | } |
711 | 711 | ||
712 | // the bootloader install class does NOT use any GUI stuff. | ||
713 | // All messages are passed via signals. | ||
714 | connect(bl, SIGNAL(done(bool)), logger, SLOT(setFinished())); | ||
715 | connect(bl, SIGNAL(done(bool)), this, SLOT(installBootloaderPost(bool))); | ||
716 | connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int))); | ||
717 | connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int))); | ||
718 | |||
712 | // set bootloader filename. Do this now as installed() needs it. | 719 | // set bootloader filename. Do this now as installed() needs it. |
713 | QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList(); | 720 | QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList(); |
714 | QStringList blfilepath; | 721 | QStringList blfilepath; |
@@ -788,16 +795,14 @@ void RbUtilQt::installBootloader() | |||
788 | m_error = true; | 795 | m_error = true; |
789 | return; | 796 | return; |
790 | } | 797 | } |
791 | bl->setOfFile(offile); | 798 | if(!bl->setOfFile(offile, blfile)) { |
799 | logger->addItem(tr("Error reading firmware file"), LOGERROR); | ||
800 | logger->setFinished(); | ||
801 | m_error = true; | ||
802 | return; | ||
803 | } | ||
792 | } | 804 | } |
793 | 805 | ||
794 | // the bootloader install class does NOT use any GUI stuff. | ||
795 | // All messages are passed via signals. | ||
796 | connect(bl, SIGNAL(done(bool)), logger, SLOT(setFinished())); | ||
797 | connect(bl, SIGNAL(done(bool)), this, SLOT(installBootloaderPost(bool))); | ||
798 | connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int))); | ||
799 | connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int))); | ||
800 | |||
801 | // start install. | 806 | // start install. |
802 | if(!backupDestination.isEmpty()) { | 807 | if(!backupDestination.isEmpty()) { |
803 | if(!bl->backup(backupDestination)) { | 808 | if(!bl->backup(backupDestination)) { |