X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6001e347baf63a91be525f3b9beeefde4bc16f19..0fccf28fe6cfd00c63eac76d5aa27b8ce1330467:/src/common/zipstrm.cpp diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index d334dd8c58..fb191d35c3 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -7,7 +7,7 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "zipstream.h" +#pragma implementation "zipstrm.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -17,7 +17,7 @@ #pragma hdrstop #endif -#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB +#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB #include "wx/log.h" #include "wx/intl.h" @@ -39,33 +39,33 @@ wxZipInputStream::wxZipInputStream(const wxString& archive, const wxString& file m_Pos = 0; m_Size = 0; - m_Archive = (void*) unzOpen(archive.mb_str(wxConvFile)); - if (m_Archive == NULL) + m_Archive = (void*) unzOpen(archive.mb_str()); + if (m_Archive == NULL) { m_lasterror = wxStream_READ_ERR; return; } - if (unzLocateFile((unzFile)m_Archive, file.mb_str(wxConvFile), 0) != UNZ_OK) + if (unzLocateFile((unzFile)m_Archive, file.mb_str(), 0) != UNZ_OK) { m_lasterror = wxStream_READ_ERR; return; } - + unzGetCurrentFileInfo((unzFile)m_Archive, &zinfo, (char*) NULL, 0, (void*) NULL, 0, (char*) NULL, 0); - if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK) + if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK) { m_lasterror = wxStream_READ_ERR; return; } - m_Size = zinfo.uncompressed_size; + m_Size = (size_t)zinfo.uncompressed_size; } wxZipInputStream::~wxZipInputStream() { - if (m_Archive) + if (m_Archive) { if (m_Size != 0) unzCloseCurrentFile((unzFile)m_Archive); @@ -73,13 +73,32 @@ wxZipInputStream::~wxZipInputStream() } } +bool wxZipInputStream::Eof() const +{ + wxASSERT_MSG( m_Pos <= (off_t)m_Size, + _T("wxZipInputStream: invalid current position") ); + + return m_Pos >= (off_t)m_Size; +} size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize) { - if (m_Pos + bufsize > m_Size) bufsize = m_Size - m_Pos; + wxASSERT_MSG( m_Pos <= (off_t)m_Size, + _T("wxZipInputStream: invalid current position") ); + + if ( m_Pos >= (off_t)m_Size ) + { + m_lasterror = wxStream_EOF; + return 0; + } + + if (m_Pos + bufsize > m_Size) + bufsize = m_Size - m_Pos; + unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize); m_Pos += bufsize; + return bufsize; } @@ -90,7 +109,7 @@ off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode) off_t nextpos; void *buf; - switch (mode) + switch (mode) { case wxFromCurrent : nextpos = seek + m_Pos; break; case wxFromStart : nextpos = seek; break; @@ -99,7 +118,7 @@ off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode) } // cheated seeking : - if (nextpos > m_Pos) + if (nextpos > m_Pos) { buf = malloc(nextpos - m_Pos); unzReadCurrentFile((unzFile)m_Archive, buf, nextpos - m_Pos); @@ -107,8 +126,8 @@ off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode) } else if (nextpos < m_Pos) { unzCloseCurrentFile((unzFile)m_Archive); - if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK) - { + if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK) + { m_lasterror = wxStream_READ_ERR; return m_Pos; } @@ -122,4 +141,4 @@ off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode) } #endif - // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB + // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB