summaryrefslogtreecommitdiffstats
path: root/quazip.patch
blob: bbd0bb1edc5e95fd2a64fb3d0f19d9a7b2acdd41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 250)
+++ CMakeLists.txt	(working copy)
@@ -51,4 +51,4 @@
 
 add_subdirectory(quazip)
 
-install(FILES FindQuaZip.cmake DESTINATION ${CMAKE_ROOT}/Modules)
+#install(FILES FindQuaZip.cmake DESTINATION ${CMAKE_ROOT}/Modules)
Index: quazip/CMakeLists.txt
===================================================================
--- quazip/CMakeLists.txt	(revision 250)
+++ quazip/CMakeLists.txt	(working copy)
@@ -14,10 +14,14 @@
 qt_wrap_cpp(MOC_SRCS ${PUBLIC_HEADERS})
 set(SRCS ${SRCS} ${MOC_SRCS})
 
-add_library(quazip SHARED ${SRCS})
-set_target_properties(quazip PROPERTIES VERSION 1.0.0 SOVERSION 1)
+add_library(quazip STATIC ${SRCS})
+#set_target_properties(quazip PROPERTIES VERSION 1.0.0 SOVERSION 1)
 # Link against ZLIB_LIBRARIES if needed (on Windows this variable is empty)
-target_link_libraries(quazip ${QT_QTMAIN_LIBRARY} ${QT_QTCORE_LIBRARY} ${ZLIB_LIBRARIES})
+target_link_libraries(quazip ${ZLIB_LIBRARIES})
+qt5_use_modules(quazip Core)
+if(WIN32)
+    add_definitions(-DZ_PREFIX)
+endif()
 
 install(FILES ${PUBLIC_HEADERS} DESTINATION include/quazip)
 install(TARGETS quazip LIBRARY DESTINATION ${LIB_DESTINATION} ARCHIVE DESTINATION ${LIB_DESTINATION} RUNTIME DESTINATION ${LIB_DESTINATION})
Index: quazip/JlCompress.cpp
===================================================================
--- quazip/JlCompress.cpp	(revision 250)
+++ quazip/JlCompress.cpp	(working copy)
@@ -26,7 +26,7 @@
 #include "JlCompress.h"
 #include <QDebug>
 
-static bool copyData(QIODevice &inFile, QIODevice &outFile)
+bool JlCompress::copyData(QIODevice &inFile, QIODevice &outFile)
 {
     while (!inFile.atEnd()) {
         char buf[4096];
@@ -100,7 +100,7 @@
  * dunque gli errori di compressione di una sotto cartella sono gli stessi di questa
  * funzione.
  */
-bool JlCompress::compressSubDir(QuaZip* zip, QString dir, QString origDir, bool recursive) {
+bool JlCompress::compressSubDir(QuaZip* zip, QString dir, QString origDir, bool recursive, QSet<QString>& added) {
     // zip: oggetto dove aggiungere il file
     // dir: cartella reale corrente
     // origDir: cartella reale originale
@@ -133,7 +133,7 @@
         QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot);
         Q_FOREACH (QFileInfo file, files) {
             // Comprimo la sotto cartella
-            if(!compressSubDir(zip,file.absoluteFilePath(),origDir,recursive)) return false;
+			if(!compressSubDir(zip,file.absoluteFilePath(),origDir,recursive,added)) return false;
         }
     }
 
@@ -148,6 +148,7 @@
 
         // Comprimo il file
         if (!compressFile(zip,file.absoluteFilePath(),filename)) return false;
+		added.insert(filename);
     }
 
     return true;
@@ -344,8 +345,9 @@
         return false;
     }
 
+	QSet<QString> added;
     // Aggiungo i file e le sotto cartelle
-    if (!compressSubDir(&zip,dir,dir,recursive)) {
+	if (!compressSubDir(&zip,dir,dir,recursive,added)) {
         QFile::remove(fileCompressed);
         return false;
     }
@@ -437,6 +439,53 @@
     return extracted;
 }
 
+QStringList JlCompress::extractWithExceptions(QString fileCompressed, QString dir, QStringList exceptions)
+{
+	QuaZip zip(fileCompressed);
+	if(!zip.open(QuaZip::mdUnzip))
+	{
+		return QStringList();
+	}
+
+	QDir directory(dir);
+	QStringList extracted;
+	if (!zip.goToFirstFile())
+	{
+		return QStringList();
+	}
+	do
+	{
+		QString name = zip.getCurrentFileName();
+		bool ok = true;
+		for(auto str: exceptions)
+		{
+			if(name.startsWith(str))
+			{
+				ok = false;
+				break;
+			}
+		}
+		if(!ok)
+			continue;
+		QString absFilePath = directory.absoluteFilePath(name);
+		if (!JlCompress::extractFile(&zip, "", absFilePath))
+		{
+			JlCompress::removeFile(extracted);
+			return QStringList();
+		}
+		extracted.append(absFilePath);
+	} while (zip.goToNextFile());
+
+	zip.close();
+	if(zip.getZipError()!=0)
+	{
+		JlCompress::removeFile(extracted);
+		return QStringList();
+	}
+
+	return extracted;
+}
+
 /**OK
  * Estrae il file fileCompressed nella cartella dir.
  * Se dir = "" allora il file viene estratto nella cartella corrente.
Index: quazip/JlCompress.h
===================================================================
--- quazip/JlCompress.h	(revision 250)
+++ quazip/JlCompress.h	(working copy)
@@ -40,7 +40,7 @@
   simple operations, such as mass ZIP packing or extraction.
   */
 class QUAZIP_EXPORT JlCompress {
-private:
+public:
     /// Compress a single file.
     /**
       \param zip Opened zip to compress the file to.
@@ -59,7 +59,7 @@
       files.
       \return true if success, false otherwise.
       */
-    static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive = true);
+	static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive, QSet<QString>& added);
     /// Extract a single file.
     /**
       \param zip The opened zip archive to extract from.
@@ -68,6 +68,7 @@
       \return true if success, false otherwise.
       */
     static bool extractFile(QuaZip* zip, QString fileName, QString fileDest);
+private:
     /// Remove some files.
     /**
       \param listFile The list of files to remove.
@@ -76,6 +77,8 @@
     static bool removeFile(QStringList listFile);
 
 public:
+	/// copy data from inFile to outFile
+	static bool copyData(QIODevice &inFile, QIODevice &outFile);
     /// Compress a single file.
     /**
       \param fileCompressed The name of the archive.
@@ -127,6 +130,15 @@
       \return The list of the full paths of the files extracted, empty on failure.
       */
     static QStringList extractDir(QString fileCompressed, QString dir = QString());
+	/// Extract a whole archive, with a list of exceptions (prefixes to ignore).
+	/**
+	  \param fileCompressed The name of the archive.
+	  \param dir The directory to extract to, the current directory if
+	  left empty.
+	  \param exceptions The list of exception prefixes
+	  \return The list of the full paths of the files extracted, empty on failure.
+	  */
+	static QStringList extractWithExceptions(QString fileCompressed, QString dir, QStringList exceptions);
     /// Get the file list.
     /**
       \return The list of the files in the archive, or, more precisely, the