2 #include "MACProgressHelper.h"
6 CMACProgressHelper::CMACProgressHelper(int nTotalSteps
, int * pPercentageDone
, APE_PROGRESS_CALLBACK ProgressCallback
, int * pKillFlag
)
8 m_pKillFlag
= pKillFlag
;
10 m_bUseCallback
= FALSE
;
11 if (ProgressCallback
!= NULL
)
13 m_bUseCallback
= TRUE
;
14 m_CallbackFunction
= ProgressCallback
;
17 m_pPercentageDone
= pPercentageDone
;
19 m_nTotalSteps
= nTotalSteps
;
21 m_nLastCallbackFiredPercentageDone
= 0;
26 CMACProgressHelper::~CMACProgressHelper()
31 void CMACProgressHelper::UpdateProgress(int nCurrentStep
, BOOL bForceUpdate
)
34 if (nCurrentStep
== -1)
37 m_nCurrentStep
= nCurrentStep
;
39 // figure the percentage done
40 float fPercentageDone
= float(m_nCurrentStep
) / float(max(m_nTotalSteps
, 1));
41 int nPercentageDone
= (int) (fPercentageDone
* 1000 * 100);
42 if (nPercentageDone
> 100000) nPercentageDone
= 100000;
44 // update the percent done pointer
45 if (m_pPercentageDone
)
47 *m_pPercentageDone
= nPercentageDone
;
53 if (bForceUpdate
|| (nPercentageDone
- m_nLastCallbackFiredPercentageDone
) >= 1000)
55 m_CallbackFunction(nPercentageDone
);
56 m_nLastCallbackFiredPercentageDone
= nPercentageDone
;
61 int CMACProgressHelper::ProcessKillFlag(BOOL bSleep
)
63 // process any messages (allows repaint, etc.)
71 while (*m_pKillFlag
== KILL_FLAG_PAUSE
)
73 snooze(50*1000); // SHINTA: Replacement of Windows' SLEEP()
77 if ((*m_pKillFlag
!= KILL_FLAG_CONTINUE
) && (*m_pKillFlag
!= KILL_FLAG_PAUSE
))