// This routine will update the File Gauge progress bar to the specified percentage // (value between 0 and 100) static void UpdateGaugeFileProgressBar(double value) { int nBars; static long lModLastValue = 0; if(sgProduct.mode != SILENT) { if(!CheckInterval(&lModLastValue, UPDATE_INTERVAL_PROGRESS_BAR)) return; // Figure out how many bars should be displayed nBars = (int)(dlgInfo.nMaxFileBars * value / 100); // Only paint if we need to display more bars if((nBars > dlgInfo.nFileBars) || (dlgInfo.nFileBars == 0)) { HWND hWndGauge = GetDlgItem(dlgInfo.hWndDlg, IDC_PROGRESS_FILE); RECT rect; // Update the gauge state before painting dlgInfo.nFileBars = nBars; // Only invalidate the part that needs updating GetClientRect(hWndGauge, &rect); InvalidateRect(hWndGauge, &rect, FALSE); // Update the whole extracting dialog. We do this because we don't // have a message loop to process WM_PAINT messages in case the // extracting dialog was exposed UpdateWindow(dlgInfo.hWndDlg); } } }
// // Check rate limit // bool RateLimit::SetLimit(const STLW::string & sKey, const W_FLOAT dPerSecond, const W_FLOAT dBurst, const UINT_32 iEvents) { bool bCheckResult = true; for (;;) { W_FLOAT dATime = 0.0; W_FLOAT dBucket = 0.0; UINT_64 iUnique = pStorage -> Get(sKey, dATime, dBucket); if (iUnique == 0) { dATime = 0; dBucket = 1; } bCheckResult = CheckInterval(dPerSecond, dBurst, dATime, dBucket, iEvents); if (pStorage -> Set(sKey, dATime, dBucket, iUnique)) { break; } } return bCheckResult; }
void SetStatusStatus(void) { char szStatusStatusLine[MAX_BUF_MEDIUM]; char szCurrentStatusInfo[MAX_BUF_MEDIUM]; char szPercentString[MAX_BUF_MEDIUM]; char szPercentageCompleted[MAX_BUF_MEDIUM]; static long lModLastValue = 0; double dRate; static double dRateCounter; DWORD dwTickNow; DWORD dwTickDif; DWORD dwKBytesSoFar; DWORD dwRoundedRate; char szTimeLeft[MAX_BUF_TINY]; /* If the user just clicked on the Resume button, then the time lapsed * between gdwTickStart and when the Resume button was clicked needs to * be subtracted taken into account when calculating dwTickDif. So * "this" lapsed time needs to be added to gdwTickStart. */ if(gtiPaused.bTickDownloadResumed) { gdwTickStart = AddToTick(gdwTickStart, gtiPaused.dwTickDif); InitTickInfo(); } /* GetTickCount() returns time in milliseconds. This is more accurate, * which will allow us to get at a 2 decimal precision value for the * download rate. */ dwTickNow = GetTickCount(); if((gdwTickStart == 0) && gbStartTickCounter) dwTickNow = gdwTickStart = GetTickCount(); dwTickDif = GetTickDif(dwTickNow, gdwTickStart); /* Only update the UI every UPDATE_INTERVAL_STATUS interval, * which is currently set to 1 sec. */ if(!CheckInterval(&lModLastValue, UPDATE_INTERVAL_STATUS)) return; if(glAbsoluteBytesSoFar == 0) dRateCounter = 0.0; else dRateCounter = dwTickDif / 1000; if(dRateCounter == 0.0) dRate = 0.0; else dRate = (glAbsoluteBytesSoFar - glBytesResumedFrom) / dRateCounter / 1024; dwKBytesSoFar = glAbsoluteBytesSoFar / 1024; /* Use a rate that is rounded to the nearest integer. If dRate used directly, * the "Time Left" will jump around quite a bit due to the rate usually * varying up and down by quite a bit. The rounded rate give a "more linear" * count down of the "Time Left". */ dwRoundedRate = RoundDouble(dRate); if(dwRoundedRate > 0) GetTimeLeft((glTotalKb - dwKBytesSoFar) / dwRoundedRate, szTimeLeft, sizeof(szTimeLeft)); else lstrcpy(szTimeLeft, "00:00:00"); if(!gbShowDownloadRetryMsg) { GetConfigIniProfileString("Strings", "Status Download", "", szStatusStatusLine, sizeof(szStatusStatusLine)); if(*szStatusStatusLine != '\0') sprintf(szCurrentStatusInfo, szStatusStatusLine, szTimeLeft, dRate, dwKBytesSoFar, glTotalKb); else sprintf(szCurrentStatusInfo, "%s at %.2fKB/sec (%uKB of %uKB downloaded)", szTimeLeft, dRate, dwKBytesSoFar, glTotalKb); } else { GetConfigIniProfileString("Strings", "Status Retry", "", szStatusStatusLine, sizeof(szStatusStatusLine)); if(*szStatusStatusLine != '\0') sprintf(szCurrentStatusInfo, szStatusStatusLine, szTimeLeft, dRate, dwKBytesSoFar, glTotalKb); else sprintf(szCurrentStatusInfo, "%s at %.2KB/sec (%uKB of %uKB downloaded)", szTimeLeft, dRate, dwKBytesSoFar, glTotalKb); } GetConfigIniProfileString("Strings", "Status Percentage Completed", "", szPercentageCompleted, sizeof(szPercentageCompleted)); wsprintf(szPercentString, szPercentageCompleted, (int)GetPercentSoFar()); /* Set the download dialog title */ SetDlgItemText(dlgInfo.hWndDlg, IDC_STATUS_STATUS, szCurrentStatusInfo); SetDlgItemText(dlgInfo.hWndDlg, IDC_PERCENTAGE, szPercentString); }