Mercurial > vba-linux
diff src/win32/7zip/7z/CPP/7zip/Common/MethodProps.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MethodProps.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,99 @@ 1.4 +// MethodProps.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "../../Common/MyCom.h" 1.9 + 1.10 +#include "../ICoder.h" 1.11 + 1.12 +#include "MethodProps.h" 1.13 + 1.14 +static UInt64 k_LZMA = 0x030101; 1.15 +// static UInt64 k_LZMA2 = 0x030102; 1.16 + 1.17 +HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder) 1.18 +{ 1.19 + bool tryReduce = false; 1.20 + UInt32 reducedDictionarySize = 1 << 10; 1.21 + if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */)) 1.22 + { 1.23 + for (;;) 1.24 + { 1.25 + const UInt32 step = (reducedDictionarySize >> 1); 1.26 + if (reducedDictionarySize >= *inSizeForReduce) 1.27 + { 1.28 + tryReduce = true; 1.29 + break; 1.30 + } 1.31 + reducedDictionarySize += step; 1.32 + if (reducedDictionarySize >= *inSizeForReduce) 1.33 + { 1.34 + tryReduce = true; 1.35 + break; 1.36 + } 1.37 + if (reducedDictionarySize >= ((UInt32)3 << 30)) 1.38 + break; 1.39 + reducedDictionarySize += step; 1.40 + } 1.41 + } 1.42 + 1.43 + { 1.44 + int numProps = method.Props.Size(); 1.45 + CMyComPtr<ICompressSetCoderProperties> setCoderProperties; 1.46 + coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); 1.47 + if (setCoderProperties == NULL) 1.48 + { 1.49 + if (numProps != 0) 1.50 + return E_INVALIDARG; 1.51 + } 1.52 + else 1.53 + { 1.54 + CRecordVector<PROPID> propIDs; 1.55 + NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps]; 1.56 + HRESULT res = S_OK; 1.57 + try 1.58 + { 1.59 + for (int i = 0; i < numProps; i++) 1.60 + { 1.61 + const CProp &prop = method.Props[i]; 1.62 + propIDs.Add(prop.Id); 1.63 + NWindows::NCOM::CPropVariant &value = values[i]; 1.64 + value = prop.Value; 1.65 + // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal) 1.66 + if (tryReduce) 1.67 + if (prop.Id == NCoderPropID::kDictionarySize) 1.68 + if (value.vt == VT_UI4) 1.69 + if (reducedDictionarySize < value.ulVal) 1.70 + value.ulVal = reducedDictionarySize; 1.71 + } 1.72 + CMyComPtr<ICompressSetCoderProperties> setCoderProperties; 1.73 + coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); 1.74 + res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps); 1.75 + } 1.76 + catch(...) 1.77 + { 1.78 + delete []values; 1.79 + throw; 1.80 + } 1.81 + delete []values; 1.82 + RINOK(res); 1.83 + } 1.84 + } 1.85 + 1.86 + /* 1.87 + CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties; 1.88 + coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties); 1.89 + if (writeCoderProperties != NULL) 1.90 + { 1.91 + CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp; 1.92 + CMyComPtr<ISequentialOutStream> outStream(outStreamSpec); 1.93 + outStreamSpec->Init(); 1.94 + RINOK(writeCoderProperties->WriteCoderProperties(outStream)); 1.95 + size_t size = outStreamSpec->GetSize(); 1.96 + filterProps.SetCapacity(size); 1.97 + memmove(filterProps, outStreamSpec->GetBuffer(), size); 1.98 + } 1.99 + */ 1.100 + return S_OK; 1.101 +} 1.102 +