- Fixed potential crash caused by WinSock being shutdown while the connection is still open.

- Cleaned up dialog creation a little (some details, such as font, were being changed after the dialog was already visible).
- Restores focus to its previous state when exiting.
- Fixed another one of those "holding down Cancel at the wrong moment can cause the installer to suddenly exit" problems.


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3443 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
eccles 2004-02-01 15:50:00 +00:00
parent 438365532e
commit 38d9a9aa37
3 changed files with 72 additions and 70 deletions

View file

@ -27,7 +27,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
IDD_DIALOG1 DIALOGEX 0, 0, 265, 104
STYLE DS_CONTROL | WS_CHILD
STYLE WS_CHILD
EXSTYLE WS_EX_NOPARENTNOTIFY
FONT 8, "MS Sans Serif"
BEGIN

View file

@ -111,10 +111,7 @@ static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LP
LRESULT Res = 0;
while ( !TryEnterCS() ) Sleep(0);
if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL)
{
SendMessage(GetDlgItem(hwnd, IDCANCEL), BM_SETSTATE, FALSE, 0);
g_cancelled = 1;
}
else
Res = CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
LeaveCS();
@ -164,7 +161,6 @@ __declspec(dllexport) void download (HWND parent,
char buf[1024];
char url[1024];
char filename[1024];
int wasen=0;
HWND hwndAux;
HWND hwndL=0;
HWND hwndB=0;
@ -174,8 +170,6 @@ __declspec(dllexport) void download (HWND parent,
RECT r, cr, orig_childRc;
int timeout_ms=30000;
JNL_HTTPGet *get = 0;
char *error=NULL;
static char szDownloading[1024];//= "Downloading %s";
@ -220,10 +214,16 @@ __declspec(dllexport) void download (HWND parent,
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
if (hFile == INVALID_HANDLE_VALUE) {
wsprintf (buf, "Unable to open %s", filename);
error=buf;
} else {
if (hFile == INVALID_HANDLE_VALUE)
{
wsprintf(buf, "Unable to open %s", filename);
error = buf;
}
else
{
HWND hwndPrevFocus;
BOOL fCancelDisabled;
if (parent)
{
childwnd=FindWindowEx(parent,NULL,"#32770",NULL);
@ -251,10 +251,10 @@ __declspec(dllexport) void download (HWND parent,
HWND pb = g_hwndProgressBar = GetDlgItem(dlg, pbid);
long c;
if (hwPb)
{
long c;
c = SendMessage(hwPb, PBM_SETBARCOLOR, 0, 0);
SendMessage(hwPb, PBM_SETBARCOLOR, 0, c);
SendMessage(pb, PBM_SETBARCOLOR, 0, c);
@ -264,7 +264,7 @@ __declspec(dllexport) void download (HWND parent,
SendMessage(pb, PBM_SETBKCOLOR, 0, c);
}
ShowWindow(pb, SW_SHOW);
ShowWindow(pb, SW_SHOWNA);
GetWindowRect(childwnd,&orig_childRc);
GetWindowRect(dlg,&cr);
@ -280,7 +280,7 @@ __declspec(dllexport) void download (HWND parent,
GetWindowRect(hwndAux,&r);
ScreenToClient(parent,(LPPOINT)&r);
ScreenToClient(parent,((LPPOINT)&r)+1);
SetWindowPos(dlg,0,r.left,r.top,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);
SetWindowPos(dlg,0,r.left,r.top,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOZORDER);
hwndAux = GetDlgItem(dlg,IDC_STATIC2);
GetWindowRect(hwndAux,&cr);
@ -305,16 +305,21 @@ __declspec(dllexport) void download (HWND parent,
long hFont = SendMessage(parent, WM_GETFONT, 0, 0);
SendDlgItemMessage(dlg, pbid, WM_SETFONT, hFont, 0);
SendDlgItemMessage(dlg, IDC_STATIC2, WM_SETFONT, hFont, 0);
ShowWindow(dlg, SW_SHOWNA);
}
// enable the cancel button
wasen=EnableWindow(GetDlgItem(parent,IDCANCEL),TRUE);
SendMessage(parent, WM_NEXTDLGCTL, (WPARAM) GetDlgItem(parent, IDCANCEL), TRUE);
hwndPrevFocus = GetFocus();
fCancelDisabled = EnableWindow(GetDlgItem(parent, IDCANCEL), TRUE);
SendMessage(parent, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(parent, IDCANCEL), TRUE);
}
{
WSADATA wsaData;
WSAStartup(MAKEWORD(1, 1), &wsaData);
JNL_HTTPGet *get = 0;
static char main_buf[8192];
char *buf=main_buf;
char *p=NULL;
@ -373,11 +378,17 @@ __declspec(dllexport) void download (HWND parent,
}
}
while (!TryEnterCS()); // Process messages
if ((g_cancelled || error) && dlg)
DestroyWindow(dlg);
if (g_cancelled || error)
{
if (dlg)
DestroyWindow(dlg);
dlg = NULL;
if (!error)
error = "cancel";
}
LeaveCS();
if ( g_cancelled || error )
if (error)
{
if (parent)
{
@ -393,11 +404,14 @@ __declspec(dllexport) void download (HWND parent,
SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE
);
if (wasen)
// Prevent wierd stuff happening if the cancel button happens to be
// pressed at the moment we are finishing
SendMessage(GetDlgItem(parent, IDCANCEL), BM_SETSTATE, FALSE, 0);
// Restore the previous focus and cancel button states
SendMessage(parent, WM_NEXTDLGCTL, (WPARAM)hwndPrevFocus, TRUE);
if (fCancelDisabled)
EnableWindow(GetDlgItem(parent, IDCANCEL), FALSE);
}
if ( !error )
error = "cancel";
break;
}
@ -406,8 +420,8 @@ __declspec(dllexport) void download (HWND parent,
st = get->run ();
if (st == -1) {
error=get->geterrorstr();
//break;
lstrcpyn(url, get->geterrorstr(), sizeof(url));
error = url;
} else if (st == 1) {
if (sofar < cl)
error="download incomplete";
@ -416,25 +430,18 @@ __declspec(dllexport) void download (HWND parent,
bSuccess=TRUE;
error = "success";
}
//break;
} else {
if (get->get_status () == 0) {
// progressFunc ("Connecting ...", 0);
if (last_recv_time+timeout_ms < GetTickCount())
{
error = "Timed out on connecting.";
//break;
}
} else if (get->get_status () == 1) {
progress_callback(dlg, "Reading headers", 0);
if (last_recv_time+timeout_ms < GetTickCount())
{
error = "Timed out on getting headers.";
//break;
}
} else if (get->get_status () == 2) {
@ -443,12 +450,11 @@ __declspec(dllexport) void download (HWND parent,
last_recv_time=GetTickCount();
cl = get->content_length ();
if (cl == 0) {
if (cl == 0)
error = "Server did not specify content length.";
//break;
} else if (dlg) {
SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
g_file_size=cl;
else if (dlg) {
SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
g_file_size=cl;
}
}
@ -491,14 +497,10 @@ __declspec(dllexport) void download (HWND parent,
} else {
if (sofar < cl)
error = "Server aborted.";
//break;
}
}
if (GetTickCount() > last_recv_time+timeout_ms)
{
error = "Downloading timed out.";
//break;
}
} else {
error = "Bad response status.";
@ -507,6 +509,8 @@ __declspec(dllexport) void download (HWND parent,
}
// Clean up the connection then release winsock
if (get) delete get;
WSACleanup();
}
@ -518,8 +522,6 @@ __declspec(dllexport) void download (HWND parent,
}
pushstring(error);
if (get) delete get;
}

Binary file not shown.