]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filesys.cpp
Add wxUSE_TARSTREAM and wxUSE_FS_ARCHIVE.
[wxWidgets.git] / src / common / filesys.cpp
index 425be7057ce7a6ea5a726925442f2c4ba105d649..d63b432e72e736cfe073016f9a65bbb6a8cb9526 100644 (file)
@@ -27,6 +27,7 @@
 #include "wx/mimetype.h"
 #include "wx/filename.h"
 #include "wx/tokenzr.h"
+#include "wx/fileback.h"
 
 
 //--------------------------------------------------------------------------------
@@ -214,7 +215,13 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
 
     // we need to check whether we can really read from this file, otherwise
     // wxFSFile is not going to work
+#if wxUSE_FILE
+    wxFileInputStream *is = new wxFileInputStream(fullpath);
+#elif wxUSE_FFILE
     wxFFileInputStream *is = new wxFFileInputStream(fullpath);
+#else
+#error One of wxUSE_FILE or wxUSE_FFILE must be set to 1 for wxFSHandler to work
+#endif
     if ( !is->Ok() )
     {
         delete is;
@@ -351,7 +358,7 @@ void wxFileSystem::ChangePathTo(const wxString& location, bool is_dir)
 
 
 
-wxFSFile* wxFileSystem::OpenFile(const wxString& location)
+wxFSFile* wxFileSystem::OpenFile(const wxString& location, int flags)
 {
     wxString loc = MakeCorrectPath(location);
     unsigned i, ln;
@@ -404,6 +411,15 @@ wxFSFile* wxFileSystem::OpenFile(const wxString& location)
             node = node->GetNext();
         }
     }
+
+    if (s && (flags & wxFS_SEEKABLE) != 0 && !s->GetStream()->IsSeekable())
+    {
+        wxBackedInputStream *stream;
+        stream = new wxBackedInputStream(s->DetachStream());
+        stream->FindLength();
+        s->SetStream(stream);
+    }
+
     return (s);
 }
 
@@ -487,6 +503,20 @@ void wxFileSystem::AddHandler(wxFileSystemHandler *handler)
     m_Handlers.Insert((size_t)0, handler);
 }
 
+wxFileSystemHandler* wxFileSystem::RemoveHandler(wxFileSystemHandler *handler)
+{
+    // if handler has already been removed (or deleted)
+    // we return NULL. This is by design in case
+    // CleanUpHandlers() is called before RemoveHandler
+    // is called, as we cannot control the order
+    // which modules are unloaded
+    if (!m_Handlers.DeleteObject(handler))
+        return NULL;
+
+    return handler;
+}
+
+
 bool wxFileSystem::HasHandlerForPath(const wxString &location)
 {
     for ( wxList::compatibility_iterator node = m_Handlers.GetFirst();
@@ -589,15 +619,28 @@ class wxFileSystemModule : public wxModule
     DECLARE_DYNAMIC_CLASS(wxFileSystemModule)
 
     public:
+        wxFileSystemModule() :
+            wxModule(),
+            m_handler(NULL)
+        {
+        }
+
         virtual bool OnInit()
         {
-            wxFileSystem::AddHandler(new wxLocalFSHandler);
+            m_handler = new wxLocalFSHandler;
+            wxFileSystem::AddHandler(m_handler);
             return true;
         }
         virtual void OnExit()
         {
+            delete wxFileSystem::RemoveHandler(m_handler);
+
             wxFileSystem::CleanUpHandlers();
         }
+
+    private:
+        wxFileSystemHandler* m_handler;
+
 };
 
 IMPLEMENT_DYNAMIC_CLASS(wxFileSystemModule, wxModule)