Added ExecToStack
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1814 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
04e4f0f129
commit
3797b9776d
6 changed files with 61 additions and 60 deletions
|
@ -19,7 +19,7 @@ typedef struct _stack_t {
|
||||||
} stack_t;
|
} stack_t;
|
||||||
|
|
||||||
|
|
||||||
static int g_stringsize;
|
static unsigned int g_stringsize;
|
||||||
static stack_t **g_stacktop;
|
static stack_t **g_stacktop;
|
||||||
static char *g_variables;
|
static char *g_variables;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ BSC32=bscmake.exe
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LINK32=link.exe
|
LINK32=link.exe
|
||||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/nsExec.dll" /opt:nowin98
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /map /machine:I386 /nodefaultlib /out:"../../Plugins/nsExec.dll" /opt:nowin98
|
||||||
# SUBTRACT LINK32 /pdb:none
|
# SUBTRACT LINK32 /pdb:none
|
||||||
# Begin Target
|
# Begin Target
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,13 @@ nsExec::Exec [/TIMEOUT=x] path
|
||||||
|
|
||||||
nsExec::ExecToLog [/TIMEOUT=x] path
|
nsExec::ExecToLog [/TIMEOUT=x] path
|
||||||
|
|
||||||
Both functions are the same except ExecToLog will print the output
|
-or-
|
||||||
to the logwindow.
|
|
||||||
|
nsExec::ExecToStack [/TIMEOUT=x] path
|
||||||
|
|
||||||
|
All functions are the same except ExecToLog will print the output
|
||||||
|
to the logwindow and ExecToStack will push up to ${NSIS_MAX_STRLEN}
|
||||||
|
characters of output onto the stack after the return value.
|
||||||
|
|
||||||
The timeout value is optional. The timeout is the time in
|
The timeout value is optional. The timeout is the time in
|
||||||
milliseconds nsExec will wait for output. If output from the
|
milliseconds nsExec will wait for output. If output from the
|
||||||
|
|
|
@ -45,7 +45,7 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable
|
||||||
g_hwndParent=hwndParent;
|
g_hwndParent=hwndParent;
|
||||||
EXDLL_INIT();
|
EXDLL_INIT();
|
||||||
{
|
{
|
||||||
ExecScript(false);
|
ExecScript(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,15 @@ void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *var
|
||||||
g_hwndParent=hwndParent;
|
g_hwndParent=hwndParent;
|
||||||
EXDLL_INIT();
|
EXDLL_INIT();
|
||||||
{
|
{
|
||||||
ExecScript(true);
|
ExecScript(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __declspec(dllexport) ExecToStack(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||||
|
g_hwndParent=hwndParent;
|
||||||
|
EXDLL_INIT();
|
||||||
|
{
|
||||||
|
ExecScript(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +69,9 @@ BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lp
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecScript(BOOL log) {
|
void ExecScript(int log) {
|
||||||
|
char szRet[128] = "";
|
||||||
|
|
||||||
g_to = 0; // default is no timeout
|
g_to = 0; // default is no timeout
|
||||||
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
||||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
||||||
|
@ -73,8 +83,8 @@ void ExecScript(BOOL log) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!g_exec[0]) {
|
if (!g_exec[0]) {
|
||||||
pushstring("error");
|
lstrcpy(szRet, "error");
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
STARTUPINFO si={sizeof(si),};
|
STARTUPINFO si={sizeof(si),};
|
||||||
|
@ -87,15 +97,14 @@ void ExecScript(BOOL log) {
|
||||||
DWORD dwExit = !STILL_ACTIVE;
|
DWORD dwExit = !STILL_ACTIVE;
|
||||||
DWORD dwLastOutput;
|
DWORD dwLastOutput;
|
||||||
static char szBuf[1024];
|
static char szBuf[1024];
|
||||||
char szRet[128] = "";
|
|
||||||
HGLOBAL hUnusedBuf;
|
HGLOBAL hUnusedBuf;
|
||||||
char *szUnusedBuf = 0;
|
char *szUnusedBuf = 0;
|
||||||
|
|
||||||
if (log) {
|
if (log) {
|
||||||
hUnusedBuf = GlobalAlloc(GHND, sizeof(szBuf)*4);
|
hUnusedBuf = GlobalAlloc(GHND, log & 2 ? g_stringsize : sizeof(szBuf)*4);
|
||||||
if (!hUnusedBuf) {
|
if (!hUnusedBuf) {
|
||||||
pushstring("error");
|
lstrcpy(szRet, "error");
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||||
}
|
}
|
||||||
|
@ -109,8 +118,8 @@ void ExecScript(BOOL log) {
|
||||||
else sa.lpSecurityDescriptor = NULL;
|
else sa.lpSecurityDescriptor = NULL;
|
||||||
sa.bInheritHandle = true;
|
sa.bInheritHandle = true;
|
||||||
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
||||||
pushstring("error");
|
lstrcpy(szRet, "error");
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetStartupInfo(&si);
|
GetStartupInfo(&si);
|
||||||
|
@ -119,14 +128,8 @@ void ExecScript(BOOL log) {
|
||||||
si.hStdOutput = newstdout;
|
si.hStdOutput = newstdout;
|
||||||
si.hStdError = newstdout;
|
si.hStdError = newstdout;
|
||||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||||
pushstring("error");
|
lstrcpy(szRet, "error");
|
||||||
CloseHandle(newstdout);
|
goto done;
|
||||||
CloseHandle(read_stdout);
|
|
||||||
if (log) {
|
|
||||||
GlobalUnlock(hUnusedBuf);
|
|
||||||
GlobalFree(hUnusedBuf);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dwLastOutput = GetTickCount();
|
dwLastOutput = GetTickCount();
|
||||||
|
@ -140,37 +143,34 @@ void ExecScript(BOOL log) {
|
||||||
if (log) {
|
if (log) {
|
||||||
char *p, *lineBreak;
|
char *p, *lineBreak;
|
||||||
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||||
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
if (GlobalSize(hUnusedBuf) < iReqLen && (iReqLen < g_stringsize || !(log & 2))) {
|
||||||
GlobalUnlock(hUnusedBuf);
|
GlobalUnlock(hUnusedBuf);
|
||||||
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
||||||
if (!hUnusedBuf) {
|
if (!hUnusedBuf) {
|
||||||
pushstring("error");
|
lstrcpy(szRet, "error");
|
||||||
CloseHandle(pi.hThread);
|
break;
|
||||||
CloseHandle(pi.hProcess);
|
|
||||||
CloseHandle(newstdout);
|
|
||||||
CloseHandle(read_stdout);
|
|
||||||
if (log) {
|
|
||||||
GlobalUnlock(hUnusedBuf);
|
|
||||||
GlobalFree(hUnusedBuf);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||||
}
|
}
|
||||||
p = szUnusedBuf; // get the old left overs
|
p = szUnusedBuf; // get the old left overs
|
||||||
lstrcat(p, szBuf);
|
if (iReqLen < g_stringsize || !(log & 2)) lstrcat(p, szBuf);
|
||||||
|
else {
|
||||||
while (lineBreak = my_strstr(p, "\r\n")) {
|
lstrcpyn(p + lstrlen(p), szBuf, g_stringsize - lstrlen(p));
|
||||||
*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 (!(log & 2)) {
|
||||||
if (p != szUnusedBuf) {
|
while (lineBreak = my_strstr(p, "\r\n")) {
|
||||||
char *p2 = szUnusedBuf;
|
*lineBreak = 0;
|
||||||
while (*p) *p2++ = *p++;
|
LogMessage(p);
|
||||||
*p2 = 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,9 @@ void ExecScript(BOOL log) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (log && *szUnusedBuf) LogMessage(szUnusedBuf);
|
done:
|
||||||
|
if (log & 2) pushstring(szUnusedBuf);
|
||||||
|
if (log & 1 && *szUnusedBuf) LogMessage(szUnusedBuf);
|
||||||
if (!szRet[0]) wsprintf(szRet,"%d",dwExit);
|
if (!szRet[0]) wsprintf(szRet,"%d",dwExit);
|
||||||
pushstring(szRet);
|
pushstring(szRet);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
|
|
|
@ -6,25 +6,19 @@ ShowInstDetails show
|
||||||
|
|
||||||
Section "MakeNSIS commands help"
|
Section "MakeNSIS commands help"
|
||||||
nsExec::ExecToLog '"${NSISDIR}\makensis.exe" /CMDHELP'
|
nsExec::ExecToLog '"${NSISDIR}\makensis.exe" /CMDHELP'
|
||||||
Pop $0
|
Pop $0 # return value/error/timeout
|
||||||
DetailPrint ""
|
DetailPrint ""
|
||||||
DetailPrint " Return value: $0"
|
DetailPrint " Return value: $0"
|
||||||
|
DetailPrint ""
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "Output to variable"
|
Section "Output to variable"
|
||||||
ReadEnvStr $0 COMSPEC
|
nsExec::ExecToStack '"${NSISDIR}\makensis.exe" /VERSION'
|
||||||
GetTempFileName $1
|
Pop $0 # return value/error/timeout
|
||||||
StrCpy $2 "${NSISDIR}\makensis.exe"
|
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
|
||||||
GetFullPathName /SHORT $2 $2
|
DetailPrint '"${NSISDIR}\makensis.exe" /VERSION printed: $1'
|
||||||
StrCpy $0 '"$0" /C $2 /VERSION > "$1"'
|
|
||||||
nsExec::Exec $0
|
|
||||||
FileOpen $0 $1 r
|
|
||||||
FileRead $0 $3
|
|
||||||
FileClose $0
|
|
||||||
SetDetailsPrint none
|
|
||||||
Delete $1
|
|
||||||
SetDetailsPrint both
|
|
||||||
DetailPrint ""
|
DetailPrint ""
|
||||||
DetailPrint "$2 /VERSION returned: $3"
|
DetailPrint " Return value: $0"
|
||||||
DetailPrint ""
|
DetailPrint ""
|
||||||
|
Return
|
||||||
SectionEnd
|
SectionEnd
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue