Smaller
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1879 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
25459dcb70
commit
53d954e00b
7 changed files with 160 additions and 259 deletions
|
@ -33,7 +33,6 @@ JNL_AsyncDNS::~JNL_AsyncDNS()
|
||||||
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
||||||
{
|
{
|
||||||
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
|
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
|
||||||
int nowinsock=JNL::open_socketlib();
|
|
||||||
struct hostent *hostentry;
|
struct hostent *hostentry;
|
||||||
hostentry=::gethostbyname(_this->m_hostname);
|
hostentry=::gethostbyname(_this->m_hostname);
|
||||||
if (hostentry)
|
if (hostentry)
|
||||||
|
@ -42,7 +41,6 @@ unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_this->m_addr=INADDR_NONE;
|
_this->m_addr=INADDR_NONE;
|
||||||
if (!nowinsock) JNL::close_socketlib();
|
|
||||||
_this->m_thread_kill=1;
|
_this->m_thread_kill=1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,6 @@ JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsi
|
||||||
m_recv_buffer=(char*)malloc(m_recv_buffer_len);
|
m_recv_buffer=(char*)malloc(m_recv_buffer_len);
|
||||||
m_send_buffer=(char*)malloc(m_send_buffer_len);
|
m_send_buffer=(char*)malloc(m_send_buffer_len);
|
||||||
m_socket=-1;
|
m_socket=-1;
|
||||||
memset(m_recv_buffer,0,recvbufsize);
|
|
||||||
memset(m_send_buffer,0,sendbufsize);
|
|
||||||
m_remote_port=0;
|
m_remote_port=0;
|
||||||
m_state=STATE_NOCONNECTION;
|
m_state=STATE_NOCONNECTION;
|
||||||
m_recv_len=m_recv_pos=0;
|
m_recv_len=m_recv_pos=0;
|
||||||
|
|
|
@ -9,53 +9,24 @@
|
||||||
#ifndef _NETINC_H_
|
#ifndef _NETINC_H_
|
||||||
#define _NETINC_H_
|
#define _NETINC_H_
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include "util.h"
|
||||||
#include <time.h>
|
|
||||||
#define strcasecmp(x,y) stricmp(x,y)
|
#define strcasecmp(x,y) stricmp(x,y)
|
||||||
#define ERRNO (WSAGetLastError())
|
#define ERRNO (WSAGetLastError())
|
||||||
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
|
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
|
||||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
#define EINPROGRESS WSAEWOULDBLOCK
|
#define EINPROGRESS WSAEWOULDBLOCK
|
||||||
|
#define memset mini_memset
|
||||||
|
#define memcpy mini_memcpy
|
||||||
|
#define strcpy lstrcpy
|
||||||
|
#define strncpy lstrcpyn
|
||||||
|
#define strcat lstrcat
|
||||||
|
#define strlen lstrlen
|
||||||
|
#define malloc(x) (new char[x])
|
||||||
|
#define free(x) {delete x;}
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#ifndef THREAD_SAFE
|
|
||||||
#define THREAD_SAFE
|
|
||||||
#endif
|
|
||||||
#ifndef _REENTRANT
|
|
||||||
#define _REENTRANT
|
|
||||||
#endif
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define ERRNO errno
|
|
||||||
#define closesocket(s) close(s)
|
|
||||||
#define SET_SOCK_BLOCK(s,block) { int __flags; if ((__flags = fcntl(s, F_GETFL, 0)) != -1) { if (!block) __flags |= O_NONBLOCK; else __flags &= ~O_NONBLOCK; fcntl(s, F_SETFL, __flags); } }
|
|
||||||
|
|
||||||
#define stricmp(x,y) strcasecmp(x,y)
|
|
||||||
#define strnicmp(x,y,z) strncasecmp(x,y,z)
|
|
||||||
#define wsprintf sprintf
|
|
||||||
|
|
||||||
#endif // !_WIN32
|
|
||||||
|
|
||||||
#ifndef INADDR_NONE
|
#ifndef INADDR_NONE
|
||||||
#define INADDR_NONE 0xffffffff
|
#define INADDR_NONE 0xffffffff
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,15 +39,4 @@ typedef int socklen_t;
|
||||||
#define SHUT_RDWR 2
|
#define SHUT_RDWR 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void mini_memset(void *,char,int);
|
|
||||||
extern void mini_memcpy(void *,void*,int);
|
|
||||||
#define memset mini_memset
|
|
||||||
#define memcpy mini_memcpy
|
|
||||||
#define strcpy lstrcpy
|
|
||||||
#define strncpy lstrcpyn
|
|
||||||
#define strcat lstrcat
|
|
||||||
#define strlen lstrlen
|
|
||||||
#define malloc(x) GlobalAlloc(GPTR,(x))
|
|
||||||
#define free(x) { if (x) GlobalFree(x); }
|
|
||||||
|
|
||||||
#endif //_NETINC_H_
|
#endif //_NETINC_H_
|
||||||
|
|
|
@ -48,14 +48,15 @@ HANDLE hModule;
|
||||||
HWND g_parent;
|
HWND g_parent;
|
||||||
HWND g_dialog;
|
HWND g_dialog;
|
||||||
HWND g_childwnd;
|
HWND g_childwnd;
|
||||||
|
HWND g_hwndProgressBar;
|
||||||
static int g_cancelled;
|
static int g_cancelled;
|
||||||
|
|
||||||
BOOL CALLBACK DownloadDialogProc(HWND hwndDlg,
|
BOOL CALLBACK DownloadDialogProc(HWND hwndDlg,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam)
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,37 +64,21 @@ static void *lpWndProcOld;
|
||||||
|
|
||||||
static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL)
|
if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL)
|
||||||
{
|
{
|
||||||
g_cancelled = 1;
|
g_cancelled = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
|
return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL APIENTRY DllMain( HANDLE _hModule,
|
BOOL APIENTRY DllMain( HANDLE _hModule,
|
||||||
DWORD ul_reason_for_call,
|
DWORD ul_reason_for_call,
|
||||||
LPVOID lpReserved
|
LPVOID lpReserved
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
hModule = _hModule;
|
||||||
switch (ul_reason_for_call)
|
return TRUE;
|
||||||
{
|
|
||||||
case DLL_PROCESS_ATTACH:
|
|
||||||
case DLL_THREAD_ATTACH:
|
|
||||||
hModule = _hModule;
|
|
||||||
JNL::open_socketlib ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DLL_THREAD_DETACH:
|
|
||||||
case DLL_PROCESS_DETACH:
|
|
||||||
JNL::close_socketlib ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,75 +88,66 @@ static void progress_callback(char *msg, int read_bytes)
|
||||||
{
|
{
|
||||||
if (g_dialog)
|
if (g_dialog)
|
||||||
{
|
{
|
||||||
HWND hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
|
SetDlgItemText (g_dialog, IDC_STATIC2, msg);
|
||||||
|
if (g_file_size) SendMessage(g_hwndProgressBar, PBM_SETPOS, (WPARAM)MulDiv(read_bytes,30000,g_file_size), 0);
|
||||||
SetDlgItemText (g_dialog, IDC_STATIC2, msg);
|
|
||||||
if (g_file_size) SendMessage(hwndProgressBar, PBM_SETPOS, (WPARAM)MulDiv(read_bytes,30000,g_file_size), 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getProxyInfo(char *out)
|
|
||||||
{
|
|
||||||
DWORD v=0;
|
|
||||||
HKEY hKey;
|
|
||||||
if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
DWORD l = 4;
|
|
||||||
DWORD t;
|
|
||||||
if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD)
|
|
||||||
{
|
|
||||||
l=8192;
|
|
||||||
if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ)
|
|
||||||
{
|
|
||||||
v=0;
|
|
||||||
*out=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else v=0;
|
|
||||||
out[8192-1]=0;
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern char *_strstr(char *i, char *s);
|
extern char *_strstr(char *i, char *s);
|
||||||
#define strstr _strstr
|
#define strstr _strstr
|
||||||
|
|
||||||
static
|
static
|
||||||
void downloadFile(char *url,
|
void downloadFile(char *url,
|
||||||
HANDLE hFile,
|
HANDLE hFile,
|
||||||
char **error)
|
char **error)
|
||||||
{
|
{
|
||||||
static char buf[8192];
|
WSADATA wsaData;
|
||||||
|
WSAStartup(MAKEWORD(1, 1), &wsaData);
|
||||||
|
|
||||||
|
static char buf[8192]="";
|
||||||
char *p=NULL;
|
char *p=NULL;
|
||||||
if (getProxyInfo(buf))
|
|
||||||
|
HKEY hKey;
|
||||||
|
if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
p=strstr(buf,"http=");
|
DWORD l = 4;
|
||||||
if (!p) p=buf;
|
DWORD t;
|
||||||
else {
|
DWORD v;
|
||||||
p+=5;
|
if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v)
|
||||||
|
{
|
||||||
|
l=8192;
|
||||||
|
if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ)
|
||||||
|
{
|
||||||
|
p=strstr(buf,"http=");
|
||||||
|
if (!p) p=buf;
|
||||||
|
else {
|
||||||
|
p+=5;
|
||||||
|
}
|
||||||
|
char *tp=strstr(p,";");
|
||||||
|
if (tp) *tp=0;
|
||||||
|
char *p2=strstr(p,"=");
|
||||||
|
if (p2) p=0; // we found the wrong proxy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
char *tp=strstr(p,";");
|
buf[8192-1]=0;
|
||||||
if (tp) *tp=0;
|
RegCloseKey(hKey);
|
||||||
char *p2=strstr(p,"=");
|
|
||||||
if (p2) p=0; // we found the wrong proxy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD start_time=GetTickCount();
|
DWORD start_time=GetTickCount();
|
||||||
JNL_HTTPGet *get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL);
|
JNL_HTTPGet *get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL);
|
||||||
int st;
|
int st;
|
||||||
int has_printed_headers = 0;
|
int has_printed_headers = 0;
|
||||||
int cl;
|
int cl;
|
||||||
int len;
|
int len;
|
||||||
int sofar = 0;
|
int sofar = 0;
|
||||||
DWORD last_recv_time=start_time;
|
DWORD last_recv_time=start_time;
|
||||||
|
|
||||||
get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)");
|
get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)");
|
||||||
get->addheader ("Accept: */*");
|
get->addheader ("Accept: */*");
|
||||||
|
|
||||||
get->connect (url);
|
get->connect (url);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (g_dialog)
|
if (g_dialog)
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
@ -181,65 +157,64 @@ void downloadFile(char *url,
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sleep(25);
|
Sleep(25);
|
||||||
|
|
||||||
if (g_cancelled) break;
|
if (g_cancelled) break;
|
||||||
|
|
||||||
st = get->run ();
|
st = get->run ();
|
||||||
|
|
||||||
if (st == -1) {
|
if (st == -1) {
|
||||||
*error=get->geterrorstr();
|
*error=get->geterrorstr();
|
||||||
break;
|
break;
|
||||||
} else if (st == 1) {
|
} else if (st == 1) {
|
||||||
if (sofar < cl)
|
if (sofar < cl)
|
||||||
*error="download incomplete";
|
*error="download incomplete";
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (get->get_status () == 0) {
|
if (get->get_status () == 0) {
|
||||||
// progressFunc ("Connecting ...", 0);
|
// progressFunc ("Connecting ...", 0);
|
||||||
if (last_recv_time+g_timeout_ms < GetTickCount())
|
if (last_recv_time+g_timeout_ms < GetTickCount())
|
||||||
{
|
{
|
||||||
*error = "Timed out on connecting.";
|
*error = "Timed out on connecting.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (get->get_status () == 1) {
|
} else if (get->get_status () == 1) {
|
||||||
|
|
||||||
progress_callback("Reading headers", 0);
|
progress_callback("Reading headers", 0);
|
||||||
if (last_recv_time+g_timeout_ms < GetTickCount())
|
if (last_recv_time+g_timeout_ms < GetTickCount())
|
||||||
{
|
{
|
||||||
*error = "Timed out on getting headers.";
|
*error = "Timed out on getting headers.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (get->get_status () == 2) {
|
} else if (get->get_status () == 2) {
|
||||||
|
|
||||||
if (! has_printed_headers) {
|
if (! has_printed_headers) {
|
||||||
has_printed_headers = 1;
|
has_printed_headers = 1;
|
||||||
last_recv_time=GetTickCount();
|
last_recv_time=GetTickCount();
|
||||||
|
|
||||||
cl = get->content_length ();
|
cl = get->content_length ();
|
||||||
if (cl == 0) {
|
if (cl == 0) {
|
||||||
*error = "Server did not specify content length.";
|
*error = "Server did not specify content length.";
|
||||||
break;
|
break;
|
||||||
} else if (g_dialog) {
|
} else if (g_dialog) {
|
||||||
HWND hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
|
SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
|
||||||
SendMessage(hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
|
|
||||||
g_file_size=cl;
|
g_file_size=cl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((len = get->bytes_available ()) > 0) {
|
while ((len = get->bytes_available ()) > 0) {
|
||||||
if (len > 8192)
|
if (len > 8192)
|
||||||
len = 8192;
|
len = 8192;
|
||||||
len = get->get_bytes (buf, len);
|
len = get->get_bytes (buf, len);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
last_recv_time=GetTickCount();
|
last_recv_time=GetTickCount();
|
||||||
DWORD dw;
|
DWORD dw;
|
||||||
WriteFile(hFile,buf,len,&dw,NULL);
|
WriteFile(hFile,buf,len,&dw,NULL);
|
||||||
sofar += len;
|
sofar += len;
|
||||||
int time_sofar=(GetTickCount()-start_time)/1000;
|
int time_sofar=(GetTickCount()-start_time)/1000;
|
||||||
int bps=sofar/(time_sofar?time_sofar:1);
|
int bps=sofar/(time_sofar?time_sofar:1);
|
||||||
int remain=MulDiv(time_sofar,cl,sofar) - time_sofar;
|
int remain=MulDiv(time_sofar,cl,sofar) - time_sofar;
|
||||||
|
@ -254,47 +229,49 @@ void downloadFile(char *url,
|
||||||
rtext="hour";
|
rtext="hour";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wsprintf (buf,
|
wsprintf (buf,
|
||||||
"%dkB (%d%%) of %dkB @ %d.%01dkB/s",
|
"%dkB (%d%%) of %dkB @ %d.%01dkB/s",
|
||||||
sofar/1024,
|
sofar/1024,
|
||||||
MulDiv(100,sofar,cl),
|
MulDiv(100,sofar,cl),
|
||||||
cl/1024,
|
cl/1024,
|
||||||
bps/1024,((bps*10)/1024)%10
|
bps/1024,((bps*10)/1024)%10
|
||||||
);
|
);
|
||||||
if (remain) wsprintf(buf+lstrlen(buf)," (%d %s%s remaining)",
|
if (remain) wsprintf(buf+lstrlen(buf)," (%d %s%s remaining)",
|
||||||
remain,
|
remain,
|
||||||
rtext,
|
rtext,
|
||||||
remain==1?"":"s"
|
remain==1?"":"s"
|
||||||
);
|
);
|
||||||
progress_callback(buf, sofar);
|
progress_callback(buf, sofar);
|
||||||
} else {
|
} else {
|
||||||
if (sofar < cl)
|
if (sofar < cl)
|
||||||
*error = "Server aborted.";
|
*error = "Server aborted.";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GetTickCount() > last_recv_time+g_timeout_ms)
|
if (GetTickCount() > last_recv_time+g_timeout_ms)
|
||||||
{
|
{
|
||||||
*error = "Downloading timed out.";
|
*error = "Downloading timed out.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
*error = "Bad response status.";
|
*error = "Bad response status.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
{
|
{
|
||||||
char *t=*error;
|
char *t=*error;
|
||||||
*error = (char *)GlobalAlloc(GPTR,strlen(t)+1);
|
*error = new char[lstrlen(t)+1];
|
||||||
lstrcpy(*error,t);
|
lstrcpy(*error,t);
|
||||||
}
|
}
|
||||||
delete get;
|
delete get;
|
||||||
|
|
||||||
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT r, cr;
|
RECT r, cr;
|
||||||
|
@ -310,34 +287,34 @@ extern "C"
|
||||||
{
|
{
|
||||||
|
|
||||||
__declspec(dllexport) void download (HWND parent,
|
__declspec(dllexport) void download (HWND parent,
|
||||||
int string_size,
|
int string_size,
|
||||||
char *variables,
|
char *variables,
|
||||||
stack_t **stacktop)
|
stack_t **stacktop)
|
||||||
{
|
{
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
static char url[1024];
|
static char url[1024];
|
||||||
static char filename[1024];
|
static char filename[1024];
|
||||||
int wasen=0;
|
int wasen=0;
|
||||||
HWND hwndL=0;
|
HWND hwndL=0;
|
||||||
HWND hwndB=0;
|
HWND hwndB=0;
|
||||||
|
|
||||||
g_parent = parent;
|
g_parent = parent;
|
||||||
EXDLL_INIT();
|
EXDLL_INIT();
|
||||||
|
|
||||||
popstring(url);
|
popstring(url);
|
||||||
lstrcpyn(buf, url, 10);
|
lstrcpyn(buf, url, 10);
|
||||||
if (!lstrcmp(buf, "/TIMEOUT=")) {
|
if (!lstrcmp(buf, "/TIMEOUT=")) {
|
||||||
g_timeout_ms=my_atoi(url+9);
|
g_timeout_ms=my_atoi(url+9);
|
||||||
popstring(url);
|
popstring(url);
|
||||||
}
|
}
|
||||||
popstring(filename);
|
popstring(filename);
|
||||||
|
|
||||||
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
|
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
|
||||||
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE) {
|
if (hFile == INVALID_HANDLE_VALUE) {
|
||||||
wsprintf (buf, "Unable to open %s", filename);
|
wsprintf (buf, "Unable to open %s", filename);
|
||||||
setuservariable(INST_0, buf);
|
setuservariable(INST_0, buf);
|
||||||
} else {
|
} else {
|
||||||
if (g_parent)
|
if (g_parent)
|
||||||
{
|
{
|
||||||
g_childwnd=FindWindowEx(g_parent,NULL,"#32770",NULL);
|
g_childwnd=FindWindowEx(g_parent,NULL,"#32770",NULL);
|
||||||
|
@ -349,13 +326,13 @@ __declspec(dllexport) void download (HWND parent,
|
||||||
else hwndB=NULL;
|
else hwndB=NULL;
|
||||||
|
|
||||||
wasen=EnableWindow(GetDlgItem(g_parent,IDCANCEL),1);
|
wasen=EnableWindow(GetDlgItem(g_parent,IDCANCEL),1);
|
||||||
lpWndProcOld = (void *) GetWindowLong(g_parent,GWL_WNDPROC);
|
lpWndProcOld = (void *) GetWindowLong(g_parent,GWL_WNDPROC);
|
||||||
SetWindowLong(g_parent,GWL_WNDPROC,(long)ParentWndProc);
|
SetWindowLong(g_parent,GWL_WNDPROC,(long)ParentWndProc);
|
||||||
|
|
||||||
g_dialog = CreateDialog((HINSTANCE)hModule,
|
g_dialog = CreateDialog((HINSTANCE)hModule,
|
||||||
MAKEINTRESOURCE(IDD_DIALOG1),
|
MAKEINTRESOURCE(IDD_DIALOG1),
|
||||||
g_childwnd,
|
g_childwnd,
|
||||||
DownloadDialogProc);
|
DownloadDialogProc);
|
||||||
if (g_dialog)
|
if (g_dialog)
|
||||||
{
|
{
|
||||||
GetWindowRect(g_dialog,&cr);
|
GetWindowRect(g_dialog,&cr);
|
||||||
|
@ -371,18 +348,19 @@ __declspec(dllexport) void download (HWND parent,
|
||||||
char *p=filename;
|
char *p=filename;
|
||||||
while (*p) p++;
|
while (*p) p++;
|
||||||
while (*p != '\\' && p != filename) p=CharPrev(filename,p);
|
while (*p != '\\' && p != filename) p=CharPrev(filename,p);
|
||||||
wsprintf(buf,"Downloading %s", p+1);
|
wsprintf(buf,"Downloading %s", p+1);
|
||||||
SetDlgItemText(g_childwnd,1006,buf);
|
SetDlgItemText(g_childwnd,1006,buf);
|
||||||
|
|
||||||
wsprintf(buf,"Connecting ...");
|
wsprintf(buf,"Connecting ...");
|
||||||
SetDlgItemText (g_dialog, IDC_STATIC2, buf);
|
SetDlgItemText (g_dialog, IDC_STATIC2, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
|
||||||
|
|
||||||
char *error=NULL;
|
char *error=NULL;
|
||||||
|
|
||||||
downloadFile(url, hFile, &error);
|
downloadFile(url, hFile, &error);
|
||||||
|
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
if (g_parent)
|
if (g_parent)
|
||||||
|
@ -398,29 +376,28 @@ __declspec(dllexport) void download (HWND parent,
|
||||||
if (wasen) EnableWindow(GetDlgItem(g_parent,IDCANCEL),0);
|
if (wasen) EnableWindow(GetDlgItem(g_parent,IDCANCEL),0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (g_cancelled) {
|
if (g_cancelled) {
|
||||||
setuservariable(INST_0, "cancel");
|
setuservariable(INST_0, "cancel");
|
||||||
DeleteFile(filename);
|
DeleteFile(filename);
|
||||||
} else if (error == NULL) {
|
} else if (error == NULL) {
|
||||||
setuservariable(INST_0, "success");
|
setuservariable(INST_0, "success");
|
||||||
} else {
|
} else {
|
||||||
DeleteFile(filename);
|
DeleteFile(filename);
|
||||||
setuservariable(INST_0, error);
|
setuservariable(INST_0, error);
|
||||||
}
|
}
|
||||||
if (error) GlobalFree(error);
|
if (error) GlobalFree(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__declspec(dllexport) void download_quiet(HWND parent,
|
__declspec(dllexport) void download_quiet(HWND parent,
|
||||||
int stringsize,
|
int stringsize,
|
||||||
char *variables,
|
char *variables,
|
||||||
stack_t **stacktop)
|
stack_t **stacktop)
|
||||||
{
|
{
|
||||||
|
g_hwndProgressBar=0;
|
||||||
download(NULL,stringsize,variables,stacktop);
|
download(NULL,stringsize,variables,stacktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} //extern "C"
|
||||||
|
|
||||||
|
|
|
@ -10,31 +10,6 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int JNL::open_socketlib()
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
WSADATA wsaData;
|
|
||||||
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) return 1;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
void JNL::close_socketlib()
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
WSACleanup();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
unsigned long JNL::ipstr_to_addr(const char *cp)
|
|
||||||
{
|
|
||||||
return ::inet_addr(cp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen)
|
|
||||||
{
|
|
||||||
struct in_addr a; a.s_addr=addr;
|
|
||||||
char *p=::inet_ntoa(a); strncpy(host,p?p:"",maxhostlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
int my_atoi(char *s)
|
int my_atoi(char *s)
|
||||||
{
|
{
|
||||||
int sign=0;
|
int sign=0;
|
||||||
|
|
|
@ -27,15 +27,8 @@
|
||||||
#ifndef _UTIL_H_
|
#ifndef _UTIL_H_
|
||||||
#define _UTIL_H_
|
#define _UTIL_H_
|
||||||
|
|
||||||
class JNL
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static int open_socketlib();
|
|
||||||
static void close_socketlib();
|
|
||||||
static unsigned long ipstr_to_addr(const char *cp);
|
|
||||||
static void addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
|
|
||||||
};
|
|
||||||
|
|
||||||
int my_atoi(char *p);
|
int my_atoi(char *p);
|
||||||
|
void mini_memset(void *,char,int);
|
||||||
|
void mini_memcpy(void *,void*,int);
|
||||||
|
|
||||||
#endif //_UTIL_H_
|
#endif //_UTIL_H_
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue