#include "wx/datstrm.h"
#include "wx/zstream.h"
#include "wx/mstream.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/wfstream.h"
#include "zlib.h"
//
static wxFileOffset QuietSeek(wxInputStream& stream, wxFileOffset pos)
{
-#if defined(__WXDEBUG__) && wxUSE_LOG
+#if wxUSE_LOG
wxLogLevel level = wxLog::GetLogLevel();
wxLog::SetLogLevel(wxLOG_Debug - 1);
wxFileOffset result = stream.SeekI(pos);
/////////////////////////////////////////////////////////////////////////////
// Class factory
-wxZipClassFactory g_wxZipClassFactory;
+static wxZipClassFactory g_wxZipClassFactory;
wxZipClassFactory::wxZipClassFactory()
{
const wxChar * const *
wxZipClassFactory::GetProtocols(wxStreamProtocolType type) const
{
- static const wxChar *protocols[] = { _T("zip"), NULL };
- static const wxChar *mimetypes[] = { _T("application/zip"), NULL };
- static const wxChar *fileexts[] = { _T(".zip"), _T(".htb"), NULL };
+ static const wxChar *protocols[] = { wxT("zip"), NULL };
+ static const wxChar *mimetypes[] = { wxT("application/zip"), NULL };
+ static const wxChar *fileexts[] = { wxT(".zip"), wxT(".htb"), NULL };
static const wxChar *empty[] = { NULL };
switch (type) {
m_pos(0),
m_ok(false)
{
- wxCHECK_RET(size <= sizeof(m_data), _T("buffer too small"));
+ wxCHECK_RET(size <= sizeof(m_data), wxT("buffer too small"));
m_size = stream.Read(m_data, size).LastRead();
m_ok = m_size == size;
}
wxFileOffset m_pos;
wxFileOffset m_len;
- DECLARE_NO_COPY_CLASS(wxStoredInputStream)
+ wxDECLARE_NO_COPY_CLASS(wxStoredInputStream);
};
wxStoredInputStream::wxStoredInputStream(wxInputStream& stream)
private:
wxFileOffset m_pos;
- DECLARE_NO_COPY_CLASS(wxStoredOutputStream)
+ wxDECLARE_NO_COPY_CLASS(wxStoredOutputStream);
};
size_t wxStoredOutputStream::OnSysWrite(const void *buffer, size_t size)
size_t m_start;
size_t m_end;
- DECLARE_NO_COPY_CLASS(wxTeeInputStream)
+ wxDECLARE_NO_COPY_CLASS(wxTeeInputStream);
};
wxTeeInputStream::wxTeeInputStream(wxInputStream& stream)
enum { BUFSIZE = 8192 };
wxCharBuffer m_dummy;
- DECLARE_NO_COPY_CLASS(wxRawInputStream)
+ wxDECLARE_NO_COPY_CLASS(wxRawInputStream);
};
wxRawInputStream::wxRawInputStream(wxInputStream& stream)
switch (wxFileName::GetFormat(format)) {
case wxPATH_DOS:
{
- wxString name(isDir ? m_Name + _T("\\") : m_Name);
+ wxString name(isDir ? m_Name + wxT("\\") : m_Name);
for (size_t i = 0; i < name.length(); i++)
- if (name[i] == _T('/'))
- name[i] = _T('\\');
+ if (name[i] == wxT('/'))
+ name[i] = wxT('\\');
return name;
}
case wxPATH_UNIX:
- return isDir ? m_Name + _T("/") : m_Name;
+ return isDir ? m_Name + wxT("/") : m_Name;
default:
;
while (!internal.empty() && *internal.begin() == '/')
internal.erase(0, 1);
- while (!internal.empty() && internal.compare(0, 2, _T("./")) == 0)
+ while (!internal.empty() && internal.compare(0, 2, wxT("./")) == 0)
internal.erase(0, 2);
- if (internal == _T(".") || internal == _T(".."))
+ if (internal == wxT(".") || internal == wxT(".."))
internal = wxEmptyString;
return internal;
if (m_DiskNumber != 0 || m_StartDisk != 0 ||
m_EntriesHere != m_TotalEntries)
+ {
wxLogWarning(_("assuming this is a multi-part zip concatenated"));
+ }
return true;
}
Init();
m_allowSeeking = true;
wxFFileInputStream *ffile;
- ffile = wx_static_cast(wxFFileInputStream*, m_parent_i_stream);
+ ffile = static_cast<wxFFileInputStream*>(m_parent_i_stream);
wxZipEntryPtr_ entry;
- if (ffile->Ok()) {
+ if (ffile->IsOk()) {
do {
entry.reset(GetNextEntry());
}
m_TotalEntries = endrec.GetTotalEntries();
m_Comment = endrec.GetComment();
+ wxUint32 magic = m_TotalEntries ? CENTRAL_MAGIC : END_MAGIC;
+
// Now find the central-directory. we have the file offset of
// the CD, so look there first.
if (m_parent_i_stream->SeekI(endrec.GetOffset()) != wxInvalidOffset &&
- ReadSignature() == CENTRAL_MAGIC) {
- m_signature = CENTRAL_MAGIC;
+ ReadSignature() == magic) {
+ m_signature = magic;
m_position = endrec.GetOffset();
m_offsetAdjustment = 0;
return true;
// to a self extractor, so take the CD size (also in endrec), subtract
// it from the file offset of the end-central-directory and look there.
if (m_parent_i_stream->SeekI(endPos - endrec.GetSize())
- != wxInvalidOffset && ReadSignature() == CENTRAL_MAGIC) {
- m_signature = CENTRAL_MAGIC;
+ != wxInvalidOffset && ReadSignature() == magic) {
+ m_signature = magic;
m_position = endPos - endrec.GetSize();
m_offsetAdjustment = m_position - endrec.GetOffset();
return true;
return IsOk();
}
-// Can be overriden to add support for additional decompression methods
+// Can be overridden to add support for additional decompression methods
//
wxInputStream *wxZipInputStream::OpenDecompressor(wxInputStream& stream)
{
m_lasterror = wxSTREAM_READ_ERROR;
if (m_entry.GetSize() != TellI())
+ {
wxLogError(_("reading zip stream (entry %s): bad length"),
m_entry.GetName().c_str());
+ }
else if (m_crcAccumulator != m_entry.GetCrc())
+ {
wxLogError(_("reading zip stream (entry %s): bad crc"),
m_entry.GetName().c_str());
+ }
else
+ {
m_lasterror = wxSTREAM_EOF;
+ }
}
}
m_comp = NULL;
m_level = level;
m_offsetAdjustment = wxInvalidOffset;
+ m_endrecWritten = false;
}
wxZipOutputStream::~wxZipOutputStream()
return false;
}
- return CopyEntry(zipEntry, wx_static_cast(wxZipInputStream&, stream));
+ return CopyEntry(zipEntry, static_cast<wxZipInputStream&>(stream));
}
bool wxZipOutputStream::CopyArchiveMetaData(wxZipInputStream& inputStream)
bool wxZipOutputStream::CopyArchiveMetaData(wxArchiveInputStream& stream)
{
- return CopyArchiveMetaData(wx_static_cast(wxZipInputStream&, stream));
+ return CopyArchiveMetaData(static_cast<wxZipInputStream&>(stream));
}
void wxZipOutputStream::SetLevel(int level)
return true;
}
-// Can be overriden to add support for additional compression methods
+// Can be overridden to add support for additional compression methods
//
wxOutputStream *wxZipOutputStream::OpenCompressor(
wxOutputStream& stream,
{
CloseEntry();
- if (m_lasterror == wxSTREAM_WRITE_ERROR || m_entries.size() == 0) {
+ if (m_lasterror == wxSTREAM_WRITE_ERROR
+ || (m_entries.size() == 0 && m_endrecWritten))
+ {
wxFilterOutputStream::Close();
return false;
}
endrec.Write(*m_parent_o_stream, GetConv());
m_lasterror = m_parent_o_stream->GetLastError();
-
+ m_endrecWritten = true;
+
if (!wxFilterOutputStream::Close() || !IsOk())
return false;
m_lasterror = wxSTREAM_EOF;