|
1 // MethodProps.cpp |
|
2 |
|
3 #include "StdAfx.h" |
|
4 |
|
5 #include "MethodProps.h" |
|
6 #include "../../Common/MyCom.h" |
|
7 |
|
8 static UInt64 k_LZMA = 0x030101; |
|
9 // static UInt64 k_LZMA2 = 0x030102; |
|
10 |
|
11 HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder) |
|
12 { |
|
13 bool tryReduce = false; |
|
14 UInt32 reducedDictionarySize = 1 << 10; |
|
15 if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */)) |
|
16 { |
|
17 for (;;) |
|
18 { |
|
19 const UInt32 step = (reducedDictionarySize >> 1); |
|
20 if (reducedDictionarySize >= *inSizeForReduce) |
|
21 { |
|
22 tryReduce = true; |
|
23 break; |
|
24 } |
|
25 reducedDictionarySize += step; |
|
26 if (reducedDictionarySize >= *inSizeForReduce) |
|
27 { |
|
28 tryReduce = true; |
|
29 break; |
|
30 } |
|
31 if (reducedDictionarySize >= ((UInt32)3 << 30)) |
|
32 break; |
|
33 reducedDictionarySize += step; |
|
34 } |
|
35 } |
|
36 |
|
37 { |
|
38 int numProperties = method.Properties.Size(); |
|
39 CMyComPtr<ICompressSetCoderProperties> setCoderProperties; |
|
40 coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); |
|
41 if (setCoderProperties == NULL) |
|
42 { |
|
43 if (numProperties != 0) |
|
44 return E_INVALIDARG; |
|
45 } |
|
46 else |
|
47 { |
|
48 CRecordVector<PROPID> propIDs; |
|
49 NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties]; |
|
50 HRESULT res = S_OK; |
|
51 try |
|
52 { |
|
53 for (int i = 0; i < numProperties; i++) |
|
54 { |
|
55 const CProp &prop = method.Properties[i]; |
|
56 propIDs.Add(prop.Id); |
|
57 NWindows::NCOM::CPropVariant &value = values[i]; |
|
58 value = prop.Value; |
|
59 // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal) |
|
60 if (tryReduce) |
|
61 if (prop.Id == NCoderPropID::kDictionarySize) |
|
62 if (value.vt == VT_UI4) |
|
63 if (reducedDictionarySize < value.ulVal) |
|
64 value.ulVal = reducedDictionarySize; |
|
65 } |
|
66 CMyComPtr<ICompressSetCoderProperties> setCoderProperties; |
|
67 coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); |
|
68 res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties); |
|
69 } |
|
70 catch(...) |
|
71 { |
|
72 delete []values; |
|
73 throw; |
|
74 } |
|
75 delete []values; |
|
76 RINOK(res); |
|
77 } |
|
78 } |
|
79 |
|
80 /* |
|
81 CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties; |
|
82 coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties); |
|
83 if (writeCoderProperties != NULL) |
|
84 { |
|
85 CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp; |
|
86 CMyComPtr<ISequentialOutStream> outStream(outStreamSpec); |
|
87 outStreamSpec->Init(); |
|
88 RINOK(writeCoderProperties->WriteCoderProperties(outStream)); |
|
89 size_t size = outStreamSpec->GetSize(); |
|
90 filterProps.SetCapacity(size); |
|
91 memmove(filterProps, outStreamSpec->GetBuffer(), size); |
|
92 } |
|
93 */ |
|
94 return S_OK; |
|
95 } |
|
96 |