X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/02761f6cd478e3c2c97cf6f93442747f7b029833..8a16d7370e3cdc7d583a6f14ab11b3a1d27b73df:/src/common/filesys.cpp diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp index 425be7057c..2d44cf8c5f 100644 --- a/src/common/filesys.cpp +++ b/src/common/filesys.cpp @@ -487,6 +487,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 +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)