Added return value to nsExex. Logging still broke.
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1250 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
62abf21381
commit
7075c16cb1
1 changed files with 142 additions and 150 deletions
|
@ -11,14 +11,14 @@
|
||||||
#define TIMEOUT 100000
|
#define TIMEOUT 100000
|
||||||
#define LOOPTIMEOUT 100
|
#define LOOPTIMEOUT 100
|
||||||
|
|
||||||
HINSTANCE g_hInstance;
|
HINSTANCE g_hInstance;
|
||||||
HWND g_hwndParent;
|
HWND g_hwndParent;
|
||||||
HWND g_hwndList;
|
HWND g_hwndList;
|
||||||
HWND g_hwndDlg;
|
HWND g_hwndDlg;
|
||||||
char * g_exec;
|
char * g_exec;
|
||||||
char * g_szto;
|
char * g_szto;
|
||||||
BOOL g_foundto;
|
BOOL g_foundto;
|
||||||
int g_to;
|
int g_to;
|
||||||
|
|
||||||
|
|
||||||
void ExecScript(BOOL log);
|
void ExecScript(BOOL log);
|
||||||
|
@ -28,171 +28,163 @@ char *my_strstr(const char *string, const char *strCharSet);
|
||||||
int my_atoi(char *s);
|
int my_atoi(char *s);
|
||||||
|
|
||||||
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||||
g_hwndParent=hwndParent;
|
g_hwndParent=hwndParent;
|
||||||
EXDLL_INIT();
|
EXDLL_INIT();
|
||||||
{
|
{
|
||||||
ExecScript(false);
|
ExecScript(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||||
g_hwndParent=hwndParent;
|
g_hwndParent=hwndParent;
|
||||||
EXDLL_INIT();
|
EXDLL_INIT();
|
||||||
{
|
{
|
||||||
ExecScript(true);
|
ExecScript(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||||
g_hInstance=hInst;
|
g_hInstance=hInst;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecScript(BOOL log) {
|
void ExecScript(BOOL log) {
|
||||||
g_to = TIMEOUT;
|
g_to = TIMEOUT;
|
||||||
g_foundto = FALSE;
|
g_foundto = FALSE;
|
||||||
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
||||||
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
||||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
||||||
g_szto = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
g_szto = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
||||||
if (!popstring(g_szto)) {
|
if (!popstring(g_szto)) {
|
||||||
if (my_strstr(g_szto,"/TIMEOUT=")) {
|
if (my_strstr(g_szto,"/TIMEOUT=")) {
|
||||||
g_szto += 9;
|
g_szto += 9;
|
||||||
g_to = my_atoi(g_szto);
|
g_to = my_atoi(g_szto);
|
||||||
if (g_to<0) g_to = TIMEOUT;
|
if (g_to<0) g_to = TIMEOUT;
|
||||||
g_foundto = TRUE;
|
g_foundto = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (g_foundto) {
|
if (g_foundto) {
|
||||||
if (popstring(g_exec)) {
|
if (popstring(g_exec)) {
|
||||||
pushstring("error");
|
pushstring("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lstrcpy(g_exec,g_szto);
|
lstrcpy(g_exec,g_szto);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
STARTUPINFO si={sizeof(si),};
|
STARTUPINFO si={sizeof(si),};
|
||||||
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
||||||
SECURITY_DESCRIPTOR sd={0,};
|
SECURITY_DESCRIPTOR sd={0,};
|
||||||
PROCESS_INFORMATION pi={0,};
|
PROCESS_INFORMATION pi={0,};
|
||||||
OSVERSIONINFO osv={sizeof(osv)};
|
OSVERSIONINFO osv={sizeof(osv)};
|
||||||
HANDLE newstdout=0,read_stdout=0;
|
HANDLE newstdout=0,read_stdout=0;
|
||||||
DWORD dwRead = 1;
|
DWORD dwRead = 1;
|
||||||
DWORD dwExit = !STILL_ACTIVE;
|
DWORD dwExit = !STILL_ACTIVE;
|
||||||
static char szBuf[1024];
|
static char szBuf[1024];
|
||||||
static char szBufTmp[4096];
|
static char szBufTmp[4096];
|
||||||
szBufTmp[0]=0;
|
static char szRet[128];
|
||||||
GetVersionEx(&osv);
|
szBufTmp[0]=0;
|
||||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
GetVersionEx(&osv);
|
||||||
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||||
SetSecurityDescriptorDacl(&sd,true,NULL,false);
|
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
||||||
sa.lpSecurityDescriptor = &sd;
|
SetSecurityDescriptorDacl(&sd,true,NULL,false);
|
||||||
}
|
sa.lpSecurityDescriptor = &sd;
|
||||||
else sa.lpSecurityDescriptor = NULL;
|
}
|
||||||
sa.bInheritHandle = true;
|
else sa.lpSecurityDescriptor = NULL;
|
||||||
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
sa.bInheritHandle = true;
|
||||||
pushstring("error");
|
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
||||||
return;
|
pushstring("error");
|
||||||
}
|
return;
|
||||||
GetStartupInfo(&si);
|
}
|
||||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
GetStartupInfo(&si);
|
||||||
si.wShowWindow = SW_HIDE;
|
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||||
si.hStdOutput = newstdout;
|
si.wShowWindow = SW_HIDE;
|
||||||
si.hStdError = newstdout;
|
si.hStdOutput = newstdout;
|
||||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
si.hStdError = newstdout;
|
||||||
CloseHandle(newstdout);
|
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(newstdout);
|
||||||
pushstring("error");
|
CloseHandle(read_stdout);
|
||||||
}
|
pushstring("error");
|
||||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
}
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||||
if (dwRead) {
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
if (dwRead) {
|
||||||
szBuf[dwRead] = 0;
|
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||||
if (log) {
|
szBuf[dwRead] = 0;
|
||||||
lstrcat(szBufTmp,szBuf);
|
if (log) {
|
||||||
LogMessages(szBufTmp);
|
lstrcat(szBufTmp,szBuf);
|
||||||
}
|
LogMessages(szBufTmp);
|
||||||
}
|
*szBuf = 0;
|
||||||
else Sleep(LOOPTIMEOUT);
|
}
|
||||||
GetExitCodeProcess(pi.hProcess, &dwExit);
|
}
|
||||||
if (dwExit != STILL_ACTIVE) {
|
else Sleep(LOOPTIMEOUT);
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
GetExitCodeProcess(pi.hProcess, &dwExit);
|
||||||
}
|
if (dwExit != STILL_ACTIVE) {
|
||||||
}
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
CloseHandle(pi.hThread);
|
}
|
||||||
CloseHandle(pi.hProcess);
|
}
|
||||||
CloseHandle(newstdout);
|
wsprintf(szRet,"%d",dwExit);
|
||||||
CloseHandle(read_stdout);
|
pushstring(szRet);
|
||||||
}
|
CloseHandle(pi.hThread);
|
||||||
|
CloseHandle(pi.hProcess);
|
||||||
|
CloseHandle(newstdout);
|
||||||
|
CloseHandle(read_stdout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int LogMessages(const char *pStr) {
|
int LogMessages(const char *pStr) {
|
||||||
if (my_strstr(pStr,"\r")) {
|
if (my_strstr(pStr,"\r\n")) {
|
||||||
while (*pStr) {
|
while (*pStr) {
|
||||||
char *i = my_strstr(pStr,"\r");
|
char *i = my_strstr(pStr,"\r\n");
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
LogMessage(pStr);
|
LogMessage(pStr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*i=0;
|
else {
|
||||||
if (*(i+1)=='\n') *(i+1)=0;
|
*i=0;
|
||||||
LogMessage(pStr);
|
LogMessage(pStr);
|
||||||
if (!*(i+1)) pStr = i+2;
|
if (i-pStr<0) break;
|
||||||
else pStr = i+1;
|
pStr = i+2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (my_strstr(pStr,"\n")) {
|
}
|
||||||
while (*pStr) {
|
return 1;
|
||||||
char *i = my_strstr(pStr,"\n");
|
|
||||||
if (i==0) {
|
|
||||||
LogMessage(pStr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*i=0;
|
|
||||||
LogMessage(pStr);
|
|
||||||
pStr = i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// code I stole (err borrowed) from Tim Kosse
|
// code I stole (err borrowed) from Tim Kosse
|
||||||
// all credits/problems are his
|
// all credits/problems are his
|
||||||
int LogMessage(const char *pStr) {
|
int LogMessage(const char *pStr) {
|
||||||
LVITEM item={0};
|
LVITEM item={0};
|
||||||
int nItemCount;
|
int nItemCount;
|
||||||
if (!g_hwndList) return -1;
|
if (!g_hwndList) return -1;
|
||||||
if (lstrlen(pStr)==0) return -1;
|
if (lstrlen(pStr)==0) return -1;
|
||||||
nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0);
|
nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0);
|
||||||
item.mask=LVIF_TEXT;
|
item.mask=LVIF_TEXT;
|
||||||
item.pszText=(char *)pStr;
|
item.pszText=(char *)pStr;
|
||||||
item.cchTextMax=0;
|
item.cchTextMax=0;
|
||||||
item.iItem=nItemCount;
|
item.iItem=nItemCount;
|
||||||
ListView_InsertItem(g_hwndList, &item);
|
ListView_InsertItem(g_hwndList, &item);
|
||||||
ListView_EnsureVisible(g_hwndList, item.iItem, 0);
|
ListView_EnsureVisible(g_hwndList, item.iItem, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *my_strstr(const char *string, const char *strCharSet) {
|
char *my_strstr(const char *string, const char *strCharSet) {
|
||||||
char *s1, *s2;
|
char *s1, *s2;
|
||||||
size_t chklen;
|
size_t chklen;
|
||||||
size_t i;
|
size_t i;
|
||||||
if (lstrlen(string) < lstrlen(strCharSet)) return 0;
|
if (lstrlen(string) < lstrlen(strCharSet)) return 0;
|
||||||
if (!*strCharSet) return (char*)string;
|
if (!*strCharSet) return (char*)string;
|
||||||
chklen=lstrlen(string)-lstrlen(strCharSet);
|
chklen=lstrlen(string)-lstrlen(strCharSet);
|
||||||
for (i = 0; i < chklen; i++) {
|
for (i = 0; i < chklen; i++) {
|
||||||
s1=&((char*)string)[i];
|
s1=&((char*)string)[i];
|
||||||
s2=(char*)strCharSet;
|
s2=(char*)strCharSet;
|
||||||
while (*s1++ == *s2++)
|
while (*s1++ == *s2++)
|
||||||
if (!*s2)
|
if (!*s2)
|
||||||
return &((char*)string)[i];
|
return &((char*)string)[i];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int my_atoi(char *s)
|
int my_atoi(char *s)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue