1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// MethodProps.h 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __7Z_METHOD_PROPS_H 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __7Z_METHOD_PROPS_H 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 6cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#include "../../Common/MyString.h" 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../Windows/PropVariant.h" 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 10cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#include "../ICoder.h" 11cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 12cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckybool StringToBool(const UString &s, bool &res); 13cd66d540cead3f8200b0c73bad9c276d67896c3dDavid SrbeckyHRESULT PROPVARIANT_to_bool(const PROPVARIANT &prop, bool &dest); 14cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckyunsigned ParseStringToUInt32(const UString &srcString, UInt32 &number); 15cd66d540cead3f8200b0c73bad9c276d67896c3dDavid SrbeckyHRESULT ParsePropToUInt32(const UString &name, const PROPVARIANT &prop, UInt32 &resValue); 16cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 17cd66d540cead3f8200b0c73bad9c276d67896c3dDavid SrbeckyHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads); 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 19baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CProp 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync PROPID Id; 22cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky bool IsOptional; 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync NWindows::NCOM::CPropVariant Value; 24cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky CProp(): IsOptional(false) {} 25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 27cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckystruct CProps 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CObjectVector<CProp> Props; 30cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 31cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky void Clear() { Props.Clear(); } 32cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 33cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky bool AreThereNonOptionalProps() const 34cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 35cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky FOR_VECTOR (i, Props) 36cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (!Props[i].IsOptional) 37cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return true; 38cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return false; 39cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 40cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 41cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky void AddProp32(PROPID propid, UInt32 level); 42cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 43cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky void AddPropString(PROPID propid, const wchar_t *s) 44cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 45cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky CProp prop; 46cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky prop.IsOptional = true; 47cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky prop.Id = propid; 48cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky prop.Value = s; 49cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky Props.Add(prop); 50cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 51cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 52cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky HRESULT SetCoderProps(ICompressSetCoderProperties *scp, const UInt64 *dataSizeReduce) const; 53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 55cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckyclass CMethodProps: public CProps 56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 57cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky HRESULT SetParam(const UString &name, const UString &value); 58cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckypublic: 59cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int GetLevel() const; 60cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int Get_NumThreads() const 61cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 62cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int i = FindProp(NCoderPropID::kNumThreads); 63cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (i >= 0) 64cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (Props[i].Value.vt == VT_UI4) 65cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return (int)Props[i].Value.ulVal; 66cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return -1; 67cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 68cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 69cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky bool Get_DicSize(UInt32 &res) const 70cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 71cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky res = 0; 72cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int i = FindProp(NCoderPropID::kDictionarySize); 73cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (i >= 0) 74cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (Props[i].Value.vt == VT_UI4) 75cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 76cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky res = Props[i].Value.ulVal; 77cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return true; 78cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 79cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return false; 80cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 81cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 82cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int FindProp(PROPID id) const; 83cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 84cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Get_Lzma_Algo() const 85cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 86cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int i = FindProp(NCoderPropID::kAlgorithm); 87cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (i >= 0) 88cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (Props[i].Value.vt == VT_UI4) 89cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return Props[i].Value.ulVal; 90cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return GetLevel() >= 5 ? 1 : 0; 91cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 92cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 93cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Get_Lzma_DicSize() const 94cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 95cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int i = FindProp(NCoderPropID::kDictionarySize); 96cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (i >= 0) 97cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (Props[i].Value.vt == VT_UI4) 98cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return Props[i].Value.ulVal; 99cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int level = GetLevel(); 100cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)); 101cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 102cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 103cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Get_Lzma_NumThreads(bool &fixedNumber) const 104cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 105cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky fixedNumber = false; 106cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int numThreads = Get_NumThreads(); 107cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (numThreads >= 0) 108cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 109cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky fixedNumber = true; 110cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return numThreads < 2 ? 1 : 2; 111cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 112cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return Get_Lzma_Algo() == 0 ? 1 : 2; 113cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 114cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 115cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Get_BZip2_NumThreads(bool &fixedNumber) const 116cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 117cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky fixedNumber = false; 118cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int numThreads = Get_NumThreads(); 119cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (numThreads >= 0) 120cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 121cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky fixedNumber = true; 122cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (numThreads < 1) return 1; 123cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (numThreads > 64) return 64; 124cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return numThreads; 125cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 126cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return 1; 127cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 128cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 129cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Get_BZip2_BlockSize() const 130cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 131cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int i = FindProp(NCoderPropID::kDictionarySize); 132cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (i >= 0) 133cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (Props[i].Value.vt == VT_UI4) 134cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 135cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 blockSize = Props[i].Value.ulVal; 136cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky const UInt32 kDicSizeMin = 100000; 137cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky const UInt32 kDicSizeMax = 900000; 138cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (blockSize < kDicSizeMin) blockSize = kDicSizeMin; 139cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (blockSize > kDicSizeMax) blockSize = kDicSizeMax; 140cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return blockSize; 141cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 142cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int level = GetLevel(); 143cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return 100000 * (level >= 5 ? 9 : (level >= 1 ? level * 2 - 1: 1)); 144cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 145cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 146cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Get_Ppmd_MemSize() const 147cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 148cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int i = FindProp(NCoderPropID::kUsedMemorySize); 149cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (i >= 0) 150cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (Props[i].Value.vt == VT_UI4) 151cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return Props[i].Value.ulVal; 152cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky int level = GetLevel(); 153cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky return level >= 9 ? (192 << 20) : ((UInt32)1 << (level + 19)); 154cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 155cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 156cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky void AddLevelProp(UInt32 level) 157cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 158cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky AddProp32(NCoderPropID::kLevel, level); 159cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 160cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 161cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky void AddNumThreadsProp(UInt32 numThreads) 162cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 163cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky AddProp32(NCoderPropID::kNumThreads, numThreads); 164cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 165cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 166cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky HRESULT ParseParamsFromString(const UString &srcString); 167cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky HRESULT ParseParamsFromPROPVARIANT(const UString &realName, const PROPVARIANT &value); 168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 170cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckyclass COneMethodInfo: public CMethodProps 171cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky{ 172cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckypublic: 173cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UString MethodName; 174cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 175cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky void Clear() 176cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 177cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky CMethodProps::Clear(); 178cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky MethodName.Empty(); 179cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 180cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky bool IsEmpty() const { return MethodName.IsEmpty() && Props.IsEmpty(); } 181cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky HRESULT ParseMethodFromPROPVARIANT(const UString &realName, const PROPVARIANT &value); 182cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky HRESULT ParseMethodFromString(const UString &s); 183cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky}; 184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 185baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 186