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);
|
void ExecScript(BOOL log);
|
||||||
int LogMessages(const char *pStr);
|
void LogMessages(const char *pStr);
|
||||||
int LogMessage(const char *pStr);
|
void 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);
|
||||||
|
|
||||||
|
@ -82,9 +82,20 @@ void ExecScript(BOOL log) {
|
||||||
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 szRet[128];
|
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);
|
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);
|
||||||
|
@ -107,15 +118,41 @@ void ExecScript(BOOL log) {
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(read_stdout);
|
||||||
pushstring("error");
|
pushstring("error");
|
||||||
}
|
}
|
||||||
|
|
||||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
if (dwRead) {
|
if (dwRead) {
|
||||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||||
szBuf[dwRead] = 0;
|
szBuf[dwRead] = 0;
|
||||||
if (log) {
|
if (log) {
|
||||||
lstrcat(szBufTmp,szBuf);
|
char *p, *lineBreak;
|
||||||
LogMessages(szBufTmp);
|
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||||
*szBuf = 0;
|
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);
|
else Sleep(LOOPTIMEOUT);
|
||||||
|
@ -124,41 +161,24 @@ void ExecScript(BOOL log) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (*szUnusedBuf) LogMessage(szUnusedBuf);
|
||||||
wsprintf(szRet,"%d",dwExit);
|
wsprintf(szRet,"%d",dwExit);
|
||||||
pushstring(szRet);
|
pushstring(szRet);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(newstdout);
|
CloseHandle(newstdout);
|
||||||
CloseHandle(read_stdout);
|
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
|
// code I stole (err borrowed) from Tim Kosse
|
||||||
// all credits/problems are his
|
// all credits/problems are his
|
||||||
int LogMessage(const char *pStr) {
|
void LogMessage(const char *pStr) {
|
||||||
LVITEM item={0};
|
LVITEM item={0};
|
||||||
int nItemCount;
|
int nItemCount;
|
||||||
if (!g_hwndList) return -1;
|
if (!g_hwndList) return;
|
||||||
if (lstrlen(pStr)==0) return -1;
|
if (!lstrlen(pStr)) return;
|
||||||
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;
|
||||||
|
@ -166,7 +186,6 @@ int LogMessage(const char *pStr) {
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,7 +196,7 @@ char *my_strstr(const char *string, const char *strCharSet) {
|
||||||
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++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue