Logging should work well now
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1256 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
8bcf198b34
commit
8d30b904a7
1 changed files with 194 additions and 175 deletions
|
@ -22,8 +22,8 @@ int g_to;
|
|||
|
||||
|
||||
void ExecScript(BOOL log);
|
||||
int LogMessages(const char *pStr);
|
||||
int LogMessage(const char *pStr);
|
||||
void LogMessages(const char *pStr);
|
||||
void LogMessage(const char *pStr);
|
||||
char *my_strstr(const char *string, const char *strCharSet);
|
||||
int my_atoi(char *s);
|
||||
|
||||
|
@ -82,9 +82,20 @@ void ExecScript(BOOL log) {
|
|||
DWORD dwRead = 1;
|
||||
DWORD dwExit = !STILL_ACTIVE;
|
||||
static char szBuf[1024];
|
||||
static char szBufTmp[4096];
|
||||
static char szRet[128];
|
||||
szBufTmp[0]=0;
|
||||
|
||||
HGLOBAL hUnusedBuf;
|
||||
static char *szUnusedBuf;
|
||||
|
||||
if (log) {
|
||||
hUnusedBuf = GlobalAlloc(GHND, sizeof(szBuf)*4);
|
||||
if (!hUnusedBuf) {
|
||||
pushstring("error");
|
||||
return;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
}
|
||||
|
||||
GetVersionEx(&osv);
|
||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
||||
|
@ -107,15 +118,41 @@ void ExecScript(BOOL log) {
|
|||
CloseHandle(read_stdout);
|
||||
pushstring("error");
|
||||
}
|
||||
|
||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
if (dwRead) {
|
||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||
szBuf[dwRead] = 0;
|
||||
if (log) {
|
||||
lstrcat(szBufTmp,szBuf);
|
||||
LogMessages(szBufTmp);
|
||||
*szBuf = 0;
|
||||
char *p, *lineBreak;
|
||||
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
||||
GlobalUnlock(hUnusedBuf);
|
||||
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
||||
if (!hUnusedBuf) {
|
||||
pushstring("error");
|
||||
return;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
}
|
||||
|
||||
p = szUnusedBuf; // get the old left overs
|
||||
lstrcat(p, szBuf);
|
||||
|
||||
while (lineBreak = my_strstr(p, "\r\n")) {
|
||||
*lineBreak = 0;
|
||||
LogMessage(p);
|
||||
p = lineBreak + 2;
|
||||
}
|
||||
|
||||
// If data was taken out from the unused buffer, move p contents to the start of szUnusedBuf
|
||||
if (p != szUnusedBuf) {
|
||||
char *p2 = szUnusedBuf;
|
||||
while (*p)
|
||||
*p2++ = *p++;
|
||||
*p2 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else Sleep(LOOPTIMEOUT);
|
||||
|
@ -124,41 +161,24 @@ void ExecScript(BOOL log) {
|
|||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
}
|
||||
}
|
||||
if (*szUnusedBuf) LogMessage(szUnusedBuf);
|
||||
wsprintf(szRet,"%d",dwExit);
|
||||
pushstring(szRet);
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
if (log) GlobalUnlock(hUnusedBuf);
|
||||
}
|
||||
}
|
||||
|
||||
int LogMessages(const char *pStr) {
|
||||
if (my_strstr(pStr,"\r\n")) {
|
||||
while (*pStr) {
|
||||
char *i = my_strstr(pStr,"\r\n");
|
||||
if (i==0) {
|
||||
LogMessage(pStr);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
*i=0;
|
||||
LogMessage(pStr);
|
||||
if (i-pStr<0) break;
|
||||
pStr = i+2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// code I stole (err borrowed) from Tim Kosse
|
||||
// all credits/problems are his
|
||||
int LogMessage(const char *pStr) {
|
||||
void LogMessage(const char *pStr) {
|
||||
LVITEM item={0};
|
||||
int nItemCount;
|
||||
if (!g_hwndList) return -1;
|
||||
if (lstrlen(pStr)==0) return -1;
|
||||
if (!g_hwndList) return;
|
||||
if (!lstrlen(pStr)) return;
|
||||
nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0);
|
||||
item.mask=LVIF_TEXT;
|
||||
item.pszText=(char *)pStr;
|
||||
|
@ -166,7 +186,6 @@ int LogMessage(const char *pStr) {
|
|||
item.iItem=nItemCount;
|
||||
ListView_InsertItem(g_hwndList, &item);
|
||||
ListView_EnsureVisible(g_hwndList, item.iItem, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,7 +196,7 @@ char *my_strstr(const char *string, const char *strCharSet) {
|
|||
if (lstrlen(string) < lstrlen(strCharSet)) return 0;
|
||||
if (!*strCharSet) return (char*)string;
|
||||
chklen=lstrlen(string)-lstrlen(strCharSet);
|
||||
for (i = 0; i < chklen; i++) {
|
||||
for (i = 0; i <= chklen; i++) {
|
||||
s1=&((char*)string)[i];
|
||||
s2=(char*)strCharSet;
|
||||
while (*s1++ == *s2++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue