From 71254ce61cbfd611cee75e3e3bb9485556691523 Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 16 Sep 2005 16:05:12 +0000 Subject: [PATCH] better and uniform rounding of required/available size display git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4266 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/exehead/Ui.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index c55f71e2..b3f8f933 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -782,20 +782,17 @@ static BOOL CALLBACK UninstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l #endif -static void NSISCALL SetSizeText(int dlgItem, int prefix, unsigned kb, BOOL roundDown) +static void NSISCALL SetSizeText(int dlgItem, int prefix, unsigned kb) { char scalestr[32], byte[32]; - unsigned sh=20; - int scale=LANG_GIGA; + unsigned sh = 20; + int scale = LANG_GIGA; - if (kb < 1024*1024) { sh=10; scale=LANG_MEGA; } - if (kb < 1024) { sh=0; scale=LANG_KILO; } + if (kb < 1024 * 1024) { sh = 10; scale = LANG_MEGA; } + if (kb < 1024) { sh = 0; scale = LANG_KILO; } - if (!roundDown) - // this will not overflow because currently, installers - // can't contain over 2GB of data and this is not used - // for the available size, but only required size - kb += (1 << sh) / 10; // round up number after decimal point + if (kb < (0xFFFFFFFF - ((1 << 20) / 20))) // check for overflow + kb += (1 << sh) / 20; // round numbers for better display (e.g. 1.59 => 1.6) wsprintf( GetNSISString(g_tmp, prefix) + mystrlen(g_tmp), @@ -971,9 +968,9 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar error = NSIS_INSTDIR_NOT_ENOUGH_SPACE; if (LANG_STR_TAB(LANG_SPACE_REQ)) { - SetSizeText(IDC_SPACEREQUIRED,LANG_SPACE_REQ,total,FALSE); + SetSizeText(IDC_SPACEREQUIRED,LANG_SPACE_REQ,total); if (available_set) - SetSizeText(IDC_SPACEAVAILABLE,LANG_SPACE_AVAIL,available,TRUE); + SetSizeText(IDC_SPACEAVAILABLE,LANG_SPACE_AVAIL,available); else SetUITextNT(IDC_SPACEAVAILABLE,""); } @@ -1366,7 +1363,7 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar RefreshComponents(hwndTree1, hTreeItems); if (LANG_STR_TAB(LANG_SPACE_REQ)) { - SetSizeText(IDC_SPACEREQUIRED,LANG_SPACE_REQ,sumsecsfield(size_kb),FALSE); + SetSizeText(IDC_SPACEREQUIRED,LANG_SPACE_REQ,sumsecsfield(size_kb)); } }