diff options
Diffstat (limited to 'rbutil/rbutilqt/base/ziputil.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/ziputil.cpp | 28 |
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 |
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())) { |