X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/374b4f1c0b24ffb096e33a8c9f63031247a2efe0..97c7099a70fd3af6ac7bef7f420581c8801ba22d:/src/common/filesys.cpp?ds=sidebyside diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp index 405598e9c2..57fc6e3712 100644 --- a/src/common/filesys.cpp +++ b/src/common/filesys.cpp @@ -20,10 +20,10 @@ #ifndef WX_PRECOMP #include "wx/log.h" + #include "wx/module.h" #endif #include "wx/wfstream.h" -#include "wx/module.h" #include "wx/mimetype.h" #include "wx/filename.h" #include "wx/tokenzr.h" @@ -214,7 +214,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; @@ -487,6 +493,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 +609,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)