Skip to content

Commit f60d40a

Browse files
committed
use VSIReadDir() from gdal instead of quazip for listing .zip files and remove quazip entirely, including HAVE_ZLIB variable ; set default scanZip to 2 (Basic Scan)
1 parent e23e21f commit f60d40a

35 files changed

+78
-7402
lines changed

CMakeLists.txt

-14
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,6 @@ FIND_PROGRAM(QT_LRELEASE_EXECUTABLE
258258
NO_DEFAULT_PATH
259259
)
260260

261-
262-
#############################################################
263-
# search for zlib optional, used by quazip
264-
# this uses script provided by cmake
265-
# if WIN32 should use zlib from QT
266-
FIND_PACKAGE(ZLIB)
267-
IF (ZLIB_FOUND)
268-
MESSAGE(STATUS "Found zlib: ${ZLIB_LIBRARY}")
269-
SET(HAVE_ZLIB TRUE)
270-
ELSE (ZLIB_FOUND)
271-
MESSAGE(STATUS "Could not find zlib (optional)")
272-
ENDIF(ZLIB_FOUND)
273-
274-
275261
#############################################################
276262
# enable warnings
277263

PROVENANCE

-31
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,4 @@ licensed under the GPL or LGPL, version 2.
6868
== External Source Files ==
6969
The following files are included in the QGIS source tree from external
7070
sources. The source, license, and copyright are noted for each.
71-
=== src/core/quazip ===
72-
QuaZIP is the C++ wrapper for the Gilles Vollant's ZIP/UNZIP package
73-
using Trolltech's Qt library.
74-
Copyright (C) 2005-2011 Sergey A. Tachenov
75-
Added to the QGIS source tree 17 April 2012 as part of a patch from
76-
Etienne Tourigny <etourigny.dev@gmail.com>
77-
78-
* COPYING
79-
* ioapi.h
80-
* JlCompress.h
81-
* quaadler32.cpp
82-
* quachecksum32.h
83-
* quacrc32.h
84-
* quazipfile.cpp
85-
* quazipfileinfo.h
86-
* quazip.h
87-
* quazipnewinfo.h
88-
* unzip.c
89-
* zip.c
90-
* crypt.h
91-
* JlCompress.cpp
92-
* qioapi.cpp
93-
* quaadler32.h
94-
* quacrc32.cpp
95-
* quazip.cpp
96-
* quazipfile.h
97-
* quazip_global.h
98-
* quazipnewinfo.cpp
99-
* README.txt
100-
* unzip.h
101-
* zip.h
10271

cmake_templates/qgsconfig.h.in

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#cmakedefine HAVE_SPATIALITE
3333

34-
#cmakedefine HAVE_ZLIB
35-
3634
#cmakedefine HAVE_MSSQL
3735

3836
#cmakedefine HAVE_PYTHON

src/app/qgsoptions.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
210210
cmbScanZipInBrowser->clear();
211211
cmbScanZipInBrowser->addItem( tr( "No" ) ); // 0
212212
cmbScanZipInBrowser->addItem( tr( "Passthru" ) ); // 1
213-
// only add these options if zlib is available
214-
#ifdef HAVE_ZLIB
215213
cmbScanZipInBrowser->addItem( tr( "Basic scan" ) ); // 2
216214
cmbScanZipInBrowser->addItem( tr( "Full scan" ) ); // 3
217-
cmbScanZipInBrowser->setCurrentIndex( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() );
218-
#else
219-
if ( settings.value( "/qgis/scanZipInBrowser", 1 ) == 0 )
220-
cmbScanZipInBrowser->setCurrentIndex( 0 );
221-
else
222-
cmbScanZipInBrowser->setCurrentIndex( 1 );
223-
#endif
215+
cmbScanZipInBrowser->setCurrentIndex( settings.value( "/qgis/scanZipInBrowser", 2 ).toInt() );
224216

225217
// set the display update threshold
226218
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );

src/core/CMakeLists.txt

-29
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,6 @@ SET(QGIS_CORE_SRCS
177177
qgsspatialindex.cpp
178178
)
179179

180-
IF(HAVE_ZLIB)
181-
ADD_DEFINITIONS(-DQUAZIP_BUILD)
182-
183-
SET(QGIS_CORE_SRCS
184-
${QGIS_CORE_SRCS}
185-
quazip/unzip.c
186-
quazip/zip.c
187-
quazip/JlCompress.cpp
188-
quazip/qioapi.cpp
189-
quazip/quaadler32.cpp
190-
quazip/quacrc32.cpp
191-
quazip/quazip.cpp
192-
quazip/quazipfile.cpp
193-
quazip/quazipnewinfo.cpp
194-
)
195-
ENDIF(HAVE_ZLIB)
196-
197180
IF(WIN32)
198181
SET(QGIS_CORE_SRCS
199182
${QGIS_CORE_SRCS}
@@ -298,13 +281,6 @@ SET(QGIS_CORE_MOC_HDRS
298281
gps/qextserialport/qextserialenumerator.h
299282
)
300283

301-
IF (HAVE_ZLIB)
302-
SET(QGIS_CORE_MOC_HDRS
303-
${QGIS_CORE_MOC_HDRS}
304-
quazip/quazipfile.h
305-
)
306-
ENDIF(HAVE_ZLIB)
307-
308284

309285
IF (QT_MOBILITY_LOCATION_FOUND)
310286
SET(QGIS_CORE_MOC_HDRS
@@ -541,11 +517,6 @@ ELSE (WITH_INTERNAL_SPATIALITE)
541517
TARGET_LINK_LIBRARIES(qgis_core ${SQLITE3_LIBRARY})
542518
ENDIF (WITH_INTERNAL_SPATIALITE)
543519

544-
IF (HAVE_ZLIB)
545-
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
546-
TARGET_LINK_LIBRARIES(qgis_core ${ZLIB_LIBRARY})
547-
ENDIF (HAVE_ZLIB)
548-
549520
IF (APPLE)
550521
SET_TARGET_PROPERTIES(qgis_core PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
551522
ENDIF (APPLE)

src/core/qgsdataitem.cpp

+71-33
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
#include "qgsproviderregistry.h"
3737
#include "qgsconfig.h"
3838

39-
// use internal quazip for /vsizip support
40-
#ifdef HAVE_ZLIB
41-
#define QUAZIP_STATIC
42-
#include <quazip/quazip.h>
43-
#endif
39+
// use GDAL VSI mechanism
40+
#include "cpl_vsi.h"
41+
#include "cpl_string.h"
4442

4543
// shared icons
4644
const QIcon &QgsLayerItem::iconPoint()
@@ -449,7 +447,7 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
449447
QVector<QgsDataItem*> children;
450448
QDir dir( mPath );
451449
QSettings settings;
452-
bool scanZip = ( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() != 0 );
450+
bool scanZip = ( settings.value( "/qgis/scanZipInBrowser", 2 ).toInt() != 0 );
453451

454452
QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
455453
foreach( QString subdir, entries )
@@ -775,14 +773,70 @@ QgsZipItem::~QgsZipItem()
775773
{
776774
}
777775

776+
// internal function to scan a vsidir (zip or tar file) recursively
777+
// hopefully this will make it to GDAL
778+
char **VSIReadDirRecursive1( const char *pszPath )
779+
{
780+
char **papszFiles = NULL;
781+
char **papszFiles1 = NULL;
782+
char **papszFiles2 = NULL;
783+
VSIStatBufL psStatBuf;
784+
char szTemp1[1096];
785+
char szTemp2[1096];
786+
787+
// get listing
788+
papszFiles1 = VSIReadDir( pszPath );
789+
if ( ! papszFiles1 )
790+
return NULL;
791+
792+
// get files and directories inside listing
793+
for ( int i = 0; i < CSLCount( papszFiles1 ); i++ )
794+
{
795+
// build complete file name for stat
796+
strcpy( szTemp1, pszPath );
797+
strcat( szTemp1, ( char* )"/" ); // this might not be ok on windows
798+
strcat( szTemp1, papszFiles1[i] );
799+
// if is file, add it
800+
if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
801+
VSI_ISREG( psStatBuf.st_mode ) )
802+
{
803+
papszFiles = CSLAddString( papszFiles, papszFiles1[i] );
804+
}
805+
else if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
806+
VSI_ISDIR( psStatBuf.st_mode ) )
807+
{
808+
// add directory entry
809+
strcpy( szTemp2, papszFiles1[i] );
810+
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
811+
papszFiles = CSLAddString( papszFiles, szTemp2 );
812+
// recursively add files inside directory
813+
papszFiles2 = VSIReadDirRecursive1( szTemp1 );
814+
if ( papszFiles2 )
815+
{
816+
for ( int j = 0; j < CSLCount( papszFiles2 ); j++ )
817+
{
818+
strcpy( szTemp2, papszFiles1[i] );
819+
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
820+
strcat( szTemp2, papszFiles2[j] );
821+
papszFiles = CSLAddString( papszFiles, szTemp2 );
822+
}
823+
CSLDestroy( papszFiles2 );
824+
}
825+
}
826+
}
827+
CSLDestroy( papszFiles1 );
828+
829+
return papszFiles;
830+
}
831+
778832
QVector<QgsDataItem*> QgsZipItem::createChildren( )
779833
{
780834
QVector<QgsDataItem*> children;
781835
QString tmpPath;
782836
QString childPath;
783837

784838
QSettings settings;
785-
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
839+
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 2 ).toInt();
786840

787841
mZipFileList.clear();
788842

@@ -794,15 +848,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
794848
return children;
795849
}
796850

