1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// SetProperties.cpp 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "StdAfx.h" 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "SetProperties.h" 6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Windows/PropVariant.h" 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Common/MyString.h" 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Common/StringToInt.h" 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Common/MyCom.h" 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../Archive/IArchive.h" 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 14baa3858d3f5d128a5c8466b700098109edcad5f2repo syncusing namespace NWindows; 15baa3858d3f5d128a5c8466b700098109edcad5f2repo syncusing namespace NCOM; 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 17baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop) 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const wchar_t *endPtr; 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt64 result = ConvertStringToUInt64(s, &endPtr); 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (endPtr - (const wchar_t *)s != s.Length()) 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = s; 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (result <= 0xFFFFFFFF) 24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = (UInt32)result; 25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = result; 27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 29baa3858d3f5d128a5c8466b700098109edcad5f2repo syncHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties) 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (properties.IsEmpty()) 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CMyComPtr<ISetProperties> setProperties; 34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties); 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!setProperties) 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UStringVector realNames; 39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CPropVariant *values = new CPropVariant[properties.Size()]; 40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync try 41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int i; 43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for(i = 0; i < properties.Size(); i++) 44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CProperty &property = properties[i]; 46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync NCOM::CPropVariant propVariant; 47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString name = property.Name; 48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (property.Value.IsEmpty()) 49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!name.IsEmpty()) 51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync wchar_t c = name[name.Length() - 1]; 53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (c == L'-') 54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propVariant = false; 55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (c == L'+') 56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propVariant = true; 57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (propVariant.vt != VT_EMPTY) 58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync name = name.Left(name.Length() - 1); 59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ParseNumberString(property.Value, propVariant); 63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync realNames.Add(name); 64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync values[i] = propVariant; 65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CRecordVector<const wchar_t *> names; 67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for(i = 0; i < realNames.Size(); i++) 68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync names.Add((const wchar_t *)realNames[i]); 69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync RINOK(setProperties->SetProperties(&names.Front(), values, names.Size())); 71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync catch(...) 73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync delete []values; 75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync throw; 76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync delete []values; 78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 80