Added ExecToLog

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@921 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
rainwater 2002-09-04 20:40:41 +00:00
parent a659c508b1
commit 74875edfc5

View file

@ -8,16 +8,18 @@
#ifndef false
#define false FALSE
#endif
#define TIMEOUT 100000
HINSTANCE g_hInstance;
HWND g_hwndParent;
HWND g_hwndList;
HWND g_hwndDlg;
char g_exec[MAX_PATH];
BOOL g_done;
char * g_exec;
char * g_szto;
BOOL g_foundto;
int g_to;
void ExecScript(BOOL log);
int LogMessage(const char *pStr);
char *my_strstr(const char *string, const char *strCharSet);
int my_atoi(char *s);
@ -28,12 +30,50 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable
g_stacktop=stacktop;
g_variables=variables;
{
g_to = 100000;
ExecScript(false);
}
}
void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
g_hwndParent=hwndParent;
g_stringsize=string_size;
g_stacktop=stacktop;
g_variables=variables;
{
ExecScript(true);
}
}
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
g_hInstance=hInst;
return TRUE;
}
void ExecScript(BOOL log) {
g_to = TIMEOUT;
g_foundto = FALSE;
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
if (!g_foundto&&!popstring(g_exec)) {
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 = TIMEOUT;
g_foundto = TRUE;
}
}
if (g_foundto) {
if (popstring(g_exec)) {
pushstring("error");
return;
}
}
else {
lstrcpy(g_exec,g_szto);
}
{
STARTUPINFO si={sizeof(si),};
SECURITY_ATTRIBUTES sa={sizeof(sa),};
SECURITY_DESCRIPTOR sd={0,};
@ -53,7 +93,6 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable
else sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
pushstring("");
pushstring("error");
return;
}
@ -65,7 +104,6 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
CloseHandle(newstdout);
CloseHandle(read_stdout);
pushstring("");
pushstring("error");
}
WaitForSingleObject(pi.hProcess,INFINITE);
@ -73,40 +111,33 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable
memory = GlobalAlloc(GMEM_MOVEABLE,dwRead+1);
szBuf = (char *)GlobalLock(memory);
ReadFile(read_stdout, szBuf, dwRead, &dwRead, NULL);
pushstring(szBuf);
pushstring("success");
if (my_strstr(szBuf,"\r\n")) {
while (szBuf&&*szBuf) {
char *i = my_strstr(szBuf,"\r\n");
if (!i) {
if (log) {
if (my_strstr(szBuf,"\r")) {
while (*szBuf) {
char *i = my_strstr(szBuf,"\r");
if (i==0) {
LogMessage(szBuf);
break;
}
*i=0;
if (*(i+1)=='\n') *(i+1)=0;
LogMessage(szBuf);
szBuf = i+2;
if (!*(i+1)) szBuf = i+2;
else szBuf = i+1;
}
}
else if (my_strstr(szBuf,"\n")) {
MessageBox(0,"n","n",MB_OK);
}
else {
LogMessage(szBuf);
}
GlobalFree(szBuf);
}
GlobalFree(memory);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(newstdout);
CloseHandle(read_stdout);
}
pushstring("");
pushstring("error");
}
}
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
g_hInstance=hInst;
return TRUE;
}
// code I stole (err borrowed) from Tim Kosse