Added automatic use of dll commands (see config.h for more details)

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@645 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
sunjammerx 2002-08-05 02:05:00 +00:00
parent 8ef7b8fe3c
commit 31ad4513e9
16 changed files with 752 additions and 18 deletions

View file

@ -31,9 +31,12 @@
#include "fileform.h"
#include "state.h"
#include "ui.h"
#include "lang.h"
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#include "dllpaths.h"
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
extern unsigned long CRC32(unsigned long crc, const unsigned char *buf, unsigned int len);
#if !defined(NSIS_CONFIG_VISIBLE_SUPPORT) && !defined(NSIS_CONFIG_SILENT_SUPPORT)
@ -359,6 +362,11 @@ end:
if (dbd_hFile!=INVALID_HANDLE_VALUE) CloseHandle(dbd_hFile);
#endif
if (m_Err) MessageBox(NULL,m_Err,g_caption,MB_OK|MB_ICONSTOP);
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
DllPathsCleanup();
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
ExitProcess(ret);
}

View file

@ -178,6 +178,29 @@
// NSIS_SUPPORT_MESSAGEBOX enables support for MessageBox
#define NSIS_SUPPORT_MESSAGEBOX
// Added by Ximon Eighteen 5th August 2002
// If this is uncommented the following changes/new features are
// turned on :-
// - At the start of compilation a directory called dlls in
// the directory where makensis.exe is running from will be
// scanned for .dll files.
// - Any functions in the detected dll files that are exported
// by name will be remembered. These names are then legal
// command keywords in an NSIS script.
// - Any command that is unrecognised is checked against the
// list of external dll command names. If matched the dll will
// be packed into the installer.
// - On the installer machine (rather than the build machine)
// on first use of a command that requires a plugin dll that
// dll will be extracted to the temporary directory with a
// temporary file name.
// - Any parameters following the command will be pushed onto
// the stack in left to right order.
// - The command will then be invoked in the dll as if
// "CallInstDLL dll command" had been invoked.
// - When the installer exits any extracted temporary dlls will
// be deleted.
//#define NSIS_CONFIG_PLUGIN_SUPPORT
// fixes

91
Source/exehead/dllpaths.c Normal file
View file

@ -0,0 +1,91 @@
#include "dllpaths.h"
#include <windows.h>
#include "util.h"
static int initialised = 0;
static int numPackedPathIds;
static int* packedPathIds;
static char** newPaths;
void* DllPathsAlloc(long bytes)
{
return HeapAlloc(
GetProcessHeap(),
HEAP_ZERO_MEMORY,
bytes);
}
void DllPathsFree(void* ptr)
{
HeapFree(GetProcessHeap(),0,ptr);
}
void DllPathsCleanup(void)
{
if (initialised)
{
if (packedPathIds)
{
int i;
DllPathsFree(packedPathIds);
for (i = 0; i < numPackedPathIds; i++)
{
DeleteFile(newPaths[i]);
DllPathsFree(newPaths[i]);
}
DllPathsFree(newPaths);
}
numPackedPathIds = 0;
packedPathIds = 0;
newPaths = 0;
initialised = 0;
}
}
void DllPathsInitialise(void)
{
if (!initialised)
{
numPackedPathIds = 0;
packedPathIds = 0;
newPaths = 0;
initialised = 1;
}
}
void DllPathsAdd(int n,char* path)
{
DllPathsInitialise();
if (!DllPathsDetermined(n))
{
int* newIntArray = (int*)DllPathsAlloc(sizeof(int)*(numPackedPathIds+1));
char** newCharArray = (char**)DllPathsAlloc(sizeof(char*)*(numPackedPathIds+1));
mini_memcpy(newIntArray,packedPathIds,numPackedPathIds*sizeof(int));
mini_memcpy(newCharArray,newPaths,numPackedPathIds*sizeof(char*));
DllPathsFree(packedPathIds);
DllPathsFree(newPaths);
packedPathIds = newIntArray;
newPaths = newCharArray;
packedPathIds[numPackedPathIds] = n;
newPaths[numPackedPathIds] = (char*)DllPathsAlloc(sizeof(char)*(lstrlen(path)+1));
lstrcpy(newPaths[numPackedPathIds],path);
numPackedPathIds++;
}
}
char* DllPathsDetermined(int n)
{
int i;
DllPathsInitialise();
for (i = 0; i < numPackedPathIds; i++)
{
if (packedPathIds[i] == n)
return newPaths[i];
}
return 0;
}

