X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4948ebf3ffe886443ec61bbecd1d0d3b794dfee2..60acae80d0d23ee153ef92132e66d9009d5cf978:/src/common/filesys.cpp diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp index 44e265776b..2d44cf8c5f 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" @@ -484,9 +484,23 @@ void wxFileSystem::AddHandler(wxFileSystemHandler *handler) { // prepend the handler to the beginning of the list because handlers added // last should have the highest priority to allow overriding them - m_Handlers.Insert(0u, 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 +603,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)