Add wxLZMAClassFactory for run-time LZMA stream creation
This should allow handling .xz files in wxFileSystem, for example.
This commit is contained in:
@@ -117,6 +117,31 @@ private:
|
|||||||
bool DoFlush(bool finish);
|
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();
|
WXDLLIMPEXP_BASE wxVersionInfo wxGetLibLZMAVersionInfo();
|
||||||
|
|
||||||
#endif // wxUSE_LIBLZMA && wxUSE_STREAMS
|
#endif // wxUSE_LIBLZMA && wxUSE_STREAMS
|
||||||
|
@@ -369,4 +369,37 @@ bool wxLZMAOutputStream::Close()
|
|||||||
return wxFilterOutputStream::Close() && IsOk();
|
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
|
#endif // wxUSE_LIBLZMA && wxUSE_STREAMS
|
||||||
|
Reference in New Issue
Block a user