From ca9582c925cbb05fc6a180a784bcdcb537fda88e Mon Sep 17 00:00:00 2001 From: eccles Date: Sat, 6 Mar 2004 12:31:26 +0000 Subject: [PATCH] Windows 95 (OSR2)/98/ME no longer see drive free space capped to 2GB. git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3507 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/exehead/Ui.c | 57 ++++++++++++++++++++++++++---------------- Source/exehead/exec.c | 11 ++++---- Source/exehead/lang.h | 12 ++++----- Source/exehead/util.c | 9 ++++--- Source/zlib/INFBLOCK.C | 4 +-- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index d280733e..9267735b 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -97,9 +97,9 @@ static void NSISCALL EnableNext(BOOL e) EnableWindow(m_hwndOK, e); } -static void NSISCALL SetActiveCtl(HWND hDlg, HWND hCtl) +static void NSISCALL SetActiveCtl(HWND hCtl) { - SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM) hCtl, TRUE); + SendMessage(g_hwnd, WM_NEXTDLGCTL, (WPARAM) hCtl, TRUE); } static void NSISCALL NotifyCurWnd(UINT uNotifyCode) @@ -276,19 +276,20 @@ __forceinline int NSISCALL ui_doinstall(void) #ifdef NSIS_SUPPORT_BGBG if (header->bg_color1 != -1) { + DWORD cn = CHAR4_TO_DWORD('_', 'N', 'b', 0); RECT vp; extern LRESULT CALLBACK BG_WndProc(HWND, UINT, WPARAM, LPARAM); wc.lpfnWndProc = BG_WndProc; wc.hInstance = g_hInstance; wc.hIcon = g_hIcon; //wc.hCursor = LoadCursor(NULL,IDC_ARROW); - wc.lpszClassName = "_Nb"; + wc.lpszClassName = (LPCSTR)&cn; if (!RegisterClass(&wc)) return 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); - m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,"_Nb",0,WS_POPUP, + m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCSTR)&cn,0,WS_POPUP, vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL); } @@ -491,11 +492,11 @@ nextPage: if (g_exec_flags.abort) { SendMessage(hwndDlg, DM_SETDEFID, IDCANCEL, 0); - SetActiveCtl(hwndDlg, m_hwndCancel); + SetActiveCtl(m_hwndCancel); } else { - SetActiveCtl(hwndDlg, m_hwndOK); + SetActiveCtl(m_hwndOK); } mystrcpy(g_tmp,g_caption); @@ -677,7 +678,7 @@ static BOOL CALLBACK LicenseProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM EnableNext(selected); hwLicense=GetUIItem(IDC_EDIT1); - SetActiveCtl(hwndDlg, hwLicense); + SetActiveCtl(hwLicense); SendMessage(hwLicense,EM_AUTOURLDETECT,TRUE,0); #define lbg g_header->license_bg SendMessage(hwLicense,EM_SETBKGNDCOLOR,0,lbg>=0?lbg:GetSysColor(-lbg)); @@ -768,19 +769,16 @@ static char * NSISCALL inttosizestr(int kb, char *str) { char scalestr[32], byte[32]; char sh=20; - char s=0; int scale=LANG_GIGA; if (kb < 1024) { sh=0; scale=LANG_KILO; } else if (kb < 1024*1024) { sh=10; scale=LANG_MEGA; } - else if (GetVersion()&0x80000000) s='+';//only display the + on GB shown on win9x. wsprintf( str+mystrlen(str), - "%d.%d%s%s%c", + "%d.%d%s%s", kb>>sh, ((kb*10)>>sh)%10, GetNSISString(scalestr,scale), - GetNSISString(byte,LANG_BYTE), - s + GetNSISString(byte,LANG_BYTE) ); return str; } @@ -833,7 +831,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar SetUITextNT(IDC_DIR,dir); SetUITextFromLang(IDC_BROWSE,this_page->parms[2]); SetUITextFromLang(IDC_SELDIRTEXT,this_page->parms[1]); - SetActiveCtl(hwndDlg, GetUIItem(IDC_DIR)); + SetActiveCtl(GetUIItem(IDC_DIR)); } if (uMsg == WM_COMMAND) { @@ -880,7 +878,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar char *p; int error = 0; int total, available=-1; - DWORD spc,bps,fc,tc; + HMODULE hLib; GetUIText(IDC_DIR,dir); if (!is_valid_instpath(dir)) @@ -891,11 +889,27 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (p) *p=0; - if (GetDiskFreeSpace(s,&spc,&bps,&fc,&tc)) + // Test for and use the GetDiskFreeSpaceEx API + hLib = GetModuleHandle("KERNEL32.dll"); + if (hLib) { - DWORD r=MulDiv(bps*spc,fc,1<<10); - if (r > 0x7fffffff) r=0x7fffffff; - available=(int)r; + BOOL (WINAPI *GDFSE)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER) = + (void*)GetProcAddress(hLib, "GetDiskFreeSpaceExA"); + if (GDFSE) + { + ULARGE_INTEGER available64; + if (GDFSE(s, &available64, NULL, NULL)) + available = (int)(available64.QuadPart >> 10); + } + + } + + if (available == -1) + { + // GetDiskFreeSpaceEx is not available + DWORD spc, bps, fc, tc; + if (GetDiskFreeSpace(s, &spc, &bps, &fc, &tc)) + available = (int)MulDiv(bps * spc, fc, 1 << 10); } total = sumsecsfield(size_kb); @@ -905,7 +919,8 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (LANG_STR_TAB(LANG_SPACE_REQ)) { SetUITextNT(IDC_SPACEREQUIRED,inttosizestr(total,GetNSISString(s,LANG_SPACE_REQ))); - if (available != -1) + // Did we get a usable value above? + if (available >= 0) SetUITextNT(IDC_SPACEAVAILABLE,inttosizestr(available,GetNSISString(s,LANG_SPACE_AVAIL))); else SetUITextNT(IDC_SPACEAVAILABLE,""); @@ -1204,10 +1219,10 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (!noCombo) { ShowWindow(hwndCombo1, SW_SHOW); - SetActiveCtl(hwndDlg, hwndCombo1); + SetActiveCtl(hwndCombo1); } else - SetActiveCtl(hwndDlg, hwndTree1); + SetActiveCtl(hwndTree1); uMsg = g_exec_flags.insttype_changed ? WM_NOTIFY_INSTTYPE_CHANGE : WM_IN_UPDATEMSG; } diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index f8c5aa4b..5348fb7a 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -1068,7 +1068,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) } g_exec_flags.exec_error++; { - HANDLE h=LoadLibrary("advapi32.dll"); + HANDLE h=LoadLibrary("ADVAPI32.dll"); if (h) { BOOL (WINAPI *OPT)(HANDLE, DWORD,PHANDLE); @@ -1089,6 +1089,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) ATP(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); } } + FreeLibrary(h); } if (ExitWindowsEx(EWX_REBOOT,0)) @@ -1097,8 +1098,6 @@ static int NSISCALL ExecuteEntry(entry *entry_) PostQuitMessage(0); return EXEC_ERROR; } - - FreeLibrary(h); } break; #endif//NSIS_SUPPORT_REBOOT @@ -1129,13 +1128,13 @@ static int NSISCALL ExecuteEntry(entry *entry_) break; case EW_READINISTR: { - const char *errstr="!N~"; + DWORD errstr = CHAR4_TO_DWORD('!', 'N', '~', 0); char *p=var0; char *buf0=GetStringFromParm(0x01); char *buf1=GetStringFromParm(0x12); char *buf2=GetStringFromParm(-0x23); - GetPrivateProfileString(buf0,buf1,errstr,p,NSIS_MAX_STRLEN-1,buf2); - if (*((int*)errstr) == *((int*)p)) + GetPrivateProfileString(buf0,buf1,(LPCSTR)&errstr,p,NSIS_MAX_STRLEN-1,buf2); + if (*(DWORD*)p == errstr) { exec_error++; p[0]=0; diff --git a/Source/exehead/lang.h b/Source/exehead/lang.h index 943d0e90..c9b7e058 100644 --- a/Source/exehead/lang.h +++ b/Source/exehead/lang.h @@ -4,14 +4,14 @@ // generic startup strings (these will never be overridable) #ifdef NSIS_CONFIG_CRC_SUPPORT -#define _LANG_INVALIDCRC "The installer you are trying to use is corrupted or incomplete.\r\n" \ - "This could be the result of a damaged disk, a failed download or a virus.\r\n\r\n" \ - "You may want to contact the author of this installer to obtain a new copy.\r\n\r\n" \ - "It may be possible to skip this check using the /NCRC command line switch\r\n" \ +#define _LANG_INVALIDCRC "The installer you are trying to use is corrupted or incomplete.\n" \ + "This could be the result of a damaged disk, a failed download or a virus.\n\n" \ + "You may want to contact the author of this installer to obtain a new copy.\n\n" \ + "It may be possible to skip this check using the /NCRC command line switch\n" \ "(NOT RECOMMENDED)." #else -#define _LANG_INVALIDCRC "The installer you are trying to use is corrupted or incomplete.\r\n" \ - "This could be the result of a damaged disk, a failed download or a virus.\r\n\r\n" \ +#define _LANG_INVALIDCRC "The installer you are trying to use is corrupted or incomplete.\n" \ + "This could be the result of a damaged disk, a failed download or a virus.\n\n" \ "You may want to contact the author of this installer to obtain a new copy." #endif diff --git a/Source/exehead/util.c b/Source/exehead/util.c index c9cdea5a..e1eade7c 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -61,13 +61,14 @@ HANDLE NSISCALL myCreateProcess(char *cmd, char *dir) BOOL NSISCALL my_SetDialogItemText(HWND dlg, UINT idx, const char *val) { return SetDlgItemText(dlg,idx,val); - //return my_SetWindowText(GetDlgItem(dlg,idx),val); +// return my_SetWindowText(GetDlgItem(dlg, idx), val); } int NSISCALL my_GetDialogItemText(UINT idx, char *val) { extern HWND m_curwnd; return GetDlgItemText(m_curwnd, idx, val, NSIS_MAX_STRLEN); +// return my_GetWindowText(GetDlgItem(m_curwnd, idx), val, NSIS_MAX_STRLEN); } int NSISCALL my_MessageBox(const char *text, UINT type) { @@ -188,7 +189,7 @@ int NSISCALL is_valid_instpath(char *s) { static char tmp[NSIS_MAX_STRLEN]; char *root; - + mystrcpy(tmp, s); root = skip_root(tmp); @@ -280,7 +281,7 @@ char * NSISCALL my_GetTempFileName(char *buf, const char *dir) void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) { BOOL fOk = 0; - HMODULE hLib=GetModuleHandle("kernel32.dll"); + HMODULE hLib=GetModuleHandle("KERNEL32.dll"); if (hLib) { typedef BOOL (WINAPI *mfea_t)(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,DWORD dwFlags); @@ -304,7 +305,7 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) int spn; - *((int *)tmpbuf) = *((int *)"NUL"); + *(DWORD*)tmpbuf = CHAR4_TO_DWORD('N', 'U', 'L', 0); if (pszNew) { // create the file if it's not already there to prevent GetShortPathName from failing diff --git a/Source/zlib/INFBLOCK.C b/Source/zlib/INFBLOCK.C index ca6896a0..e7cdd9cb 100644 --- a/Source/zlib/INFBLOCK.C +++ b/Source/zlib/INFBLOCK.C @@ -367,7 +367,7 @@ int inflate(z_streamp z) static uIntf c[288]; /* length list for huft_build */ /* literal table */ - for (_k = 0; _k < 288; _k++) + for (_k = 0; _k < 288; _k++) { char v=8; if (_k > 143) @@ -491,7 +491,7 @@ int inflate(z_streamp z) if (c == 18) { i=7; - j=11; + j=11; } else {