]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/zipstrm.cpp
Forgot to commit the header change too.
[wxWidgets.git] / src / common / zipstrm.cpp
index 79c1c449e4ceb9f9de5f0f883586686c724ca61a..a3af2d62468131cf2e826a52ebe2fbdb769b994e 100644 (file)
@@ -28,7 +28,7 @@
 #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"
 
@@ -140,7 +140,7 @@ static wxFileOffset QuietSeek(wxInputStream& stream, wxFileOffset pos)
 /////////////////////////////////////////////////////////////////////////////
 // Class factory
 
-wxZipClassFactory g_wxZipClassFactory;
+static wxZipClassFactory g_wxZipClassFactory;
 
 wxZipClassFactory::wxZipClassFactory()
 {
@@ -251,7 +251,7 @@ private:
     wxFileOffset m_pos;
     wxFileOffset m_len;
 
-    DECLARE_NO_COPY_CLASS(wxStoredInputStream)
+    wxDECLARE_NO_COPY_CLASS(wxStoredInputStream);
 };
 
 wxStoredInputStream::wxStoredInputStream(wxInputStream& stream)
@@ -297,7 +297,7 @@ protected:
 
 private:
     wxFileOffset m_pos;
-    DECLARE_NO_COPY_CLASS(wxStoredOutputStream)
+    wxDECLARE_NO_COPY_CLASS(wxStoredOutputStream);
 };
 
 size_t wxStoredOutputStream::OnSysWrite(const void *buffer, size_t size)
@@ -359,7 +359,7 @@ private:
     size_t m_start;
     size_t m_end;
 
-    DECLARE_NO_COPY_CLASS(wxTeeInputStream)
+    wxDECLARE_NO_COPY_CLASS(wxTeeInputStream);
 };
 
 wxTeeInputStream::wxTeeInputStream(wxInputStream& stream)
@@ -455,7 +455,7 @@ private:
     enum { BUFSIZE = 8192 };
     wxCharBuffer m_dummy;
 
-    DECLARE_NO_COPY_CLASS(wxRawInputStream)
+    wxDECLARE_NO_COPY_CLASS(wxRawInputStream);
 };
 
 wxRawInputStream::wxRawInputStream(wxInputStream& stream)
@@ -1336,7 +1336,7 @@ void wxZipInputStream::Init(const wxString& file)
     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()) {
@@ -1463,11 +1463,13 @@ bool wxZipInputStream::LoadEndRecord()
     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;
@@ -1477,8 +1479,8 @@ bool wxZipInputStream::LoadEndRecord()
     // 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;
@@ -1988,6 +1990,7 @@ void wxZipOutputStream::Init(int level)
     m_comp = NULL;
     m_level = level;
     m_offsetAdjustment = wxInvalidOffset;
+    m_endrecWritten = false;
 }
 
 wxZipOutputStream::~wxZipOutputStream()
@@ -2048,7 +2051,7 @@ bool wxZipOutputStream::CopyEntry(wxArchiveEntry *entry,
         return false;
     }
 
-    return CopyEntry(zipEntry, wx_static_cast(wxZipInputStream&, stream));
+    return CopyEntry(zipEntry, static_cast<wxZipInputStream&>(stream));
 }
 
 bool wxZipOutputStream::CopyArchiveMetaData(wxZipInputStream& inputStream)
@@ -2062,7 +2065,7 @@ 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)
@@ -2287,7 +2290,9 @@ bool wxZipOutputStream::Close()
 {
     CloseEntry();
 
-    if (m_lasterror == wxSTREAM_WRITE_ERROR) {
+    if (m_lasterror == wxSTREAM_WRITE_ERROR
+        || (m_entries.size() == 0 && m_endrecWritten))
+    {
         wxFilterOutputStream::Close();
         return false;
     }
@@ -2312,7 +2317,8 @@ bool wxZipOutputStream::Close()
     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;