1370b324cSopenharmony_ci// HandlerOut.cpp 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#include "StdAfx.h" 4370b324cSopenharmony_ci 5370b324cSopenharmony_ci#include "../../../Common/StringToInt.h" 6370b324cSopenharmony_ci 7370b324cSopenharmony_ci#include "../Common/ParseProperties.h" 8370b324cSopenharmony_ci 9370b324cSopenharmony_ci#include "HandlerOut.h" 10370b324cSopenharmony_ci 11370b324cSopenharmony_cinamespace NArchive { 12370b324cSopenharmony_ci 13370b324cSopenharmony_cibool ParseSizeString(const wchar_t *s, const PROPVARIANT &prop, UInt64 percentsBase, UInt64 &res) 14370b324cSopenharmony_ci{ 15370b324cSopenharmony_ci if (*s == 0) 16370b324cSopenharmony_ci { 17370b324cSopenharmony_ci switch (prop.vt) 18370b324cSopenharmony_ci { 19370b324cSopenharmony_ci case VT_UI4: res = prop.ulVal; return true; 20370b324cSopenharmony_ci case VT_UI8: res = prop.uhVal.QuadPart; return true; 21370b324cSopenharmony_ci case VT_BSTR: 22370b324cSopenharmony_ci s = prop.bstrVal; 23370b324cSopenharmony_ci break; 24370b324cSopenharmony_ci default: return false; 25370b324cSopenharmony_ci } 26370b324cSopenharmony_ci } 27370b324cSopenharmony_ci else if (prop.vt != VT_EMPTY) 28370b324cSopenharmony_ci return false; 29370b324cSopenharmony_ci 30370b324cSopenharmony_ci bool percentMode = false; 31370b324cSopenharmony_ci { 32370b324cSopenharmony_ci const wchar_t c = *s; 33370b324cSopenharmony_ci if (MyCharLower_Ascii(c) == 'p') 34370b324cSopenharmony_ci { 35370b324cSopenharmony_ci percentMode = true; 36370b324cSopenharmony_ci s++; 37370b324cSopenharmony_ci } 38370b324cSopenharmony_ci } 39370b324cSopenharmony_ci 40370b324cSopenharmony_ci const wchar_t *end; 41370b324cSopenharmony_ci const UInt64 v = ConvertStringToUInt64(s, &end); 42370b324cSopenharmony_ci if (s == end) 43370b324cSopenharmony_ci return false; 44370b324cSopenharmony_ci const wchar_t c = *end; 45370b324cSopenharmony_ci 46370b324cSopenharmony_ci if (percentMode) 47370b324cSopenharmony_ci { 48370b324cSopenharmony_ci if (c != 0) 49370b324cSopenharmony_ci return false; 50370b324cSopenharmony_ci res = Calc_From_Val_Percents(percentsBase, v); 51370b324cSopenharmony_ci return true; 52370b324cSopenharmony_ci } 53370b324cSopenharmony_ci 54370b324cSopenharmony_ci if (c == 0) 55370b324cSopenharmony_ci { 56370b324cSopenharmony_ci res = v; 57370b324cSopenharmony_ci return true; 58370b324cSopenharmony_ci } 59370b324cSopenharmony_ci if (end[1] != 0) 60370b324cSopenharmony_ci return false; 61370b324cSopenharmony_ci 62370b324cSopenharmony_ci if (c == '%') 63370b324cSopenharmony_ci { 64370b324cSopenharmony_ci res = Calc_From_Val_Percents(percentsBase, v); 65370b324cSopenharmony_ci return true; 66370b324cSopenharmony_ci } 67370b324cSopenharmony_ci 68370b324cSopenharmony_ci unsigned numBits; 69370b324cSopenharmony_ci switch (MyCharLower_Ascii(c)) 70370b324cSopenharmony_ci { 71370b324cSopenharmony_ci case 'b': numBits = 0; break; 72370b324cSopenharmony_ci case 'k': numBits = 10; break; 73370b324cSopenharmony_ci case 'm': numBits = 20; break; 74370b324cSopenharmony_ci case 'g': numBits = 30; break; 75370b324cSopenharmony_ci case 't': numBits = 40; break; 76370b324cSopenharmony_ci default: return false; 77370b324cSopenharmony_ci } 78370b324cSopenharmony_ci const UInt64 val2 = v << numBits; 79370b324cSopenharmony_ci if ((val2 >> numBits) != v) 80370b324cSopenharmony_ci return false; 81370b324cSopenharmony_ci res = val2; 82370b324cSopenharmony_ci return true; 83370b324cSopenharmony_ci} 84370b324cSopenharmony_ci 85370b324cSopenharmony_cibool CCommonMethodProps::SetCommonProperty(const UString &name, const PROPVARIANT &value, HRESULT &hres) 86370b324cSopenharmony_ci{ 87370b324cSopenharmony_ci hres = S_OK; 88370b324cSopenharmony_ci 89370b324cSopenharmony_ci if (name.IsPrefixedBy_Ascii_NoCase("mt")) 90370b324cSopenharmony_ci { 91370b324cSopenharmony_ci #ifndef Z7_ST 92370b324cSopenharmony_ci _numThreads = _numProcessors; 93370b324cSopenharmony_ci _numThreads_WasForced = false; 94370b324cSopenharmony_ci hres = ParseMtProp2(name.Ptr(2), value, _numThreads, _numThreads_WasForced); 95370b324cSopenharmony_ci // "mt" means "_numThreads_WasForced = false" here 96370b324cSopenharmony_ci #endif 97370b324cSopenharmony_ci return true; 98370b324cSopenharmony_ci } 99370b324cSopenharmony_ci 100370b324cSopenharmony_ci if (name.IsPrefixedBy_Ascii_NoCase("memuse")) 101370b324cSopenharmony_ci { 102370b324cSopenharmony_ci UInt64 v; 103370b324cSopenharmony_ci if (!ParseSizeString(name.Ptr(6), value, _memAvail, v)) 104370b324cSopenharmony_ci hres = E_INVALIDARG; 105370b324cSopenharmony_ci _memUsage_Decompress = v; 106370b324cSopenharmony_ci _memUsage_Compress = v; 107370b324cSopenharmony_ci _memUsage_WasSet = true; 108370b324cSopenharmony_ci return true; 109370b324cSopenharmony_ci } 110370b324cSopenharmony_ci 111370b324cSopenharmony_ci return false; 112370b324cSopenharmony_ci} 113370b324cSopenharmony_ci 114370b324cSopenharmony_ci 115370b324cSopenharmony_ci#ifndef Z7_EXTRACT_ONLY 116370b324cSopenharmony_ci 117370b324cSopenharmony_cistatic void SetMethodProp32(CMethodProps &m, PROPID propID, UInt32 value) 118370b324cSopenharmony_ci{ 119370b324cSopenharmony_ci if (m.FindProp(propID) < 0) 120370b324cSopenharmony_ci m.AddProp32(propID, value); 121370b324cSopenharmony_ci} 122370b324cSopenharmony_ci 123370b324cSopenharmony_civoid CMultiMethodProps::SetGlobalLevelTo(COneMethodInfo &oneMethodInfo) const 124370b324cSopenharmony_ci{ 125370b324cSopenharmony_ci UInt32 level = _level; 126370b324cSopenharmony_ci if (level != (UInt32)(Int32)-1) 127370b324cSopenharmony_ci SetMethodProp32(oneMethodInfo, NCoderPropID::kLevel, (UInt32)level); 128370b324cSopenharmony_ci} 129370b324cSopenharmony_ci 130370b324cSopenharmony_ci#ifndef Z7_ST 131370b324cSopenharmony_ci 132370b324cSopenharmony_cistatic void SetMethodProp32_Replace(CMethodProps &m, PROPID propID, UInt32 value) 133370b324cSopenharmony_ci{ 134370b324cSopenharmony_ci const int i = m.FindProp(propID); 135370b324cSopenharmony_ci if (i >= 0) 136370b324cSopenharmony_ci { 137370b324cSopenharmony_ci NWindows::NCOM::CPropVariant &val = m.Props[(unsigned)i].Value; 138370b324cSopenharmony_ci val = (UInt32)value; 139370b324cSopenharmony_ci return; 140370b324cSopenharmony_ci } 141370b324cSopenharmony_ci m.AddProp32(propID, value); 142370b324cSopenharmony_ci} 143370b324cSopenharmony_ci 144370b324cSopenharmony_civoid CMultiMethodProps::SetMethodThreadsTo_IfNotFinded(CMethodProps &oneMethodInfo, UInt32 numThreads) 145370b324cSopenharmony_ci{ 146370b324cSopenharmony_ci SetMethodProp32(oneMethodInfo, NCoderPropID::kNumThreads, numThreads); 147370b324cSopenharmony_ci} 148370b324cSopenharmony_ci 149370b324cSopenharmony_civoid CMultiMethodProps::SetMethodThreadsTo_Replace(CMethodProps &oneMethodInfo, UInt32 numThreads) 150370b324cSopenharmony_ci{ 151370b324cSopenharmony_ci SetMethodProp32_Replace(oneMethodInfo, NCoderPropID::kNumThreads, numThreads); 152370b324cSopenharmony_ci} 153370b324cSopenharmony_ci 154370b324cSopenharmony_ci#endif // Z7_ST 155370b324cSopenharmony_ci 156370b324cSopenharmony_ci 157370b324cSopenharmony_civoid CMultiMethodProps::InitMulti() 158370b324cSopenharmony_ci{ 159370b324cSopenharmony_ci _level = (UInt32)(Int32)-1; 160370b324cSopenharmony_ci _analysisLevel = -1; 161370b324cSopenharmony_ci _crcSize = 4; 162370b324cSopenharmony_ci _autoFilter = true; 163370b324cSopenharmony_ci} 164370b324cSopenharmony_ci 165370b324cSopenharmony_civoid CMultiMethodProps::Init() 166370b324cSopenharmony_ci{ 167370b324cSopenharmony_ci InitCommon(); 168370b324cSopenharmony_ci InitMulti(); 169370b324cSopenharmony_ci _methods.Clear(); 170370b324cSopenharmony_ci _filterMethod.Clear(); 171370b324cSopenharmony_ci} 172370b324cSopenharmony_ci 173370b324cSopenharmony_ci 174370b324cSopenharmony_ciHRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value) 175370b324cSopenharmony_ci{ 176370b324cSopenharmony_ci UString name = nameSpec; 177370b324cSopenharmony_ci name.MakeLower_Ascii(); 178370b324cSopenharmony_ci if (name.IsEmpty()) 179370b324cSopenharmony_ci return E_INVALIDARG; 180370b324cSopenharmony_ci 181370b324cSopenharmony_ci if (name[0] == 'x') 182370b324cSopenharmony_ci { 183370b324cSopenharmony_ci name.Delete(0); 184370b324cSopenharmony_ci _level = 9; 185370b324cSopenharmony_ci return ParsePropToUInt32(name, value, _level); 186370b324cSopenharmony_ci } 187370b324cSopenharmony_ci 188370b324cSopenharmony_ci if (name.IsPrefixedBy_Ascii_NoCase("yx")) 189370b324cSopenharmony_ci { 190370b324cSopenharmony_ci name.Delete(0, 2); 191370b324cSopenharmony_ci UInt32 v = 9; 192370b324cSopenharmony_ci RINOK(ParsePropToUInt32(name, value, v)) 193370b324cSopenharmony_ci _analysisLevel = (int)v; 194370b324cSopenharmony_ci return S_OK; 195370b324cSopenharmony_ci } 196370b324cSopenharmony_ci 197370b324cSopenharmony_ci if (name.IsPrefixedBy_Ascii_NoCase("crc")) 198370b324cSopenharmony_ci { 199370b324cSopenharmony_ci name.Delete(0, 3); 200370b324cSopenharmony_ci _crcSize = 4; 201370b324cSopenharmony_ci return ParsePropToUInt32(name, value, _crcSize); 202370b324cSopenharmony_ci } 203370b324cSopenharmony_ci 204370b324cSopenharmony_ci { 205370b324cSopenharmony_ci HRESULT hres; 206370b324cSopenharmony_ci if (SetCommonProperty(name, value, hres)) 207370b324cSopenharmony_ci return hres; 208370b324cSopenharmony_ci } 209370b324cSopenharmony_ci 210370b324cSopenharmony_ci UInt32 number; 211370b324cSopenharmony_ci const unsigned index = ParseStringToUInt32(name, number); 212370b324cSopenharmony_ci const UString realName = name.Ptr(index); 213370b324cSopenharmony_ci if (index == 0) 214370b324cSopenharmony_ci { 215370b324cSopenharmony_ci if (name.IsEqualTo("f")) 216370b324cSopenharmony_ci { 217370b324cSopenharmony_ci const HRESULT res = PROPVARIANT_to_bool(value, _autoFilter); 218370b324cSopenharmony_ci if (res == S_OK) 219370b324cSopenharmony_ci return res; 220370b324cSopenharmony_ci if (value.vt != VT_BSTR) 221370b324cSopenharmony_ci return E_INVALIDARG; 222370b324cSopenharmony_ci return _filterMethod.ParseMethodFromPROPVARIANT(UString(), value); 223370b324cSopenharmony_ci } 224370b324cSopenharmony_ci number = 0; 225370b324cSopenharmony_ci } 226370b324cSopenharmony_ci if (number > 64) 227370b324cSopenharmony_ci return E_INVALIDARG; 228370b324cSopenharmony_ci for (unsigned j = _methods.Size(); j <= number; j++) 229370b324cSopenharmony_ci _methods.AddNew(); 230370b324cSopenharmony_ci return _methods[number].ParseMethodFromPROPVARIANT(realName, value); 231370b324cSopenharmony_ci} 232370b324cSopenharmony_ci 233370b324cSopenharmony_ci 234370b324cSopenharmony_ci 235370b324cSopenharmony_civoid CSingleMethodProps::Init() 236370b324cSopenharmony_ci{ 237370b324cSopenharmony_ci InitCommon(); 238370b324cSopenharmony_ci InitSingle(); 239370b324cSopenharmony_ci Clear(); 240370b324cSopenharmony_ci} 241370b324cSopenharmony_ci 242370b324cSopenharmony_ci 243370b324cSopenharmony_ciHRESULT CSingleMethodProps::SetProperty(const wchar_t *name2, const PROPVARIANT &value) 244370b324cSopenharmony_ci{ 245370b324cSopenharmony_ci // processed = false; 246370b324cSopenharmony_ci UString name = name2; 247370b324cSopenharmony_ci name.MakeLower_Ascii(); 248370b324cSopenharmony_ci if (name.IsEmpty()) 249370b324cSopenharmony_ci return E_INVALIDARG; 250370b324cSopenharmony_ci if (name.IsPrefixedBy_Ascii_NoCase("x")) 251370b324cSopenharmony_ci { 252370b324cSopenharmony_ci UInt32 a = 9; 253370b324cSopenharmony_ci RINOK(ParsePropToUInt32(name.Ptr(1), value, a)) 254370b324cSopenharmony_ci _level = a; 255370b324cSopenharmony_ci AddProp_Level(a); 256370b324cSopenharmony_ci // processed = true; 257370b324cSopenharmony_ci return S_OK; 258370b324cSopenharmony_ci } 259370b324cSopenharmony_ci { 260370b324cSopenharmony_ci HRESULT hres; 261370b324cSopenharmony_ci if (SetCommonProperty(name, value, hres)) 262370b324cSopenharmony_ci { 263370b324cSopenharmony_ci // processed = true; 264370b324cSopenharmony_ci return S_OK; 265370b324cSopenharmony_ci } 266370b324cSopenharmony_ci } 267370b324cSopenharmony_ci RINOK(ParseMethodFromPROPVARIANT(name, value)) 268370b324cSopenharmony_ci return S_OK; 269370b324cSopenharmony_ci} 270370b324cSopenharmony_ci 271370b324cSopenharmony_ci 272370b324cSopenharmony_ciHRESULT CSingleMethodProps::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps) 273370b324cSopenharmony_ci{ 274370b324cSopenharmony_ci Init(); 275370b324cSopenharmony_ci 276370b324cSopenharmony_ci for (UInt32 i = 0; i < numProps; i++) 277370b324cSopenharmony_ci { 278370b324cSopenharmony_ci RINOK(SetProperty(names[i], values[i])) 279370b324cSopenharmony_ci } 280370b324cSopenharmony_ci 281370b324cSopenharmony_ci return S_OK; 282370b324cSopenharmony_ci} 283370b324cSopenharmony_ci 284370b324cSopenharmony_ci#endif 285370b324cSopenharmony_ci 286370b324cSopenharmony_ci 287370b324cSopenharmony_cistatic HRESULT PROPVARIANT_to_BoolPair(const PROPVARIANT &prop, CBoolPair &dest) 288370b324cSopenharmony_ci{ 289370b324cSopenharmony_ci RINOK(PROPVARIANT_to_bool(prop, dest.Val)) 290370b324cSopenharmony_ci dest.Def = true; 291370b324cSopenharmony_ci return S_OK; 292370b324cSopenharmony_ci} 293370b324cSopenharmony_ci 294370b324cSopenharmony_ciHRESULT CHandlerTimeOptions::Parse(const UString &name, const PROPVARIANT &prop, bool &processed) 295370b324cSopenharmony_ci{ 296370b324cSopenharmony_ci processed = true; 297370b324cSopenharmony_ci if (name.IsEqualTo_Ascii_NoCase("tm")) { return PROPVARIANT_to_BoolPair(prop, Write_MTime); } 298370b324cSopenharmony_ci if (name.IsEqualTo_Ascii_NoCase("ta")) { return PROPVARIANT_to_BoolPair(prop, Write_ATime); } 299370b324cSopenharmony_ci if (name.IsEqualTo_Ascii_NoCase("tc")) { return PROPVARIANT_to_BoolPair(prop, Write_CTime); } 300370b324cSopenharmony_ci if (name.IsPrefixedBy_Ascii_NoCase("tp")) 301370b324cSopenharmony_ci { 302370b324cSopenharmony_ci UInt32 v = 0; 303370b324cSopenharmony_ci RINOK(ParsePropToUInt32(name.Ptr(2), prop, v)) 304370b324cSopenharmony_ci Prec = v; 305370b324cSopenharmony_ci return S_OK; 306370b324cSopenharmony_ci } 307370b324cSopenharmony_ci processed = false; 308370b324cSopenharmony_ci return S_OK; 309370b324cSopenharmony_ci} 310370b324cSopenharmony_ci 311370b324cSopenharmony_ci} 312