Changed default timeout to 15 seconds (from 100 seconds). Returns now if CreateProcess fails. Now closes handles if unable to allocate memory.
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1258 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
65bc61f40f
commit
c9b3214463
3 changed files with 224 additions and 206 deletions
|
@ -3,6 +3,7 @@ nsExec
|
|||
nsExec will execute command-line based programs and capture the output
|
||||
without opening a dos box.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
nsExec::Exec [/TIMEOUT=x] path
|
||||
|
@ -15,13 +16,18 @@ Both functions are the same except ExecToLog will print the output
|
|||
to the logwindow.
|
||||
|
||||
The timeout value is optional and is used to set the time in
|
||||
milliseconds for the dll to wait for the process to return
|
||||
milliseconds for the plugin to wait for the process to return
|
||||
before it quits.
|
||||
|
||||
|
||||
Return Value
|
||||
------------
|
||||
If nsExec is unable to execute the process, it will return "error"
|
||||
on the top of the stack, else it returns "success".
|
||||
on the top of the stack, else it returns the return code from the
|
||||
executed process.
|
||||
|
||||
|
||||
Copyright Info
|
||||
--------------
|
||||
Copyright (c) 2002 Robert Rainwater
|
||||
Thanks to Justin Frankel and Amir Szekely
|
|
@ -1,3 +1,23 @@
|
|||
/*
|
||||
Copyright (c) 2002 Robert Rainwater <rrainwater@yahoo.com>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include "../exdll/exdll.h"
|
||||
|
@ -8,7 +28,7 @@
|
|||
#ifndef false
|
||||
#define false FALSE
|
||||
#endif
|
||||
#define TIMEOUT 100000
|
||||
#define TIMEOUT 15000
|
||||
#define LOOPTIMEOUT 100
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
|
@ -22,7 +42,6 @@ int g_to;
|
|||
|
||||
|
||||
void ExecScript(BOOL log);
|
||||
void LogMessages(const char *pStr);
|
||||
void LogMessage(const char *pStr);
|
||||
char *my_strstr(const char *string, const char *strCharSet);
|
||||
int my_atoi(char *s);
|
||||
|
@ -83,7 +102,6 @@ void ExecScript(BOOL log) {
|
|||
DWORD dwExit = !STILL_ACTIVE;
|
||||
static char szBuf[1024];
|
||||
static char szRet[128];
|
||||
|
||||
HGLOBAL hUnusedBuf;
|
||||
static char *szUnusedBuf;
|
||||
|
||||
|
@ -117,6 +135,7 @@ void ExecScript(BOOL log) {
|
|||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
pushstring("error");
|
||||
return;
|
||||
}
|
||||
|
||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||
|
@ -132,11 +151,14 @@ void ExecScript(BOOL log) {
|
|||
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
||||
if (!hUnusedBuf) {
|
||||
pushstring("error");
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
return;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
}
|
||||
|
||||
p = szUnusedBuf; // get the old left overs
|
||||
lstrcat(p, szBuf);
|
||||
|
||||
|
@ -149,8 +171,7 @@ void ExecScript(BOOL log) {
|
|||
// 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++;
|
||||
while (*p) *p2++ = *p++;
|
||||
*p2 = 0;
|
||||
}
|
||||
}
|
||||
|
@ -172,8 +193,7 @@ void ExecScript(BOOL log) {
|
|||
}
|
||||
}
|
||||
|
||||
// code I stole (err borrowed) from Tim Kosse
|
||||
// all credits/problems are his
|
||||
// Tim Kosse's LogMessage
|
||||
void LogMessage(const char *pStr) {
|
||||
LVITEM item={0};
|
||||
int nItemCount;
|
||||
|
@ -200,20 +220,16 @@ char *my_strstr(const char *string, const char *strCharSet) {
|
|||
s1=&((char*)string)[i];
|
||||
s2=(char*)strCharSet;
|
||||
while (*s1++ == *s2++)
|
||||
if (!*s2)
|
||||
return &((char*)string)[i];
|
||||
if (!*s2) return &((char*)string)[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int my_atoi(char *s)
|
||||
{
|
||||
int my_atoi(char *s) {
|
||||
unsigned int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
{
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) {
|
||||
s+=2;
|
||||
for (;;)
|
||||
{
|
||||
for (;;) {
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
|
@ -223,11 +239,9 @@ int my_atoi(char *s)
|
|||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
{
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0') {
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
for (;;) {
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
else break;
|
||||
|
@ -235,12 +249,10 @@ int my_atoi(char *s)
|
|||
v+=c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
int sign=0;
|
||||
if (*s == '-') { s++; sign++; }
|
||||
for (;;)
|
||||
{
|
||||
for (;;) {
|
||||
int c=*s++ - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue