misc/libphysfs/lzma/CPP/7zip/UI/Common/SetProperties.cpp
branchui-scaling
changeset 15283 c4fd2813b127
parent 13390 0135e64c6c66
parent 15279 7ab5cf405686
child 15663 d92eeb468dad
equal deleted inserted replaced
13390:0135e64c6c66 15283:c4fd2813b127
     1 // SetProperties.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "SetProperties.h"
       
     6 
       
     7 #include "Windows/PropVariant.h"
       
     8 #include "Common/MyString.h"
       
     9 #include "Common/StringToInt.h"
       
    10 #include "Common/MyCom.h"
       
    11 
       
    12 #include "../../Archive/IArchive.h"
       
    13 
       
    14 using namespace NWindows;
       
    15 using namespace NCOM;
       
    16 
       
    17 static void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)
       
    18 {
       
    19   const wchar_t *endPtr;
       
    20   UInt64 result = ConvertStringToUInt64(s, &endPtr);
       
    21   if (endPtr - (const wchar_t *)s != s.Length())
       
    22     prop = s;
       
    23   else if (result <= 0xFFFFFFFF)
       
    24     prop = (UInt32)result;
       
    25   else 
       
    26     prop = result;
       
    27 }
       
    28 
       
    29 HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)
       
    30 {
       
    31   if (properties.IsEmpty())
       
    32     return S_OK;
       
    33   CMyComPtr<ISetProperties> setProperties;
       
    34   unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);
       
    35   if (!setProperties)
       
    36     return S_OK;
       
    37 
       
    38   UStringVector realNames;
       
    39   CPropVariant *values = new CPropVariant[properties.Size()];
       
    40   try
       
    41   {
       
    42     int i;
       
    43     for(i = 0; i < properties.Size(); i++)
       
    44     {
       
    45       const CProperty &property = properties[i];
       
    46       NCOM::CPropVariant propVariant;
       
    47       if (!property.Value.IsEmpty())
       
    48         ParseNumberString(property.Value, propVariant);
       
    49       realNames.Add(property.Name);
       
    50       values[i] = propVariant;
       
    51     }
       
    52     CRecordVector<const wchar_t *> names;
       
    53     for(i = 0; i < realNames.Size(); i++)
       
    54       names.Add((const wchar_t *)realNames[i]);
       
    55     
       
    56     RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));
       
    57   }
       
    58   catch(...)
       
    59   {
       
    60     delete []values;
       
    61     throw;
       
    62   }
       
    63   delete []values;
       
    64   return S_OK;
       
    65 }