36
36
#include " qgsproviderregistry.h"
37
37
#include " qgsconfig.h"
38
38
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"
44
42
45
43
// shared icons
46
44
const QIcon &QgsLayerItem::iconPoint ()
@@ -449,7 +447,7 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
449
447
QVector<QgsDataItem*> children;
450
448
QDir dir ( mPath );
451
449
QSettings settings;
452
- bool scanZip = ( settings.value ( " /qgis/scanZipInBrowser" , 1 ).toInt () != 0 );
450
+ bool scanZip = ( settings.value ( " /qgis/scanZipInBrowser" , 2 ).toInt () != 0 );
453
451
454
452
QStringList entries = dir.entryList ( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
455
453
foreach ( QString subdir, entries )
@@ -775,14 +773,70 @@ QgsZipItem::~QgsZipItem()
775
773
{
776
774
}
777
775
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
+
778
832
QVector<QgsDataItem*> QgsZipItem::createChildren ( )
779
833
{
780
834
QVector<QgsDataItem*> children;
781
835
QString tmpPath;
782
836
QString childPath;
783
837
784
838
QSettings settings;
785
- int scanZipSetting = settings.value ( " /qgis/scanZipInBrowser" , 1 ).toInt ();
839
+ int scanZipSetting = settings.value ( " /qgis/scanZipInBrowser" , 2 ).toInt ();
786
840
787
841
mZipFileList .clear ();
788
842
@@ -794,15 +848,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
794
848
return children;
795
849
}
796
850
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
-
806
851
// if scanZipBrowser == 1 (Passthru): do not scan zip and allow to open directly with /vsizip/
807
852
if ( scanZipSetting == 1 )
808
853
{
@@ -811,32 +856,25 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
811
856
return children;
812
857
}
813
858
814
- #ifdef HAVE_ZLIB
815
- QgsDebugMsg ( QString ( " Open file %1 with quazip" ).arg ( path () ) );
816
859
// 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 )
819
863
{
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++ )
825
865
{
826
- tmpPath = zip.getCurrentFileName ();
866
+ tmpPath = papszSiblingFiles[i];
867
+ QgsDebugMsg ( QString ( " Read file %1" ).arg ( tmpPath ) );
827
868
// skip directories (files ending with /)
828
869
if ( tmpPath.right ( 1 ) != " /" )
829
870
mZipFileList << tmpPath;
830
871
}
831
- zip. close ( );
872
+ CSLDestroy ( papszSiblingFiles );
832
873
}
833
- if ( zip. getZipError () != UNZ_OK )
874
+ else
834
875
{
835
- QgsDebugMsg ( QString ( " Zip error: %1" ).arg ( zip. getZipError () ) );
876
+ QgsDebugMsg ( QString ( " Error reading %1" ).arg ( path () ) );
836
877
}
837
- #else
838
- QgsDebugMsg ( QString ( " Cannot open file %1 with quazip - zlib not configured" ).arg ( path () ) );
839
- #endif
840
878
841
879
// loop over files inside zip
842
880
foreach ( QString fileName, mZipFileList )
@@ -898,7 +936,7 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
898
936
QgsDataItem* QgsZipItem::itemFromPath ( QgsDataItem* parent, QString path, QString name )
899
937
{
900
938
QSettings settings;
901
- int scanZipSetting = settings.value ( " /qgis/scanZipInBrowser" , 1 ).toInt ();
939
+ int scanZipSetting = settings.value ( " /qgis/scanZipInBrowser" , 2 ).toInt ();
902
940
QString vsizipPath = path;
903
941
int zipFileCount = 0 ;
904
942
QFileInfo fileInfo ( path );
0 commit comments