Timeout now works
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1302 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
89c7fa3204
commit
dfbd9e93c0
2 changed files with 201 additions and 202 deletions
|
@ -28,24 +28,18 @@ freely, subject to the following restrictions:
|
|||
#ifndef false
|
||||
#define false FALSE
|
||||
#endif
|
||||
#define TIMEOUT 15000
|
||||
#define NOLOG_TIMEOUT 600000
|
||||
#define LOOPTIMEOUT 100
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
HWND g_hwndParent;
|
||||
HWND g_hwndList;
|
||||
HWND g_hwndDlg;
|
||||
char * g_exec;
|
||||
char * g_szto;
|
||||
BOOL g_foundto;
|
||||
int g_to;
|
||||
unsigned int g_to;
|
||||
|
||||
|
||||
void ExecScript(BOOL log);
|
||||
void LogMessage(const char *pStr);
|
||||
char *my_strstr(const char *string, const char *strCharSet);
|
||||
int my_atoi(char *s);
|
||||
unsigned int my_atoi(char *s);
|
||||
|
||||
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
|
@ -64,34 +58,24 @@ void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *var
|
|||
}
|
||||
|
||||
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||
g_hInstance=hInst;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ExecScript(BOOL log) {
|
||||
g_to = INFINITE;
|
||||
g_foundto = FALSE;
|
||||
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
||||
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
||||
g_to = 0; // default is no timeout
|
||||
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
||||
g_szto = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
||||
if (!popstring(g_szto)) {
|
||||
if (my_strstr(g_szto,"/TIMEOUT=")) {
|
||||
g_szto += 9;
|
||||
g_to = my_atoi(g_szto);
|
||||
if (g_to<0) g_to = log?TIMEOUT:NOLOG_TIMEOUT;
|
||||
g_foundto = TRUE;
|
||||
if (!popstring(g_exec)) {
|
||||
if (my_strstr(g_exec,"/TIMEOUT=")) {
|
||||
char *szTimeout = g_exec + 9;
|
||||
g_to = my_atoi(szTimeout);
|
||||
popstring(g_exec);
|
||||
}
|
||||
}
|
||||
if (g_foundto) {
|
||||
if (popstring(g_exec)) {
|
||||
if (!g_exec[0]) {
|
||||
pushstring("error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lstrcpy(g_exec,g_szto);
|
||||
}
|
||||
{
|
||||
STARTUPINFO si={sizeof(si),};
|
||||
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
||||
|
@ -101,10 +85,11 @@ void ExecScript(BOOL log) {
|
|||
HANDLE newstdout=0,read_stdout=0;
|
||||
DWORD dwRead = 1;
|
||||
DWORD dwExit = !STILL_ACTIVE;
|
||||
DWORD dwLastOutput;
|
||||
static char szBuf[1024];
|
||||
static char szRet[128];
|
||||
char szRet[128] = "";
|
||||
HGLOBAL hUnusedBuf;
|
||||
static char *szUnusedBuf;
|
||||
char *szUnusedBuf = 0;
|
||||
|
||||
if (log) {
|
||||
hUnusedBuf = GlobalAlloc(GHND, sizeof(szBuf)*4);
|
||||
|
@ -113,6 +98,7 @@ void ExecScript(BOOL log) {
|
|||
return;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
}
|
||||
|
||||
GetVersionEx(&osv);
|
||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
|
@ -126,7 +112,6 @@ void ExecScript(BOOL log) {
|
|||
pushstring("error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GetStartupInfo(&si);
|
||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||
|
@ -134,19 +119,25 @@ void ExecScript(BOOL log) {
|
|||
si.hStdOutput = newstdout;
|
||||
si.hStdError = newstdout;
|
||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||
pushstring("error");
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
pushstring("error");
|
||||
if (log) {
|
||||
GlobalUnlock(hUnusedBuf);
|
||||
GlobalFree(hUnusedBuf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (log) {
|
||||
dwLastOutput = GetTickCount();
|
||||
|
||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
if (dwRead) {
|
||||
dwLastOutput = GetTickCount();
|
||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||
szBuf[dwRead] = 0;
|
||||
{
|
||||
if (log) {
|
||||
char *p, *lineBreak;
|
||||
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
||||
|
@ -158,6 +149,10 @@ void ExecScript(BOOL log) {
|
|||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
if (log) {
|
||||
GlobalUnlock(hUnusedBuf);
|
||||
GlobalFree(hUnusedBuf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
|
@ -179,22 +174,29 @@ void ExecScript(BOOL log) {
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (g_to && GetTickCount() > dwLastOutput+g_to) {
|
||||
TerminateProcess(pi.hProcess, -1);
|
||||
lstrcpy(szRet, "timeout");
|
||||
}
|
||||
else Sleep(LOOPTIMEOUT);
|
||||
}
|
||||
GetExitCodeProcess(pi.hProcess, &dwExit);
|
||||
if (dwExit != STILL_ACTIVE) {
|
||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
}
|
||||
}
|
||||
if (*szUnusedBuf) LogMessage(szUnusedBuf);
|
||||
}
|
||||
else WaitForSingleObject(pi.hProcess, g_to);
|
||||
wsprintf(szRet,"%d",dwExit);
|
||||
if (log && *szUnusedBuf) LogMessage(szUnusedBuf);
|
||||
if (!szRet[0]) wsprintf(szRet,"%d",dwExit);
|
||||
pushstring(szRet);
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
if (log) GlobalUnlock(hUnusedBuf);
|
||||
if (log) {
|
||||
GlobalUnlock(hUnusedBuf);
|
||||
GlobalFree(hUnusedBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,7 +232,7 @@ char *my_strstr(const char *string, const char *strCharSet) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int my_atoi(char *s) {
|
||||
unsigned int my_atoi(char *s) {
|
||||
unsigned int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) {
|
||||
s+=2;
|
||||
|
@ -255,15 +257,12 @@ int my_atoi(char *s) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
int sign=0;
|
||||
if (*s == '-') { s++; sign++; }
|
||||
for (;;) {
|
||||
int c=*s++ - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
if (sign) return -(int) v;
|
||||
}
|
||||
return (int)v;
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue