|
1 // FilterCoder.h |
|
2 |
|
3 #ifndef __FILTERCODER_H |
|
4 #define __FILTERCODER_H |
|
5 |
|
6 #include "../../Common/MyCom.h" |
|
7 #include "../ICoder.h" |
|
8 #include "../IPassword.h" |
|
9 |
|
10 #define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \ |
|
11 { if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \ |
|
12 *outObject = (void *)(i *)this; AddRef(); return S_OK; } |
|
13 |
|
14 class CFilterCoder: |
|
15 public ICompressCoder, |
|
16 // #ifdef _ST_MODE |
|
17 public ICompressSetInStream, |
|
18 public ISequentialInStream, |
|
19 public ICompressSetOutStream, |
|
20 public ISequentialOutStream, |
|
21 public IOutStreamFlush, |
|
22 // #endif |
|
23 |
|
24 #ifndef _NO_CRYPTO |
|
25 public ICryptoSetPassword, |
|
26 #endif |
|
27 #ifndef EXTRACT_ONLY |
|
28 public ICompressSetCoderProperties, |
|
29 public ICompressWriteCoderProperties, |
|
30 // public ICryptoResetSalt, |
|
31 public ICryptoResetInitVector, |
|
32 #endif |
|
33 public ICompressSetDecoderProperties2, |
|
34 public CMyUnknownImp |
|
35 { |
|
36 protected: |
|
37 Byte *_buffer; |
|
38 // #ifdef _ST_MODE |
|
39 CMyComPtr<ISequentialInStream> _inStream; |
|
40 CMyComPtr<ISequentialOutStream> _outStream; |
|
41 UInt32 _bufferPos; |
|
42 UInt32 _convertedPosBegin; |
|
43 UInt32 _convertedPosEnd; |
|
44 // #endif |
|
45 bool _outSizeIsDefined; |
|
46 UInt64 _outSize; |
|
47 UInt64 _nowPos64; |
|
48 |
|
49 HRESULT Init() |
|
50 { |
|
51 _nowPos64 = 0; |
|
52 _outSizeIsDefined = false; |
|
53 return Filter->Init(); |
|
54 } |
|
55 |
|
56 CMyComPtr<ICryptoSetPassword> _setPassword; |
|
57 #ifndef EXTRACT_ONLY |
|
58 CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties; |
|
59 CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties; |
|
60 // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt; |
|
61 CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector; |
|
62 #endif |
|
63 CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties; |
|
64 public: |
|
65 CMyComPtr<ICompressFilter> Filter; |
|
66 |
|
67 CFilterCoder(); |
|
68 ~CFilterCoder(); |
|
69 HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size); |
|
70 bool NeedMore() const |
|
71 { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); } |
|
72 |
|
73 public: |
|
74 MY_QUERYINTERFACE_BEGIN |
|
75 MY_QUERYINTERFACE_ENTRY(ICompressCoder) |
|
76 // #ifdef _ST_MODE |
|
77 MY_QUERYINTERFACE_ENTRY(ICompressSetInStream) |
|
78 MY_QUERYINTERFACE_ENTRY(ISequentialInStream) |
|
79 |
|
80 MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream) |
|
81 MY_QUERYINTERFACE_ENTRY(ISequentialOutStream) |
|
82 MY_QUERYINTERFACE_ENTRY(IOutStreamFlush) |
|
83 // #endif |
|
84 |
|
85 #ifndef _NO_CRYPTO |
|
86 MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword) |
|
87 #endif |
|
88 |
|
89 #ifndef EXTRACT_ONLY |
|
90 MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties) |
|
91 MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties) |
|
92 // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt) |
|
93 MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector) |
|
94 #endif |
|
95 |
|
96 MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties) |
|
97 MY_QUERYINTERFACE_END |
|
98 MY_ADDREF_RELEASE |
|
99 STDMETHOD(Code)(ISequentialInStream *inStream, |
|
100 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, |
|
101 ICompressProgressInfo *progress); |
|
102 // #ifdef _ST_MODE |
|
103 STDMETHOD(ReleaseInStream)(); |
|
104 STDMETHOD(SetInStream)(ISequentialInStream *inStream); |
|
105 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \ |
|
106 STDMETHOD(SetOutStream)(ISequentialOutStream *outStream); |
|
107 STDMETHOD(ReleaseOutStream)(); |
|
108 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); |
|
109 STDMETHOD(Flush)(); |
|
110 // #endif |
|
111 |
|
112 #ifndef _NO_CRYPTO |
|
113 STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); |
|
114 #endif |
|
115 #ifndef EXTRACT_ONLY |
|
116 STDMETHOD(SetCoderProperties)(const PROPID *propIDs, |
|
117 const PROPVARIANT *properties, UInt32 numProperties); |
|
118 STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); |
|
119 // STDMETHOD(ResetSalt)(); |
|
120 STDMETHOD(ResetInitVector)(); |
|
121 #endif |
|
122 STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); |
|
123 }; |
|
124 |
|
125 // #ifdef _ST_MODE |
|
126 class CInStreamReleaser |
|
127 { |
|
128 public: |
|
129 CFilterCoder *FilterCoder; |
|
130 CInStreamReleaser(): FilterCoder(0) {} |
|
131 ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); } |
|
132 }; |
|
133 |
|
134 class COutStreamReleaser |
|
135 { |
|
136 public: |
|
137 CFilterCoder *FilterCoder; |
|
138 COutStreamReleaser(): FilterCoder(0) {} |
|
139 ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); } |
|
140 }; |
|
141 // #endif |
|
142 |
|
143 #endif |