SetProperties.cpp 1.6 KB

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