projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added -w-inl to CFG section to suppress the annoying messages about event and radiobo...
[wxWidgets.git]
/
src
/
common
/
zipstrm.cpp
diff --git
a/src/common/zipstrm.cpp
b/src/common/zipstrm.cpp
index 70e700e651d508493de12dd2848b268004111c6c..1ed942c0eac984ac65d2c023bd7642ec2703676a 100644
(file)
--- a/
src/common/zipstrm.cpp
+++ b/
src/common/zipstrm.cpp
@@
-17,13
+17,14
@@
#pragma hdrstop
#endif
#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"
#include "wx/stream.h"
#include "wx/wfstream.h"
#include "wx/zipstrm.h"
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/stream.h"
#include "wx/wfstream.h"
#include "wx/zipstrm.h"
+#include "wx/utils.h"
/* Not the right solution (paths in makefiles) but... */
#ifdef __BORLANDC__
/* Not the right solution (paths in makefiles) but... */
#ifdef __BORLANDC__
@@
-39,33
+40,33
@@
wxZipInputStream::wxZipInputStream(const wxString& archive, const wxString& file
m_Pos = 0;
m_Size = 0;
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 = wxS
tream_READ_ER
R;
+ m_lasterror = wxS
TREAM_READ_ERRO
R;
return;
}
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 = wxS
tream_READ_ER
R;
+ m_lasterror = wxS
TREAM_READ_ERRO
R;
return;
}
return;
}
-
+
unzGetCurrentFileInfo((unzFile)m_Archive, &zinfo, (char*) NULL, 0, (void*) NULL, 0, (char*) NULL, 0);
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 = wxS
tream_READ_ER
R;
+ m_lasterror = wxS
TREAM_READ_ERRO
R;
return;
}
return;
}
- m_Size = zinfo.uncompressed_size;
+ m_Size =
(size_t)
zinfo.uncompressed_size;
}
wxZipInputStream::~wxZipInputStream()
{
}
wxZipInputStream::~wxZipInputStream()
{
- if (m_Archive)
+ if (m_Archive)
{
if (m_Size != 0)
unzCloseCurrentFile((unzFile)m_Archive);
{
if (m_Size != 0)
unzCloseCurrentFile((unzFile)m_Archive);
@@
-73,13
+74,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)
{
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;
unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize);
m_Pos += bufsize;
+
return bufsize;
}
return bufsize;
}
@@
-87,10
+107,14
@@
size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize)
off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
{
off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
{
+ // NB: since ZIP files don't natively support seeking, we have to
+ // implement a brute force workaround -- reading all the data
+ // between current and the new position (or between beginning of
+ // the file and new position...)
+
off_t nextpos;
off_t nextpos;
- void *buf;
- switch (
mode)
+ switch (
mode )
{
case wxFromCurrent : nextpos = seek + m_Pos; break;
case wxFromStart : nextpos = seek; break;
{
case wxFromCurrent : nextpos = seek + m_Pos; break;
case wxFromStart : nextpos = seek; break;
@@
-98,23
+122,33
@@
off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
default : nextpos = m_Pos; break; /* just to fool compiler, never happens */
}
default : nextpos = m_Pos; break; /* just to fool compiler, never happens */
}
- // cheated seeking :
- if (
nextpos > m_Pos)
+ size_t toskip = 0;
+ if (
nextpos > m_Pos )
{
{
- buf = malloc(nextpos - m_Pos);
- unzReadCurrentFile((unzFile)m_Archive, buf, nextpos - m_Pos);
- free(buf);
+ toskip = nextpos - m_Pos;
}
}
- else if (nextpos < m_Pos) {
+ else
+ {
unzCloseCurrentFile((unzFile)m_Archive);
unzCloseCurrentFile((unzFile)m_Archive);
- if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK)
- {
- m_lasterror = wxS
tream_READ_ER
R;
+ if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK)
+
{
+ m_lasterror = wxS
TREAM_READ_ERRO
R;
return m_Pos;
}
return m_Pos;
}
- buf = malloc(nextpos);
- unzReadCurrentFile((unzFile)m_Archive, buf, nextpos);
- free(buf);
+ toskip = nextpos;
+ }
+
+ if ( toskip > 0 )
+ {
+ const size_t BUFSIZE = 4096;
+ size_t sz;
+ char buffer[BUFSIZE];
+ while ( toskip > 0 )
+ {
+ sz = wxMin(toskip, BUFSIZE);
+ unzReadCurrentFile((unzFile)m_Archive, buffer, sz);
+ toskip -= sz;
+ }
}
m_Pos = nextpos;
}
m_Pos = nextpos;
@@
-122,4
+156,4
@@
off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
}
#endif
}
#endif
- // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
+ // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB