X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/28997d375d3948d92f0846d1de3bf82df7ce59ae..dbbd41ae33856d6c9dfe6c2bf19151b1ac0a18eb:/src/common/zipstrm.cpp diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index c73a2aebd2..f9f9826428 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -34,7 +34,6 @@ #include "wx/buffer.h" #include "wx/ptr_scpd.h" #include "wx/wfstream.h" -#include "wx/html/forcelnk.h" #include "zlib.h" // value for the 'version needed to extract' field (20 means 2.0) @@ -82,7 +81,12 @@ enum { IMPLEMENT_DYNAMIC_CLASS(wxZipEntry, wxArchiveEntry) IMPLEMENT_DYNAMIC_CLASS(wxZipClassFactory, wxArchiveClassFactory) -FORCE_LINK_ME(zipstrm) +//FORCE_LINK_ME(zipstrm) +int _wx_link_dummy_func_zipstrm(); +int _wx_link_dummy_func_zipstrm() +{ + return 1; +} ///////////////////////////////////////////////////////////////////////////// @@ -168,7 +172,7 @@ wxStoredInputStream::wxStoredInputStream(wxInputStream& stream) size_t wxStoredInputStream::OnSysRead(void *buffer, size_t size) { - size_t count = wxMin(size, m_len - m_pos + (size_t)0); + size_t count = wxMin(size, (size_t)(m_len - m_pos)); count = m_parent_i_stream->Read(buffer, count).LastRead(); m_pos += count; @@ -470,7 +474,6 @@ class wxZipMemory { public: wxZipMemory() : m_data(NULL), m_size(0), m_capacity(0), m_ref(1) { } - ~wxZipMemory() { delete m_data; } wxZipMemory *AddRef() { m_ref++; return this; } void Release() { if (--m_ref == 0) delete this; } @@ -482,6 +485,7 @@ public: wxZipMemory *Unique(size_t size); private: + ~wxZipMemory() { delete m_data; } char *m_data; size_t m_size; @@ -548,7 +552,6 @@ class wxZipWeakLinks { public: wxZipWeakLinks() : m_ref(1) { } - ~wxZipWeakLinks() { wxASSERT(IsEmpty()); } void Release(const wxZipInputStream* WXUNUSED(x)) { if (--m_ref == 0) delete this; } @@ -556,11 +559,13 @@ public: { RemoveEntry(key); if (--m_ref == 0) delete this; } wxZipWeakLinks *AddEntry(wxZipEntry *entry, wxFileOffset key); - void RemoveEntry(wxFileOffset key) { m_entries.erase(key); } + void RemoveEntry(wxFileOffset key) + { m_entries.erase((_wxOffsetZipEntryMap::key_type)key); } wxZipEntry *GetEntry(wxFileOffset key) const; bool IsEmpty() const { return m_entries.empty(); } private: + ~wxZipWeakLinks() { wxASSERT(IsEmpty()); } int m_ref; _wxOffsetZipEntryMap m_entries; @@ -568,14 +573,15 @@ private: wxZipWeakLinks *wxZipWeakLinks::AddEntry(wxZipEntry *entry, wxFileOffset key) { - m_entries[key] = entry; + m_entries[(_wxOffsetZipEntryMap::key_type)key] = entry; m_ref++; return this; } wxZipEntry *wxZipWeakLinks::GetEntry(wxFileOffset key) const { - _wxOffsetZipEntryMap::const_iterator it = m_entries.find(key); + _wxOffsetZipEntryMap::const_iterator it = + m_entries.find((_wxOffsetZipEntryMap::key_type)key); return it != m_entries.end() ? it->second : NULL; } @@ -620,7 +626,8 @@ wxZipEntry::~wxZipEntry() } wxZipEntry::wxZipEntry(const wxZipEntry& e) - : m_SystemMadeBy(e.m_SystemMadeBy), + : wxArchiveEntry(e), + m_SystemMadeBy(e.m_SystemMadeBy), m_VersionMadeBy(e.m_VersionMadeBy), m_VersionNeeded(e.m_VersionNeeded), m_Flags(e.m_Flags), @@ -638,7 +645,7 @@ wxZipEntry::wxZipEntry(const wxZipEntry& e) m_ExternalAttributes(e.m_ExternalAttributes), m_Extra(AddRef(e.m_Extra)), m_LocalExtra(AddRef(e.m_LocalExtra)), - m_zipnotifier(e.m_zipnotifier), + m_zipnotifier(NULL), m_backlink(NULL) { } @@ -664,7 +671,7 @@ wxZipEntry& wxZipEntry::operator=(const wxZipEntry& e) m_ExternalAttributes = e.m_ExternalAttributes; Copy(m_Extra, e.m_Extra); Copy(m_LocalExtra, e.m_LocalExtra); - m_zipnotifier = e.m_zipnotifier; + m_zipnotifier = NULL; if (m_backlink) { m_backlink->Release(m_Key); m_backlink = NULL; @@ -741,7 +748,7 @@ void wxZipEntry::SetSystemMadeBy(int system) int mode = GetMode(); bool wasUnix = IsMadeByUnix(); - m_SystemMadeBy = system; + m_SystemMadeBy = (wxUint8)system; if (!wasUnix && IsMadeByUnix()) { SetIsDir(IsDir()); @@ -894,7 +901,7 @@ size_t wxZipEntry::WriteLocal(wxOutputStream& stream, wxMBConv& conv) const const wxWX2MBbuf name_buf = conv.cWX2MB(unixName); const char *name = name_buf; if (!name) name = ""; - wxUint16 nameLen = strlen(name); + wxUint16 nameLen = (wxUint16)strlen(name); wxDataOutputStream ds(stream); @@ -902,11 +909,11 @@ size_t wxZipEntry::WriteLocal(wxOutputStream& stream, wxMBConv& conv) const ds.Write32(GetDateTime().GetAsDOS()); ds.Write32(m_Crc); - ds.Write32(m_CompressedSize != wxInvalidOffset ? m_CompressedSize : 0); - ds.Write32(m_Size != wxInvalidOffset ? m_Size : 0); + ds.Write32(m_CompressedSize != wxInvalidOffset ? (wxUint32)m_CompressedSize : 0); + ds.Write32(m_Size != wxInvalidOffset ? (wxUint32)m_Size : 0); ds << nameLen; - wxUint16 extraLen = GetLocalExtraLen(); + wxUint16 extraLen = (wxUint16)GetLocalExtraLen(); ds.Write16(extraLen); stream.Write(name, nameLen); @@ -958,26 +965,26 @@ size_t wxZipEntry::WriteCentral(wxOutputStream& stream, wxMBConv& conv) const const wxWX2MBbuf name_buf = conv.cWX2MB(unixName); const char *name = name_buf; if (!name) name = ""; - wxUint16 nameLen = strlen(name); + wxUint16 nameLen = (wxUint16)strlen(name); const wxWX2MBbuf comment_buf = conv.cWX2MB(m_Comment); const char *comment = comment_buf; if (!comment) comment = ""; - wxUint16 commentLen = strlen(comment); + wxUint16 commentLen = (wxUint16)strlen(comment); - wxUint16 extraLen = GetExtraLen(); + wxUint16 extraLen = (wxUint16)GetExtraLen(); wxDataOutputStream ds(stream); ds << CENTRAL_MAGIC << m_VersionMadeBy << m_SystemMadeBy; - ds.Write16(GetVersionNeeded()); - ds.Write16(GetFlags()); - ds.Write16(GetMethod()); + ds.Write16((wxUint16)GetVersionNeeded()); + ds.Write16((wxUint16)GetFlags()); + ds.Write16((wxUint16)GetMethod()); ds.Write32(GetDateTime().GetAsDOS()); ds.Write32(GetCrc()); - ds.Write32(GetCompressedSize()); - ds.Write32(GetSize()); + ds.Write32((wxUint32)GetCompressedSize()); + ds.Write32((wxUint32)GetSize()); ds.Write16(nameLen); ds.Write16(extraLen); @@ -1024,7 +1031,7 @@ size_t wxZipEntry::ReadDescriptor(wxInputStream& stream) { // it's an info-zip record as expected stream.Ungetch(buf + 4, sizeof(buf) - 4); - m_Crc = m_CompressedSize; + m_Crc = (wxUint32)m_CompressedSize; m_CompressedSize = m_Size; m_Size = u1; return SUMS_SIZE + 4; @@ -1044,8 +1051,8 @@ size_t wxZipEntry::WriteDescriptor(wxOutputStream& stream, wxUint32 crc, wxDataOutputStream ds(stream); ds.Write32(crc); - ds.Write32(compressedSize); - ds.Write32(size); + ds.Write32((wxUint32)compressedSize); + ds.Write32((wxUint32)size); return SUMS_SIZE; } @@ -1067,10 +1074,10 @@ public: wxFileOffset GetOffset() const { return m_Offset; } wxString GetComment() const { return m_Comment; } - void SetDiskNumber(int num) { m_DiskNumber = num; } - void SetStartDisk(int num) { m_StartDisk = num; } - void SetEntriesHere(int num) { m_EntriesHere = num; } - void SetTotalEntries(int num) { m_TotalEntries = num; } + void SetDiskNumber(int num) { m_DiskNumber = (wxUint16)num; } + void SetStartDisk(int num) { m_StartDisk = (wxUint16)num; } + void SetEntriesHere(int num) { m_EntriesHere = (wxUint16)num; } + void SetTotalEntries(int num) { m_TotalEntries = (wxUint16)num; } void SetSize(wxFileOffset size) { m_Size = (wxUint32)size; } void SetOffset(wxFileOffset offset) { m_Offset = (wxUint32)offset; } void SetComment(const wxString& comment) { m_Comment = comment; } @@ -1103,7 +1110,7 @@ bool wxZipEndRec::Write(wxOutputStream& stream, wxMBConv& conv) const const wxWX2MBbuf comment_buf = conv.cWX2MB(m_Comment); const char *comment = comment_buf; if (!comment) comment = ""; - wxUint16 commentLen = strlen(comment); + wxUint16 commentLen = (wxUint16)strlen(comment); wxDataOutputStream ds(stream); @@ -1144,7 +1151,6 @@ class wxZipStreamLink { public: wxZipStreamLink(wxZipOutputStream *stream) : m_ref(1), m_stream(stream) { } - ~wxZipStreamLink() { } wxZipStreamLink *AddRef() { m_ref++; return this; } wxZipOutputStream *GetOutputStream() const { return m_stream; } @@ -1155,6 +1161,7 @@ public: { m_stream = NULL; if (--m_ref == 0) delete this; } private: + ~wxZipStreamLink() { } int m_ref; wxZipOutputStream *m_stream; @@ -1348,6 +1355,9 @@ bool wxZipInputStream::LoadEndRecord() // bool wxZipInputStream::FindEndRecord() { + if (!m_parent_i_stream->IsSeekable()) + return false; + // usually it's 22 bytes in size and the last thing in the file { wxLogNull nolog; @@ -1373,7 +1383,7 @@ bool wxZipInputStream::FindEndRecord() wxFileOffset minpos = wxMax(pos - 65535L, 0); while (pos > minpos) { - size_t len = pos - wxMax(pos - (BUFSIZE - 3), minpos); + size_t len = (size_t)(pos - wxMax(pos - (BUFSIZE - 3), minpos)); memcpy(buf.data() + len, buf, 3); pos -= len; @@ -1758,7 +1768,7 @@ wxFileOffset wxZipInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode) size_t toskip; if ( nextpos >= pos ) { - toskip = nextpos - pos; + toskip = (size_t)(nextpos - pos); } else { @@ -1769,7 +1779,7 @@ wxFileOffset wxZipInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode) m_lasterror = wxSTREAM_READ_ERROR; return pos; } - toskip = nextpos; + toskip = (size_t)nextpos; } if ( toskip > 0 ) @@ -1914,7 +1924,7 @@ bool wxZipOutputStream::DoCreate(wxZipEntry *entry, bool raw /*=false*/) ds << LOCAL_MAGIC; // and if this is the first entry test for seekability - if (m_headerOffset == 0) { + if (m_headerOffset == 0 && m_parent_o_stream->IsSeekable()) { bool logging = wxLog::IsEnabled(); wxLogNull nolog; wxFileOffset here = m_parent_o_stream->TellO(); @@ -2191,7 +2201,8 @@ bool wxZipOutputStream::CloseEntry() } m_headerOffset += m_headerSize + compressedSize; - m_headerSize = m_entrySize = 0; + m_headerSize = 0; + m_entrySize = 0; m_store->Close(); m_raw = false;