diff --git a/idp/downloader.cpp b/idp/downloader.cpp index f326a69..a7d041e 100644 --- a/idp/downloader.cpp +++ b/idp/downloader.cpp @@ -685,8 +685,8 @@ void Downloader::updateSpeed(NetFile *file, Timer *timer) { if(ui) { - double speed = (double)file->bytesDownloaded / ((double)timer->totalElapsed() / 1000.0); - double rtime = (double)(filesSize - (downloadedFilesSize + file->bytesDownloaded)) / speed * 1000.0; + double speed = (double)file->bytesDownloaded / nonzero((double)timer->totalElapsed() / 1000.0); + double rtime = (double)(filesSize - (downloadedFilesSize + file->bytesDownloaded)) / nonzero(speed) * 1000.0; if((filesSize == FILE_SIZE_UNKNOWN) || ((downloadedFilesSize + file->bytesDownloaded) > filesSize)) ui->setSpeedInfo(f2i(speed)); diff --git a/idp/ui.cpp b/idp/ui.cpp index 9f338dd..1aefb97 100644 --- a/idp/ui.cpp +++ b/idp/ui.cpp @@ -79,13 +79,13 @@ void Ui::setProgressInfo(DWORDLONG totalSize, DWORDLONG totalDownloaded, DWORDLO { if(!(totalSize == FILE_SIZE_UNKNOWN)) { - double totalPercents = 100.0 / ((double)totalSize / (double)totalDownloaded); + double totalPercents = 100.0 / nonzero((double)totalSize / i2d(totalDownloaded)); setProgressBarPos(controls["TotalProgressBar"], f2i(totalPercents)); } if(!(fileSize == FILE_SIZE_UNKNOWN)) { - double filePercents = 100.0 / ((double)fileSize / (double)fileDownloaded); + double filePercents = 100.0 / nonzero((double)fileSize / i2d(fileDownloaded)); setProgressBarPos(controls["FileProgressBar"], f2i(filePercents)); } } diff --git a/idp/ui.h b/idp/ui.h index 00e9001..ad29c2f 100644 --- a/idp/ui.h +++ b/idp/ui.h @@ -61,5 +61,7 @@ class Ui HWND uiMainWindow(); #define f2i(x) (_isnan(x) ? 0 : (int)(x)) +#define i2d(x) ((x == 0) ? FLT_MIN : (double)x) +#define nonzero(x) ((x == 0.0) ? FLT_MIN : (double)x) extern "C" void idpReportError();