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()) {
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;
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)
{
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;