X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8aa3cd14b57820dc30ed2034e35e39623ac45c95..eea4d01c65f9b29baa1193db762b4c6b8144af24:/src/common/fileback.cpp?ds=sidebyside diff --git a/src/common/fileback.cpp b/src/common/fileback.cpp index 06d32ae99e..704b54e165 100644 --- a/src/common/fileback.cpp +++ b/src/common/fileback.cpp @@ -14,9 +14,9 @@ #pragma hdrstop #endif -#if wxUSE_BACKINGFILE +#if wxUSE_FILESYSTEM -#include "wx/fileback.h" +#include "wx/private/fileback.h" #ifndef WX_PRECOMP #include "wx/utils.h" @@ -168,11 +168,9 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, m_filelen += count; if (count < m_buflen) { - delete m_stream; - m_stream = NULL; + wxDELETE(m_stream); if (count > 0) { - delete[] m_buf; - m_buf = NULL; + wxDELETEA(m_buf); m_buflen = 0; } m_parenterror = wxSTREAM_READ_ERROR; @@ -182,8 +180,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, m_buflen = 0; if (!m_stream) { - delete[] m_buf; - m_buf = NULL; + wxDELETEA(m_buf); } } @@ -197,8 +194,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, m_parenterror = m_stream->GetLastError(); if (m_parenterror == wxSTREAM_NO_ERROR) m_parenterror = wxSTREAM_EOF; - delete m_stream; - m_stream = NULL; + wxDELETE(m_stream); } } @@ -271,6 +267,29 @@ wxBackedInputStream::wxBackedInputStream(const wxBackingFile& backer) { } +wxFileOffset wxBackedInputStream::GetLength() const +{ + return m_backer.m_impl->GetLength(); +} + +wxFileOffset wxBackedInputStream::FindLength() const +{ + wxFileOffset len = GetLength(); + + if (len == wxInvalidOffset && IsOk()) { + // read a byte at 7ff...ffe + wxFileOffset pos = 1; + pos <<= sizeof(pos) * 8 - 1; + pos = ~pos - 1; + char ch; + size_t size = 1; + m_backer.m_impl->ReadAt(pos, &ch, &size); + len = GetLength(); + } + + return len; +} + size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size) { if (!IsOk()) @@ -281,11 +300,6 @@ size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size) return size; } -wxFileOffset wxBackedInputStream::GetLength() const -{ - return m_backer.m_impl->GetLength(); -} - wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) { switch (mode) { @@ -317,4 +331,4 @@ wxFileOffset wxBackedInputStream::OnSysTell() const return m_pos; } -#endif // wxUSE_BACKINGFILE +#endif // wxUSE_FILESYSTEM