797-
#ifndef HAVE_ZLIB
798-
// if zlib not available, only support Passthru
799-
if ( scanZipSetting == 2 || scanZipSetting == 3 )
800-
{
801-
scanZipSetting = 1;
802-
settings.setValue( "/qgis/scanZipInBrowser", 1 );
803-
}
804-
#endif
805-
806851
// if scanZipBrowser == 1 (Passthru): do not scan zip and allow to open directly with /vsizip/
807852
if ( scanZipSetting == 1 )
808853
{
@@ -811,32 +856,25 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
811856
return children;
812857
}
813858

814-
#ifdef HAVE_ZLIB
815-
QgsDebugMsg( QString( "Open file %1 with quazip" ).arg( path() ) );
816859
// get list of files inside zip file
817-
QuaZip zip( path() );
818-
if ( ! zip.open( QuaZip::mdUnzip ) || ! zip.isOpen() )
860+
QgsDebugMsg( QString( "Open file %1 with gdal vsi" ).arg( path() ) );
861+
char **papszSiblingFiles = VSIReadDirRecursive1( QString( "/vsizip/" + path() ).toLocal8Bit().constData() );
862+
if ( papszSiblingFiles )
819863
{
820-
QgsDebugMsg( QString( "Zip error: %1" ).arg( zip.getZipError() ) );
821-
}
822-
else
823-
{
824-
for ( bool more = zip.goToFirstFile(); more; more = zip.goToNextFile() )
864+
for ( int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
825865
{
826-
tmpPath = zip.getCurrentFileName();
866+
tmpPath = papszSiblingFiles[i];
867+
QgsDebugMsg( QString( "Read file %1" ).arg( tmpPath ) );
827868
// skip directories (files ending with /)
828869
if ( tmpPath.right( 1 ) != "/" )
829870
mZipFileList << tmpPath;
830871
}
831-
zip.close();
872+
CSLDestroy( papszSiblingFiles );
832873
}
833-
if ( zip.getZipError() != UNZ_OK )
874+
else
834875
{
835-
QgsDebugMsg( QString( "Zip error: %1" ).arg( zip.getZipError() ) );
876+
QgsDebugMsg( QString( "Error reading %1" ).arg( path() ) );
836877
}
837-
#else
838-
QgsDebugMsg( QString( "Cannot open file %1 with quazip - zlib not configured" ).arg( path() ) );
839-
#endif
840878

841879
// loop over files inside zip
842880
foreach( QString fileName, mZipFileList )
@@ -898,7 +936,7 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
898936
QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QString name )
899937
{
900938
QSettings settings;
901-
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
939+
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 2 ).toInt();
902940
QString vsizipPath = path;
903941
int zipFileCount = 0;
904942
QFileInfo fileInfo( path );

0 commit comments

Comments
 (0)