1 // HandlerOut.cpp
2
3 #include "StdAfx.h"
4
5 #ifndef _7ZIP_ST
6 #include "../../../Windows/System.h"
7 #endif
8
9 #include "../Common/ParseProperties.h"
10
11 #include "HandlerOut.h"
12
13 using namespace NWindows;
14
15 namespace NArchive {
16
SetMethodProp32(COneMethodInfo & m,PROPID propID,UInt32 value)17 static void SetMethodProp32(COneMethodInfo &m, PROPID propID, UInt32 value)
18 {
19 if (m.FindProp(propID) < 0)
20 m.AddProp32(propID, value);
21 }
22
SetGlobalLevelAndThreads(COneMethodInfo & oneMethodInfo,UInt32 numThreads)23 void CMultiMethodProps::SetGlobalLevelAndThreads(COneMethodInfo &oneMethodInfo
24 #ifndef _7ZIP_ST
25 , UInt32 numThreads
26 #endif
27 )
28 {
29 UInt32 level = _level;
30 if (level != (UInt32)(Int32)-1)
31 SetMethodProp32(oneMethodInfo, NCoderPropID::kLevel, (UInt32)level);
32
33 #ifndef _7ZIP_ST
34 SetMethodProp32(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
35 #endif
36 }
37
Init()38 void CMultiMethodProps::Init()
39 {
40 #ifndef _7ZIP_ST
41 _numProcessors = _numThreads = NSystem::GetNumberOfProcessors();
42 #endif
43
44 _level = (UInt32)(Int32)-1;
45 _analysisLevel = -1;
46
47 _autoFilter = true;
48 _crcSize = 4;
49 _filterMethod.Clear();
50 _methods.Clear();
51 }
52
SetProperty(const wchar_t * nameSpec,const PROPVARIANT & value)53 HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)
54 {
55 UString name = nameSpec;
56 name.MakeLower_Ascii();
57 if (name.IsEmpty())
58 return E_INVALIDARG;
59
60 if (name[0] == 'x')
61 {
62 name.Delete(0);
63 _level = 9;
64 return ParsePropToUInt32(name, value, _level);
65 }
66
67 if (name.IsPrefixedBy_Ascii_NoCase("yx"))
68 {
69 name.Delete(0, 2);
70 UInt32 v = 9;
71 RINOK(ParsePropToUInt32(name, value, v));
72 _analysisLevel = (int)v;
73 return S_OK;
74 }
75
76 if (name.IsEqualTo("crc"))
77 {
78 name.Delete(0, 3);
79 _crcSize = 4;
80 return ParsePropToUInt32(name, value, _crcSize);
81 }
82
83 UInt32 number;
84 unsigned index = ParseStringToUInt32(name, number);
85 UString realName = name.Ptr(index);
86 if (index == 0)
87 {
88 if (name.IsPrefixedBy_Ascii_NoCase("mt"))
89 {
90 #ifndef _7ZIP_ST
91 RINOK(ParseMtProp(name.Ptr(2), value, _numProcessors, _numThreads));
92 #endif
93
94 return S_OK;
95 }
96 if (name.IsEqualTo("f"))
97 {
98 HRESULT res = PROPVARIANT_to_bool(value, _autoFilter);
99 if (res == S_OK)
100 return res;
101 if (value.vt != VT_BSTR)
102 return E_INVALIDARG;
103 return _filterMethod.ParseMethodFromPROPVARIANT(UString(), value);
104 }
105 number = 0;
106 }
107 if (number > 64)
108 return E_FAIL;
109 for (int j = _methods.Size(); j <= (int)number; j++)
110 _methods.Add(COneMethodInfo());
111 return _methods[number].ParseMethodFromPROPVARIANT(realName, value);
112 }
113
Init()114 void CSingleMethodProps::Init()
115 {
116 Clear();
117 _level = (UInt32)(Int32)-1;
118
119 #ifndef _7ZIP_ST
120 _numProcessors = _numThreads = NWindows::NSystem::GetNumberOfProcessors();
121 AddProp_NumThreads(_numThreads);
122 #endif
123 }
124
SetProperties(const wchar_t * const * names,const PROPVARIANT * values,UInt32 numProps)125 HRESULT CSingleMethodProps::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps)
126 {
127 Init();
128 for (UInt32 i = 0; i < numProps; i++)
129 {
130 UString name = names[i];
131 name.MakeLower_Ascii();
132 if (name.IsEmpty())
133 return E_INVALIDARG;
134 const PROPVARIANT &value = values[i];
135 if (name[0] == L'x')
136 {
137 UInt32 a = 9;
138 RINOK(ParsePropToUInt32(name.Ptr(1), value, a));
139 _level = a;
140 AddProp_Level(a);
141 }
142 else if (name.IsPrefixedBy_Ascii_NoCase("mt"))
143 {
144 #ifndef _7ZIP_ST
145 RINOK(ParseMtProp(name.Ptr(2), value, _numProcessors, _numThreads));
146 AddProp_NumThreads(_numThreads);
147 #endif
148 }
149 else
150 {
151 RINOK(ParseMethodFromPROPVARIANT(names[i], value));
152 }
153 }
154 return S_OK;
155 }
156
157 }
158