13
Source/exehead/dllpaths.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef __X18_DLLPATHS_H
#define __X18_DLLPATHS_H
void DllPathsCleanup(void);
void DllPathsInitialise(void);
void DllPathsAdd(int,char*);
char* DllPathsDetermined(int);
#endif

View file

@ -9,6 +9,10 @@
#include "lang.h"
#include "resource.h"
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#include "dllpaths.h"
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
#define EXEC_ERROR 0x7FFFFFFF
#ifdef NSIS_CONFIG_COMPONENTPAGE
@ -1418,6 +1422,71 @@ static int ExecuteEntry(entry *entries, int pos)
}
return 0;
#endif //NSIS_CONFIG_VISIBLE_SUPPORT
// Added by Ximon Eighteen 5th August 2002
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
case EW_EXTERNALCOMMANDPREP:
{
// parms[0] - dll name
// parms[1] - function name
// parms[2] - compressed data handle
char* dllPath = DllPathsDetermined(parms[0]);
if (!dllPath)
{
HANDLE hOut;
if (!GetTempPath(NSIS_MAX_STRLEN,buf2) ||
!GetTempFileName(buf2,"nst",0,buf))
{
exec_errorflag++;
return 0;
}
hOut = myOpenFile(buf,GENERIC_WRITE,CREATE_ALWAYS);
GetCompressedDataFromDataBlock(parms[2],hOut);
CloseHandle(hOut);
DllPathsAdd(parms[0],buf);
}
// leave buf containing the dll path
// and buf2 containing the function name
process_string_fromtab(buf2,parms[1]);
}
return 0;
case EW_EXTERNALCOMMAND:
{
// parms contain command arguments
FARPROC funke;
HANDLE h;
int i;
// Place the command arguments on the stack, then invoke a CallInstDLL
// command on behalf of the user. Error handling needs improving, this
// won't fail gracefully, instead it could leave the stack in a state
// the user script won't expect.
for (i = 0; parms[i] != -1 && i < MAX_ENTRY_OFFSETS; i++)
{
stack_t* s = (stack_t*)GlobalAlloc(GPTR,sizeof(stack_t));
process_string_fromtab(s->text,parms[i]);
s->next = g_st;
g_st = s;
}
h = LoadLibrary(buf);
if (h)
{
funke = GetProcAddress(h,buf2);
if (funke)
{
void (*func)(HWND,int,char*,void*);
func = (void*)funke;
func(g_hwnd,NSIS_MAX_STRLEN,(char*)g_usrvars,(void*)&g_st);
}
FreeLibrary(h);
}
}
return 0;
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
}
MessageBox(g_hwnd,LANG_INSTCORRUPTED,g_caption,MB_OK|MB_ICONSTOP);
return EXEC_ERROR;

View file

@ -40,7 +40,7 @@ RSC=rc.exe
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O1 /Oy /D "_WINDOWS" /D "EXEHEAD" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "WIN32_LEAN_AND_MEAN" /D "NSIS_COMPRESS_USE_BZIP2" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# SUBTRACT CPP /Fr /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -152,6 +152,10 @@ SOURCE=..\crc32.c
# End Source File
# Begin Source File
SOURCE=.\dllpaths.c
# End Source File
# Begin Source File
SOURCE=.\exec.c
# End Source File
# Begin Source File
@ -180,6 +184,10 @@ SOURCE=.\config.h
# End Source File
# Begin Source File
SOURCE=.\dllpaths.h
# End Source File
# Begin Source File
SOURCE=.\exec.h
# End Source File
# Begin Source File

View file

@ -40,7 +40,7 @@ RSC=rc.exe
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O1 /Oy /D "_WINDOWS" /D "EXEHEAD" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "WIN32_LEAN_AND_MEAN" /D "NSIS_COMPRESS_USE_ZLIB" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# SUBTRACT CPP /Fr /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -152,6 +152,10 @@ SOURCE=..\crc32.c
# End Source File
# Begin Source File
SOURCE=.\dllpaths.c
# End Source File
# Begin Source File
SOURCE=.\exec.c
# End Source File
# Begin Source File

View file

@ -122,6 +122,8 @@ enum
EW_GETLABELADDR, // both of these get converted to EW_ASSIGNVAR
EW_GETFUNCTIONADDR,
EW_EXTERNALCOMMANDPREP,
EW_EXTERNALCOMMAND
};