]>
git.saurik.com Git - wxWidgets.git/blob - src/common/zipstrm.cpp
fb191d35c330b953305a74205505cb64366c938b
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     input stream for ZIP archive access 
   4 // Author:      Vaclav Slavik 
   5 // Copyright:   (c) 1999 Vaclav Slavik 
   6 // Licence:     wxWindows Licence 
   7 ///////////////////////////////////////////////////////////////////////////// 
  10 #pragma implementation "zipstrm.h" 
  13 // For compilers that support precompilation, includes "wx.h". 
  14 #include "wx/wxprec.h" 
  20 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB 
  24 #include "wx/stream.h" 
  25 #include "wx/wfstream.h" 
  26 #include "wx/zipstrm.h" 
  28 /* Not the right solution (paths in makefiles) but... */ 
  30 #include "../common/unzip.h" 
  36 wxZipInputStream::wxZipInputStream(const wxString
& archive
, const wxString
& file
) : wxInputStream() 
  42     m_Archive 
= (void*) unzOpen(archive
.mb_str()); 
  43     if (m_Archive 
== NULL
) 
  45         m_lasterror 
= wxStream_READ_ERR
; 
  48     if (unzLocateFile((unzFile
)m_Archive
, file
.mb_str(), 0) != UNZ_OK
) 
  50         m_lasterror 
= wxStream_READ_ERR
; 
  54     unzGetCurrentFileInfo((unzFile
)m_Archive
, &zinfo
, (char*) NULL
, 0, (void*) NULL
, 0, (char*) NULL
, 0); 
  56     if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
) 
  58         m_lasterror 
= wxStream_READ_ERR
; 
  61     m_Size 
= (size_t)zinfo
.uncompressed_size
; 
  66 wxZipInputStream::~wxZipInputStream() 
  71             unzCloseCurrentFile((unzFile
)m_Archive
); 
  72         unzClose((unzFile
)m_Archive
); 
  76 bool wxZipInputStream::Eof() const 
  78     wxASSERT_MSG( m_Pos 
<= (off_t
)m_Size
, 
  79                   _T("wxZipInputStream: invalid current position") ); 
  81     return m_Pos 
>= (off_t
)m_Size
; 
  85 size_t wxZipInputStream::OnSysRead(void *buffer
, size_t bufsize
) 
  87     wxASSERT_MSG( m_Pos 
<= (off_t
)m_Size
, 
  88                   _T("wxZipInputStream: invalid current position") ); 
  90     if ( m_Pos 
>= (off_t
)m_Size 
) 
  92         m_lasterror 
= wxStream_EOF
; 
  96     if (m_Pos 
+ bufsize 
> m_Size
) 
  97         bufsize 
= m_Size 
- m_Pos
; 
  99     unzReadCurrentFile((unzFile
)m_Archive
, buffer
, bufsize
); 
 107 off_t 
wxZipInputStream::OnSysSeek(off_t seek
, wxSeekMode mode
) 
 114         case wxFromCurrent 
: nextpos 
= seek 
+ m_Pos
; break; 
 115         case wxFromStart 
: nextpos 
= seek
; break; 
 116         case wxFromEnd 
: nextpos 
= m_Size 
- 1 + seek
; break; 
 117         default : nextpos 
= m_Pos
; break; /* just to fool compiler, never happens */ 
 123         buf 
= malloc(nextpos 
- m_Pos
); 
 124         unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos 
-  m_Pos
); 
 127     else if (nextpos 
< m_Pos
) { 
 128         unzCloseCurrentFile((unzFile
)m_Archive
); 
 129         if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
) 
 131             m_lasterror 
= wxStream_READ_ERR
; 
 134         buf 
= malloc(nextpos
); 
 135         unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
); 
 144   // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB