X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ba9bbf13881fe4588e2a11134add81e12f1089da..02bcd285fac7124a41292d905609220005f51087:/src/common/zipstrm.cpp diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index 1c10609715..a2e12cc38b 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -7,10 +7,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "zipstrm.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -34,6 +30,7 @@ #include "wx/buffer.h" #include "wx/ptr_scpd.h" #include "wx/wfstream.h" +#include "wx/link.h" #include "zlib.h" // value for the 'version needed to extract' field (20 means 2.0) @@ -81,12 +78,7 @@ enum { IMPLEMENT_DYNAMIC_CLASS(wxZipEntry, wxArchiveEntry) IMPLEMENT_DYNAMIC_CLASS(wxZipClassFactory, wxArchiveClassFactory) -//FORCE_LINK_ME(zipstrm) -int _wx_link_dummy_func_zipstrm(); -int _wx_link_dummy_func_zipstrm() -{ - return 1; -} +wxFORCE_LINK_THIS_MODULE(zipstrm) ///////////////////////////////////////////////////////////////////////////// @@ -172,7 +164,7 @@ wxStoredInputStream::wxStoredInputStream(wxInputStream& stream) size_t wxStoredInputStream::OnSysRead(void *buffer, size_t size) { - size_t count = wxMin(size, (size_t)(m_len - m_pos)); + size_t count = wxMin(size, wx_truncate_cast(size_t, m_len - m_pos)); count = m_parent_i_stream->Read(buffer, count).LastRead(); m_pos += count; @@ -485,7 +477,7 @@ public: wxZipMemory *Unique(size_t size); private: - ~wxZipMemory() { delete m_data; } + ~wxZipMemory() { delete [] m_data; } char *m_data; size_t m_size; @@ -505,7 +497,7 @@ wxZipMemory *wxZipMemory::Unique(size_t size) } if (zm->m_capacity < size) { - delete zm->m_data; + delete [] zm->m_data; zm->m_data = new char[size]; zm->m_capacity = size; } @@ -546,7 +538,7 @@ static void Unique(wxZipMemory*& zm, size_t size) // Collection of weak references to entries WX_DECLARE_HASH_MAP(long, wxZipEntry*, wxIntegerHash, - wxIntegerEqual, _wxOffsetZipEntryMap); + wxIntegerEqual, wx__OffsetZipEntryMap); class wxZipWeakLinks { @@ -560,7 +552,7 @@ public: wxZipWeakLinks *AddEntry(wxZipEntry *entry, wxFileOffset key); void RemoveEntry(wxFileOffset key) - { m_entries.erase((_wxOffsetZipEntryMap::key_type)key); } + { m_entries.erase((wx__OffsetZipEntryMap::key_type)key); } wxZipEntry *GetEntry(wxFileOffset key) const; bool IsEmpty() const { return m_entries.empty(); } @@ -568,20 +560,20 @@ private: ~wxZipWeakLinks() { wxASSERT(IsEmpty()); } int m_ref; - _wxOffsetZipEntryMap m_entries; + wx__OffsetZipEntryMap m_entries; }; wxZipWeakLinks *wxZipWeakLinks::AddEntry(wxZipEntry *entry, wxFileOffset key) { - m_entries[(_wxOffsetZipEntryMap::key_type)key] = entry; + m_entries[(wx__OffsetZipEntryMap::key_type)key] = entry; m_ref++; return this; } wxZipEntry *wxZipWeakLinks::GetEntry(wxFileOffset key) const { - _wxOffsetZipEntryMap::const_iterator it = - m_entries.find((_wxOffsetZipEntryMap::key_type)key); + wx__OffsetZipEntryMap::const_iterator it = + m_entries.find((wx__OffsetZipEntryMap::key_type)key); return it != m_entries.end() ? it->second : NULL; } @@ -684,6 +676,7 @@ wxString wxZipEntry::GetName(wxPathFormat format /*=wxPATH_NATIVE*/) const { bool isDir = IsDir() && !m_Name.empty(); + // optimisations for common (and easy) cases switch (wxFileName::GetFormat(format)) { case wxPATH_DOS: { @@ -1171,8 +1164,9 @@ private: ///////////////////////////////////////////////////////////////////////////// // Input stream -wxDECLARE_SCOPED_PTR(wxZipEntry, _wxZipEntryPtr) -wxDEFINE_SCOPED_PTR (wxZipEntry, _wxZipEntryPtr) +// leave the default wxZipEntryPtr free for users +wxDECLARE_SCOPED_PTR(wxZipEntry, wx__ZipEntryPtr) +wxDEFINE_SCOPED_PTR (wxZipEntry, wx__ZipEntryPtr) // constructor // @@ -1180,20 +1174,22 @@ wxZipInputStream::wxZipInputStream(wxInputStream& stream, wxMBConv& conv /*=wxConvLocal*/) : wxArchiveInputStream(stream, conv) { - m_ffile = NULL; Init(); } -// Compatibility constructor +#if 1 //WXWIN_COMPATIBILITY_2_6 + +// Part of the compatibility constructor, which has been made inline to +// avoid a problem with it not being exported by mingw 3.2.3 // -wxZipInputStream::wxZipInputStream(const wxString& archive, - const wxString& file) - : wxArchiveInputStream(OpenFile(archive), wxConvLocal) +void wxZipInputStream::Init(const wxString& file) { // no error messages wxLogNull nolog; Init(); - _wxZipEntryPtr entry; + m_allowSeeking = true; + m_ffile = wx_static_cast(wxFFileInputStream*, m_parent_i_stream); + wx__ZipEntryPtr entry; if (m_ffile->Ok()) { do { @@ -1209,10 +1205,11 @@ wxZipInputStream::wxZipInputStream(const wxString& archive, wxInputStream& wxZipInputStream::OpenFile(const wxString& archive) { wxLogNull nolog; - m_ffile = new wxFFileInputStream(archive); - return *m_ffile; + return *new wxFFileInputStream(archive); } +#endif // WXWIN_COMPATIBILITY_2_6 + void wxZipInputStream::Init() { m_store = new wxStoredInputStream(*m_parent_i_stream); @@ -1229,6 +1226,10 @@ void wxZipInputStream::Init() m_signature = 0; m_TotalEntries = 0; m_lasterror = m_parent_i_stream->GetLastError(); + m_ffile = NULL; +#if 1 //WXWIN_COMPATIBILITY_2_6 + m_allowSeeking = false; +#endif } wxZipInputStream::~wxZipInputStream() @@ -1416,7 +1417,7 @@ wxZipEntry *wxZipInputStream::GetNextEntry() if (!IsOk()) return NULL; - _wxZipEntryPtr entry(new wxZipEntry(m_entry)); + wx__ZipEntryPtr entry(new wxZipEntry(m_entry)); entry->m_backlink = m_weaklinks->AddEntry(entry.get(), entry->GetKey()); return entry.release(); } @@ -1742,11 +1743,20 @@ size_t wxZipInputStream::OnSysRead(void *buffer, size_t size) return count; } +#if 1 //WXWIN_COMPATIBILITY_2_6 + // Borrowed from VS's zip stream (c) 1999 Vaclav Slavik // wxFileOffset wxZipInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode) { - if (!m_ffile || AtHeader()) + // seeking works when the stream is created with the compatibility + // constructor + if (!m_allowSeeking) + return wxInvalidOffset; + if (!IsOpened()) + if ((AtHeader() && !DoOpen()) || !OpenDecompressor()) + m_lasterror = wxSTREAM_READ_ERROR; + if (!IsOk()) return wxInvalidOffset; // NB: since ZIP files don't natively support seeking, we have to @@ -1761,7 +1771,7 @@ wxFileOffset wxZipInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode) { case wxFromCurrent : nextpos = seek + pos; break; case wxFromStart : nextpos = seek; break; - case wxFromEnd : nextpos = GetLength() - 1 + seek; break; + case wxFromEnd : nextpos = GetLength() + seek; break; default : nextpos = pos; break; /* just to fool compiler, never happens */ } @@ -1799,12 +1809,14 @@ wxFileOffset wxZipInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode) return pos; } +#endif // WXWIN_COMPATIBILITY_2_6 + ///////////////////////////////////////////////////////////////////////////// // Output stream #include "wx/listimpl.cpp" -WX_DEFINE_LIST(_wxZipEntryList); +WX_DEFINE_LIST(wx__ZipEntryList) wxZipOutputStream::wxZipOutputStream(wxOutputStream& stream, int level /*=-1*/, @@ -1829,7 +1841,7 @@ wxZipOutputStream::wxZipOutputStream(wxOutputStream& stream, wxZipOutputStream::~wxZipOutputStream() { Close(); - WX_CLEAR_LIST(_wxZipEntryList, m_entries); + WX_CLEAR_LIST(wx__ZipEntryList, m_entries); delete m_store; delete m_deflate; delete m_pending; @@ -1858,7 +1870,7 @@ bool wxZipOutputStream::PutNextDirEntry( bool wxZipOutputStream::CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream) { - _wxZipEntryPtr e(entry); + wx__ZipEntryPtr e(entry); return inputStream.DoOpen(e.get(), true) && @@ -1925,14 +1937,18 @@ bool wxZipOutputStream::DoCreate(wxZipEntry *entry, bool raw /*=false*/) // and if this is the first entry test for seekability if (m_headerOffset == 0 && m_parent_o_stream->IsSeekable()) { +#if wxUSE_LOG bool logging = wxLog::IsEnabled(); wxLogNull nolog; +#endif // wxUSE_LOG wxFileOffset here = m_parent_o_stream->TellO(); if (here != wxInvalidOffset && here >= 4) { if (m_parent_o_stream->SeekO(here - 4) == here - 4) { m_offsetAdjustment = here - 4; +#if wxUSE_LOG wxLog::EnableLogging(logging); +#endif // wxUSE_LOG m_parent_o_stream->SeekO(here); } } @@ -2024,7 +2040,7 @@ bool wxZipOutputStream::CloseCompressor(wxOutputStream *comp) void wxZipOutputStream::CreatePendingEntry(const void *buffer, size_t size) { wxASSERT(IsOk() && m_pending && !m_comp); - _wxZipEntryPtr spPending(m_pending); + wx__ZipEntryPtr spPending(m_pending); m_pending = NULL; Buffer bufs[] = { @@ -2065,7 +2081,7 @@ void wxZipOutputStream::CreatePendingEntry(const void *buffer, size_t size) void wxZipOutputStream::CreatePendingEntry() { wxASSERT(IsOk() && m_pending && !m_comp); - _wxZipEntryPtr spPending(m_pending); + wx__ZipEntryPtr spPending(m_pending); m_pending = NULL; m_lasterror = wxSTREAM_WRITE_ERROR; @@ -2129,7 +2145,7 @@ bool wxZipOutputStream::Close() endrec.SetOffset(m_headerOffset); endrec.SetComment(m_Comment); - _wxZipEntryList::iterator it; + wx__ZipEntryList::iterator it; wxFileOffset size = 0; for (it = m_entries.begin(); it != m_entries.end(); ++it) {