1370b324cSopenharmony_ci// ProgressUtils.cpp
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#include "StdAfx.h"
4370b324cSopenharmony_ci
5370b324cSopenharmony_ci#include "ProgressUtils.h"
6370b324cSopenharmony_ci
7370b324cSopenharmony_ciCLocalProgress::CLocalProgress():
8370b324cSopenharmony_ci    SendRatio(true),
9370b324cSopenharmony_ci    SendProgress(true),
10370b324cSopenharmony_ci    ProgressOffset(0),
11370b324cSopenharmony_ci    InSize(0),
12370b324cSopenharmony_ci    OutSize(0)
13370b324cSopenharmony_ci  {}
14370b324cSopenharmony_ci
15370b324cSopenharmony_civoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)
16370b324cSopenharmony_ci{
17370b324cSopenharmony_ci  _ratioProgress.Release();
18370b324cSopenharmony_ci  _progress = progress;
19370b324cSopenharmony_ci  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);
20370b324cSopenharmony_ci  _inSizeIsMain = inSizeIsMain;
21370b324cSopenharmony_ci}
22370b324cSopenharmony_ci
23370b324cSopenharmony_ciZ7_COM7F_IMF(CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
24370b324cSopenharmony_ci{
25370b324cSopenharmony_ci  UInt64 inSize2 = InSize;
26370b324cSopenharmony_ci  UInt64 outSize2 = OutSize;
27370b324cSopenharmony_ci
28370b324cSopenharmony_ci  if (inSize)
29370b324cSopenharmony_ci    inSize2 += (*inSize);
30370b324cSopenharmony_ci  if (outSize)
31370b324cSopenharmony_ci    outSize2 += (*outSize);
32370b324cSopenharmony_ci
33370b324cSopenharmony_ci  if (SendRatio && _ratioProgress)
34370b324cSopenharmony_ci  {
35370b324cSopenharmony_ci    RINOK(_ratioProgress->SetRatioInfo(&inSize2, &outSize2))
36370b324cSopenharmony_ci  }
37370b324cSopenharmony_ci
38370b324cSopenharmony_ci  if (SendProgress)
39370b324cSopenharmony_ci  {
40370b324cSopenharmony_ci    inSize2 += ProgressOffset;
41370b324cSopenharmony_ci    outSize2 += ProgressOffset;
42370b324cSopenharmony_ci    return _progress->SetCompleted(_inSizeIsMain ? &inSize2 : &outSize2);
43370b324cSopenharmony_ci  }
44370b324cSopenharmony_ci
45370b324cSopenharmony_ci  return S_OK;
46370b324cSopenharmony_ci}
47370b324cSopenharmony_ci
48370b324cSopenharmony_ciHRESULT CLocalProgress::SetCur()
49370b324cSopenharmony_ci{
50370b324cSopenharmony_ci  return SetRatioInfo(NULL, NULL);
51370b324cSopenharmony_ci}
52