]>
git.saurik.com Git - wxWidgets.git/blob - src/common/fs_zip.cpp
706cd05352f97fc565bf9b533d141c7169ebb620
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     ZIP file system 
   4 // Author:      Vaclav Slavik 
   5 // Copyright:   (c) 1999 Vaclav Slavik 
   6 // Licence:     wxWindows Licence 
   7 ///////////////////////////////////////////////////////////////////////////// 
  11 #pragma implementation 
  14 #include "wx/wxprec.h" 
  20 #if wxUSE_FILESYSTEM && wxUSE_FS_ZIP && wxUSE_ZIPSTREAM 
  26 #include "wx/filesys.h" 
  27 #include "wx/zipstrm.h" 
  28 #include "wx/fs_zip.h" 
  30 /* Not the right solution (paths in makefiles) but... */ 
  32 #include "../common/unzip.h" 
  38 //-------------------------------------------------------------------------------- 
  40 //-------------------------------------------------------------------------------- 
  44 wxZipFSHandler::wxZipFSHandler() : wxFileSystemHandler() 
  47     m_ZipFile 
= m_Pattern 
= m_BaseDir 
= wxEmptyString
; 
  48     m_AllowDirs 
= m_AllowFiles 
= TRUE
; 
  53 wxZipFSHandler::~wxZipFSHandler() 
  56         unzClose((unzFile
)m_Archive
); 
  61 bool wxZipFSHandler::CanOpen(const wxString
& location
) 
  63     wxString p 
= GetProtocol(location
); 
  64     return (p 
== wxT("zip") ); 
  70 wxFSFile
* wxZipFSHandler::OpenFile(wxFileSystem
& WXUNUSED(fs
), const wxString
& location
) 
  72     wxString right 
= GetRightLocation(location
); 
  73     wxString left 
= GetLeftLocation(location
); 
  76     if (GetProtocol(left
) != wxT("file")) { 
  80     s 
= new wxZipInputStream(left
, right
); 
  81     if (s 
&& (s 
-> LastError() == wxStream_NOERROR
)) { 
  82         return new wxFSFile(s
, 
  83                             left 
+ wxT("#zip:") + right
, 
  84                             GetMimeTypeFromExt(location
), 
  86                             wxDateTime(wxFileModificationTime(left
))); 
  98 wxString 
wxZipFSHandler::FindFirst(const wxString
& spec
, int flags
) 
 100     wxString right 
= GetRightLocation(spec
); 
 101     wxString left 
= GetLeftLocation(spec
); 
 103     if (right
.Last() == wxT('/')) right
.RemoveLast(); 
 106         unzClose((unzFile
)m_Archive
); 
 110     if (GetProtocol(left
) != wxT("file")) { 
 111         return wxEmptyString
; 
 115         case wxFILE  
: m_AllowDirs 
= FALSE
, m_AllowFiles 
= TRUE
; break; 
 116         case wxDIR   
: m_AllowDirs 
= TRUE
, m_AllowFiles 
= FALSE
; break; 
 117         default : m_AllowDirs 
= m_AllowFiles 
= TRUE
; break; 
 121     m_Archive 
= (void*) unzOpen(m_ZipFile
.mb_str()); 
 122     m_Pattern 
= right
.AfterLast(wxT('/')); 
 123     m_BaseDir 
= right
.BeforeLast(wxT('/')); 
 126         if (unzGoToFirstFile((unzFile
)m_Archive
) != UNZ_OK
) { 
 127             unzClose((unzFile
)m_Archive
); 
 136 wxString 
wxZipFSHandler::FindNext() 
 138     if (!m_Archive
) return wxEmptyString
; 
 144 wxString 
wxZipFSHandler::DoFind() 
 146     static char namebuf
[1024]; // char, not wxChar! 
 148     wxString fn
, dir
, name
; 
 149     wxString match 
= wxEmptyString
; 
 152     while (match 
== wxEmptyString
) 
 154         unzGetCurrentFileInfo((unzFile
)m_Archive
, NULL
, namebuf
, 1024, NULL
, 0, NULL
, 0); 
 155         for (c 
= namebuf
; *c
; c
++) if (*c 
== wxT('\\')) *c 
= wxT('/'); 
 157         if (fn
.Last() == wxT('/')) { 
 163         name 
= fn
.AfterLast(wxT('/')); 
 164         dir 
= fn
.BeforeLast(wxT('/')); 
 166         if (dir 
== m_BaseDir
) { 
 167             if (m_AllowFiles 
&& !wasdir 
&& wxMatchWild(m_Pattern
, name
, FALSE
)) 
 168                 match 
= m_ZipFile 
+ wxT("#zip:") + fn
; 
 169             if (m_AllowDirs 
&& wasdir 
&& wxMatchWild(m_Pattern
, name
, FALSE
)) 
 170                 match 
= m_ZipFile 
+ wxT("#zip:") + fn
; 
 173         if (unzGoToNextFile((unzFile
)m_Archive
) != UNZ_OK
) { 
 174             unzClose((unzFile
)m_Archive
); 
 186       //wxUSE_FILESYSTEM && wxUSE_FS_ZIP && wxUSE_ZIPSTREAM