]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fileback.cpp
Ensure that component levels map is initialized before it's used (closes #10990).
[wxWidgets.git] / src / common / fileback.cpp
index 3e3531598404505000d8c03239b44eab69c16e8d..6e4253c0f76896fa8684a6ecee8724c5a603e4a4 100644 (file)
@@ -14,9 +14,9 @@
     #pragma hdrstop
 #endif
 
     #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"
 
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
@@ -82,8 +82,8 @@ wxBackingFileImpl::wxBackingFileImpl(wxInputStream *stream,
 {
     wxFileOffset len = m_stream->GetLength();
 
 {
     wxFileOffset len = m_stream->GetLength();
 
-    if (len >= 0 && len + size_t(0) < m_bufsize)
-        m_bufsize = size_t(len);
+    if (len >= 0 && len + size_t(1) < m_bufsize)
+        m_bufsize = size_t(len + 1);
 
     if (m_bufsize)
         m_buf = new char[m_bufsize];
 
     if (m_bufsize)
         m_buf = new char[m_bufsize];
@@ -171,7 +171,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
                         delete m_stream;
                         m_stream = NULL;
                         if (count > 0) {
                         delete m_stream;
                         m_stream = NULL;
                         if (count > 0) {
-                            delete m_buf;
+                            delete[] m_buf;
                             m_buf = NULL;
                             m_buflen = 0;
                         }
                             m_buf = NULL;
                             m_buflen = 0;
                         }
@@ -182,7 +182,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
                     m_buflen = 0;
 
                     if (!m_stream) {
                     m_buflen = 0;
 
                     if (!m_stream) {
-                        delete m_buf;
+                        delete[] m_buf;
                         m_buf = NULL;
                     }
                 }
                         m_buf = NULL;
                     }
                 }
@@ -271,6 +271,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())
 size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
 {
     if (!IsOk())
@@ -281,11 +304,6 @@ size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
     return size;
 }
 
     return size;
 }
 
-wxFileOffset wxBackedInputStream::GetLength() const
-{
-    return m_backer.m_impl->GetLength();
-}
-
 wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
 {
     switch (mode) {
 wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
 {
     switch (mode) {
@@ -317,4 +335,4 @@ wxFileOffset wxBackedInputStream::OnSysTell() const
     return m_pos;
 }
 
     return m_pos;
 }
 
-#endif // wxUSE_BACKINGFILE
+#endif // wxUSE_FILESYSTEM