ProgressUtils.cpp 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // ProgressUtils.h
  2. #include "StdAfx.h"
  3. #include "ProgressUtils.h"
  4. CLocalProgress::CLocalProgress()
  5. {
  6. ProgressOffset = InSize = OutSize = 0;
  7. SendRatio = SendProgress = true;
  8. }
  9. void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)
  10. {
  11. _ratioProgress.Release();
  12. _progress = progress;
  13. _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);
  14. _inSizeIsMain = inSizeIsMain;
  15. }
  16. STDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
  17. {
  18. UInt64 inSizeNew = InSize, outSizeNew = OutSize;
  19. if (inSize)
  20. inSizeNew += (*inSize);
  21. if (outSize)
  22. outSizeNew += (*outSize);
  23. if (SendRatio && _ratioProgress)
  24. {
  25. RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));
  26. }
  27. inSizeNew += ProgressOffset;
  28. outSizeNew += ProgressOffset;
  29. if (SendProgress)
  30. return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);
  31. return S_OK;
  32. }
  33. HRESULT CLocalProgress::SetCur()
  34. {
  35. return SetRatioInfo(NULL, NULL);
  36. }