1370b324cSopenharmony_ci// SetProperties.cpp
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#include "StdAfx.h"
4370b324cSopenharmony_ci
5370b324cSopenharmony_ci#include "../../../Common/MyCom.h"
6370b324cSopenharmony_ci#include "../../../Common/MyString.h"
7370b324cSopenharmony_ci#include "../../../Common/StringToInt.h"
8370b324cSopenharmony_ci
9370b324cSopenharmony_ci#include "../../../Windows/PropVariant.h"
10370b324cSopenharmony_ci
11370b324cSopenharmony_ci#include "../../Archive/IArchive.h"
12370b324cSopenharmony_ci
13370b324cSopenharmony_ci#include "SetProperties.h"
14370b324cSopenharmony_ci
15370b324cSopenharmony_ciusing namespace NWindows;
16370b324cSopenharmony_ciusing namespace NCOM;
17370b324cSopenharmony_ci
18370b324cSopenharmony_cistatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)
19370b324cSopenharmony_ci{
20370b324cSopenharmony_ci  const wchar_t *end;
21370b324cSopenharmony_ci  const UInt64 result = ConvertStringToUInt64(s, &end);
22370b324cSopenharmony_ci  if (*end != 0 || s.IsEmpty())
23370b324cSopenharmony_ci    prop = s;
24370b324cSopenharmony_ci  else if (result <= (UInt32)0xFFFFFFFF)
25370b324cSopenharmony_ci    prop = (UInt32)result;
26370b324cSopenharmony_ci  else
27370b324cSopenharmony_ci    prop = result;
28370b324cSopenharmony_ci}
29370b324cSopenharmony_ci
30370b324cSopenharmony_ci
31370b324cSopenharmony_cistruct CPropPropetiesVector
32370b324cSopenharmony_ci{
33370b324cSopenharmony_ci  CPropVariant *values;
34370b324cSopenharmony_ci  CPropPropetiesVector(unsigned num)
35370b324cSopenharmony_ci  {
36370b324cSopenharmony_ci    values = new CPropVariant[num];
37370b324cSopenharmony_ci  }
38370b324cSopenharmony_ci  ~CPropPropetiesVector()
39370b324cSopenharmony_ci  {
40370b324cSopenharmony_ci    delete []values;
41370b324cSopenharmony_ci  }
42370b324cSopenharmony_ci};
43370b324cSopenharmony_ci
44370b324cSopenharmony_ci
45370b324cSopenharmony_ciHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)
46370b324cSopenharmony_ci{
47370b324cSopenharmony_ci  if (properties.IsEmpty())
48370b324cSopenharmony_ci    return S_OK;
49370b324cSopenharmony_ci  Z7_DECL_CMyComPtr_QI_FROM(
50370b324cSopenharmony_ci      ISetProperties,
51370b324cSopenharmony_ci      setProperties, unknown)
52370b324cSopenharmony_ci  if (!setProperties)
53370b324cSopenharmony_ci    return S_OK;
54370b324cSopenharmony_ci
55370b324cSopenharmony_ci  UStringVector realNames;
56370b324cSopenharmony_ci  CPropPropetiesVector values(properties.Size());
57370b324cSopenharmony_ci  {
58370b324cSopenharmony_ci    unsigned i;
59370b324cSopenharmony_ci    for (i = 0; i < properties.Size(); i++)
60370b324cSopenharmony_ci    {
61370b324cSopenharmony_ci      const CProperty &property = properties[i];
62370b324cSopenharmony_ci      NCOM::CPropVariant propVariant;
63370b324cSopenharmony_ci      UString name = property.Name;
64370b324cSopenharmony_ci      if (property.Value.IsEmpty())
65370b324cSopenharmony_ci      {
66370b324cSopenharmony_ci        if (!name.IsEmpty())
67370b324cSopenharmony_ci        {
68370b324cSopenharmony_ci          const wchar_t c = name.Back();
69370b324cSopenharmony_ci          if (c == L'-')
70370b324cSopenharmony_ci            propVariant = false;
71370b324cSopenharmony_ci          else if (c == L'+')
72370b324cSopenharmony_ci            propVariant = true;
73370b324cSopenharmony_ci          if (propVariant.vt != VT_EMPTY)
74370b324cSopenharmony_ci            name.DeleteBack();
75370b324cSopenharmony_ci        }
76370b324cSopenharmony_ci      }
77370b324cSopenharmony_ci      else
78370b324cSopenharmony_ci        ParseNumberString(property.Value, propVariant);
79370b324cSopenharmony_ci      realNames.Add(name);
80370b324cSopenharmony_ci      values.values[i] = propVariant;
81370b324cSopenharmony_ci    }
82370b324cSopenharmony_ci    CRecordVector<const wchar_t *> names;
83370b324cSopenharmony_ci    for (i = 0; i < realNames.Size(); i++)
84370b324cSopenharmony_ci      names.Add((const wchar_t *)realNames[i]);
85370b324cSopenharmony_ci
86370b324cSopenharmony_ci    return setProperties->SetProperties(&names.Front(), values.values, names.Size());
87370b324cSopenharmony_ci  }
88370b324cSopenharmony_ci}
89