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