Some broken code, but fixes pipe issue
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@930 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
63c6ec2859
commit
055bf1d65b
2 changed files with 38 additions and 28 deletions
|
@ -9,6 +9,7 @@
|
||||||
#define false FALSE
|
#define false FALSE
|
||||||
#endif
|
#endif
|
||||||
#define TIMEOUT 100000
|
#define TIMEOUT 100000
|
||||||
|
#define LOOPTIMEOUT 100
|
||||||
|
|
||||||
HINSTANCE g_hInstance;
|
HINSTANCE g_hInstance;
|
||||||
HWND g_hwndParent;
|
HWND g_hwndParent;
|
||||||
|
@ -19,7 +20,9 @@ char * g_szto;
|
||||||
BOOL g_foundto;
|
BOOL g_foundto;
|
||||||
int g_to;
|
int g_to;
|
||||||
|
|
||||||
|
|
||||||
void ExecScript(BOOL log);
|
void ExecScript(BOOL log);
|
||||||
|
int LogMessages(const char *pStr);
|
||||||
int LogMessage(const char *pStr);
|
int LogMessage(const char *pStr);
|
||||||
char *my_strstr(const char *string, const char *strCharSet);
|
char *my_strstr(const char *string, const char *strCharSet);
|
||||||
int my_atoi(char *s);
|
int my_atoi(char *s);
|
||||||
|
@ -81,9 +84,10 @@ void ExecScript(BOOL log) {
|
||||||
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;
|
DWORD dwExit = !STILL_ACTIVE;
|
||||||
HGLOBAL memory;
|
char szBuf[1024];
|
||||||
char *szBuf;
|
char szBufTmp[1024];
|
||||||
|
szBufTmp[0]=0;
|
||||||
GetVersionEx(&osv);
|
GetVersionEx(&osv);
|
||||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||||
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
||||||
|
@ -106,35 +110,22 @@ void ExecScript(BOOL log) {
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(read_stdout);
|
||||||
pushstring("error");
|
pushstring("error");
|
||||||
}
|
}
|
||||||
if (WaitForSingleObject(pi.hProcess,INFINITE)==WAIT_TIMEOUT) {
|
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||||
TerminateProcess(pi.hProcess,GetExitCodeProcess(pi.hProcess,&dwExit));
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
}
|
if (dwRead) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||||
memory = GlobalAlloc(GMEM_MOVEABLE,dwRead+1);
|
szBuf[dwRead] = 0;
|
||||||
szBuf = (char *)GlobalLock(memory);
|
if (log) {
|
||||||
ReadFile(read_stdout, szBuf, dwRead, &dwRead, NULL);
|
lstrcat(szBufTmp,szBuf);
|
||||||
pushstring("success");
|
LogMessages(szBufTmp);
|
||||||
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);
|
|
||||||
if (!*(i+1)) szBuf = i+2;
|
|
||||||
else szBuf = i+1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else Sleep(LOOPTIMEOUT);
|
||||||
LogMessage(szBuf);
|
GetExitCodeProcess(pi.hProcess, &dwExit);
|
||||||
|
if (dwExit != STILL_ACTIVE) {
|
||||||
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalUnlock(memory);
|
|
||||||
GlobalFree(memory);
|
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(newstdout);
|
CloseHandle(newstdout);
|
||||||
|
@ -143,12 +134,31 @@ void ExecScript(BOOL log) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LogMessages(const char *pStr) {
|
||||||
|
if (my_strstr(pStr,"\r")) {
|
||||||
|
while (*pStr) {
|
||||||
|
char *i = my_strstr(pStr,"\r");
|
||||||
|
if (i==0) {
|
||||||
|
LogMessage(pStr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*i=0;
|
||||||
|
if (*(i+1)=='\n') *(i+1)=0;
|
||||||
|
LogMessage(pStr);
|
||||||
|
if (!*(i+1)) pStr = i+2;
|
||||||
|
else 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;
|
||||||
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;
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue