diff --git a/include/wx/lzmastream.h b/include/wx/lzmastream.h index 5164d67f86..9bd2ab1bab 100644 --- a/include/wx/lzmastream.h +++ b/include/wx/lzmastream.h @@ -117,6 +117,31 @@ private: bool DoFlush(bool finish); }; +// ---------------------------------------------------------------------------- +// Support for creating LZMA streams from extension/MIME type +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_BASE wxLZMAClassFactory: public wxFilterClassFactory +{ +public: + wxLZMAClassFactory(); + + wxFilterInputStream *NewStream(wxInputStream& stream) const wxOVERRIDE + { return new wxLZMAInputStream(stream); } + wxFilterOutputStream *NewStream(wxOutputStream& stream) const wxOVERRIDE + { return new wxLZMAOutputStream(stream, -1); } + wxFilterInputStream *NewStream(wxInputStream *stream) const wxOVERRIDE + { return new wxLZMAInputStream(stream); } + wxFilterOutputStream *NewStream(wxOutputStream *stream) const wxOVERRIDE + { return new wxLZMAOutputStream(stream, -1); } + + const wxChar * const *GetProtocols(wxStreamProtocolType type + = wxSTREAM_PROTOCOL) const wxOVERRIDE; + +private: + wxDECLARE_DYNAMIC_CLASS(wxLZMAClassFactory); +}; + WXDLLIMPEXP_BASE wxVersionInfo wxGetLibLZMAVersionInfo(); #endif // wxUSE_LIBLZMA && wxUSE_STREAMS diff --git a/src/common/lzmastream.cpp b/src/common/lzmastream.cpp index f931c83f6e..7c4c62a335 100644 --- a/src/common/lzmastream.cpp +++ b/src/common/lzmastream.cpp @@ -369,4 +369,37 @@ bool wxLZMAOutputStream::Close() return wxFilterOutputStream::Close() && IsOk(); } +// ---------------------------------------------------------------------------- +// wxLZMAClassFactory: allow creating streams from extension/MIME type +// ---------------------------------------------------------------------------- + +wxIMPLEMENT_DYNAMIC_CLASS(wxLZMAClassFactory, wxFilterClassFactory); + +static wxLZMAClassFactory g_wxLZMAClassFactory; + +wxLZMAClassFactory::wxLZMAClassFactory() +{ + if ( this == &g_wxLZMAClassFactory ) + PushFront(); +} + +const wxChar * const * +wxLZMAClassFactory::GetProtocols(wxStreamProtocolType type) const +{ + static const wxChar *mime[] = { wxT("application/xz"), NULL }; + static const wxChar *encs[] = { wxT("xz"), NULL }; + static const wxChar *exts[] = { wxT(".xz"), NULL }; + + const wxChar* const* ret = NULL; + switch ( type ) + { + case wxSTREAM_PROTOCOL: ret = encs; break; + case wxSTREAM_MIMETYPE: ret = mime; break; + case wxSTREAM_ENCODING: ret = encs; break; + case wxSTREAM_FILEEXT: ret = exts; break; + } + + return ret; +} + #endif // wxUSE_LIBLZMA && wxUSE_STREAMS