MethodProps.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // MethodProps.cpp
  2. #include "StdAfx.h"
  3. #include "MethodProps.h"
  4. #include "../../Common/MyCom.h"
  5. static UInt64 k_LZMA = 0x030101;
  6. // static UInt64 k_LZMA2 = 0x030102;
  7. HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)
  8. {
  9. bool tryReduce = false;
  10. UInt32 reducedDictionarySize = 1 << 10;
  11. if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))
  12. {
  13. for (;;)
  14. {
  15. const UInt32 step = (reducedDictionarySize >> 1);
  16. if (reducedDictionarySize >= *inSizeForReduce)
  17. {
  18. tryReduce = true;
  19. break;
  20. }
  21. reducedDictionarySize += step;
  22. if (reducedDictionarySize >= *inSizeForReduce)
  23. {
  24. tryReduce = true;
  25. break;
  26. }
  27. if (reducedDictionarySize >= ((UInt32)3 << 30))
  28. break;
  29. reducedDictionarySize += step;
  30. }
  31. }
  32. {
  33. int numProperties = method.Properties.Size();
  34. CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
  35. coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
  36. if (setCoderProperties == NULL)
  37. {
  38. if (numProperties != 0)
  39. return E_INVALIDARG;
  40. }
  41. else
  42. {
  43. CRecordVector<PROPID> propIDs;
  44. NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];
  45. HRESULT res = S_OK;
  46. try
  47. {
  48. for (int i = 0; i < numProperties; i++)
  49. {
  50. const CProp &prop = method.Properties[i];
  51. propIDs.Add(prop.Id);
  52. NWindows::NCOM::CPropVariant &value = values[i];
  53. value = prop.Value;
  54. // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)
  55. if (tryReduce)
  56. if (prop.Id == NCoderPropID::kDictionarySize)
  57. if (value.vt == VT_UI4)
  58. if (reducedDictionarySize < value.ulVal)
  59. value.ulVal = reducedDictionarySize;
  60. }
  61. CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
  62. coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
  63. res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties);
  64. }
  65. catch(...)
  66. {
  67. delete []values;
  68. throw;
  69. }
  70. delete []values;
  71. RINOK(res);
  72. }
  73. }
  74. /*
  75. CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
  76. coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);
  77. if (writeCoderProperties != NULL)
  78. {
  79. CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
  80. CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
  81. outStreamSpec->Init();
  82. RINOK(writeCoderProperties->WriteCoderProperties(outStream));
  83. size_t size = outStreamSpec->GetSize();
  84. filterProps.SetCapacity(size);
  85. memmove(filterProps, outStreamSpec->GetBuffer(), size);
  86. }
  87. */
  88. return S_OK;
  89. }