- Plug-in command can now come in any order in the script

- Second plug-in DLL doesn't produce errors anymore
- Infinite loop bug fixed (again)


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@678 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-08-09 22:12:10 +00:00
parent bc6494155b
commit 0b31694486
8 changed files with 153 additions and 83 deletions

View file

@ -1,5 +1,5 @@
!define VER_MAJOR 2
!define VER_MINOR 0a5
!define VER_MINOR 0a6
!ifdef NO_COMPRESSION
SetCompress off

View file

@ -113,9 +113,9 @@ void Plugins::GetExports(char* pathToDll,bool displayInfo)
char *name = (char*)exports + names[j] - ExportDirVA;
wsprintf(signature, "%s::%s", dllName, name);
m_commands.add(signature, pathToDll);
DLL newDll = {new char[lstrlen(dllName)], false};
lstrcpy(newDll.name, dllName);
m_storedDLLs.push_back(newDll);
char *dll = new char[lstrlen(dllName)];
lstrcpy(dll, dllName);
m_storedDLLs.push_back(dll);
if (displayInfo)
fprintf(g_output, " - %s\n", signature);
}
@ -156,22 +156,32 @@ char* Plugins::GetPluginDll(char* command)
return 0;
}
void Plugins::DLLStored(char* dllName)
void Plugins::StoreInstDLL(char* dllName)
{
for (int i = 0; i < m_storedDLLs.size(); i++) {
if (!strcmp(m_storedDLLs[i].name, dllName)) {
m_storedDLLs[i].stored = true;
for (int i = 0; i < m_installDLLs.size(); i++)
if (!strcmp(m_installDLLs[i], dllName))
return;
}
}
m_installDLLs.push_back(strdup(dllName));
}
bool Plugins::IsDLLStored(char* dllName)
void Plugins::StoreUninstDLL(char* dllName)
{
for (int i = 0; i < m_storedDLLs.size(); i++)
if (!strcmp(m_storedDLLs[i].name, dllName))
return m_storedDLLs[i].stored;
return false;
for (int i = 0; i < m_uninstallDLLs.size(); i++)
if (!strcmp(m_uninstallDLLs[i], dllName))
return;
m_uninstallDLLs.push_back(strdup(dllName));
}
char* Plugins::GetInstDLL(int i)
{
if (i >= 0 && i < m_installDLLs.size()) return m_installDLLs[i];
else return 0;
}
char* Plugins::GetUninstDLL(int i)
{
if (i >= 0 && i < m_uninstallDLLs.size()) return m_uninstallDLLs[i];
else return 0;
}
#endif

View file

@ -9,23 +9,22 @@
#include "strlist.h"
#include <vector>
struct DLL {
char *name;
bool stored;
};
class Plugins
{
public:
void FindCommands(char*,bool);
bool IsPluginCommand(char*);
char* GetPluginDll(char*);
void DLLStored(char*);
bool IsDLLStored(char*);
void StoreInstDLL(char*);
void StoreUninstDLL(char*);
char* GetInstDLL(int);
char* GetUninstDLL(int);
protected:
DefineList m_commands;
std::vector<DLL> m_storedDLLs;
DefineList m_commands;
std::vector<char*> m_storedDLLs;
std::vector<char*> m_installDLLs;
std::vector<char*> m_uninstallDLLs;
void GetExports(char*,bool);
};

View file

@ -1054,6 +1054,12 @@ int CEXEBuild::write_output(void)
return PS_ERROR;
}
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
// Added by Amir Szekely 9th August 2002
int err=add_plugin_initializer();
if (err != PS_OK) return err;
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
// Added by Amir Szekely 3rd August 2002
if (WriteStringTables() == PS_ERROR) return PS_ERROR;
@ -1849,4 +1855,99 @@ void CEXEBuild::build_plugin_table(void)
}
}
}
int CEXEBuild::add_plugin_initializer(void)
{
if (!plugin_used) return PS_OK;
SCRIPT_MSG("Adding plug-ins initializing function...\n");
bool uninstall = false;
int ret, i;
entry ent;
int zero_offset;
ret=add_function("Initialize_____Plugins");
if (ret != PS_OK) return ret;
again:
zero_offset=add_string("$0");
// StrCmp $PLUGINSDIR ""
ent.which=EW_STRCMP;
ent.offsets[0]=add_string("$PLUGINSDIR");
ent.offsets[1]=add_string("");
ent.offsets[2]=0;
ent.offsets[3]=ns_label.add("Initialize_____Plugins_done",0);
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Push $0
ent.which=EW_PUSHPOP;
ent.offsets[0]=zero_offset;
ent.offsets[1]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Get temp file name
ent.which=EW_GETTEMPFILENAME;
ent.offsets[0]=0; // $0
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Delete the temp file created
ent.which=EW_DELETEFILE;
ent.offsets[0]=zero_offset;
ent.offsets[1]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Craete a dir instead of that temp file
ent.which=EW_CREATEDIR;
ent.offsets[0]=zero_offset;
ent.offsets[1]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Copy $0 to $PLUGINSDIR
ent.which=EW_PLUGINCOMMANDPREP;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Pop $0
ent.which=EW_PUSHPOP;
ent.offsets[0]=0; // $0
ent.offsets[1]=1;
ent.offsets[2]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
int files_added;
if (uninstall) {
char* dll;
for (i = 0; dll = m_plugins.GetUninstDLL(i); i++) {
char tempPath[NSIS_MAX_STRLEN];
wsprintf(tempPath,"$PLUGINSDIR%s",strrchr(dll,'\\'));
ret=do_add_file(dll,0,0,0,&files_added,tempPath);
if (ret != PS_OK) return ret;
}
}
else {
char* dll;
for (i = 0; dll = m_plugins.GetInstDLL(i); i++) {
char tempPath[NSIS_MAX_STRLEN];
wsprintf(tempPath,"$PLUGINSDIR%s",strrchr(dll,'\\'));
ret=do_add_file(dll,0,0,0,&files_added,tempPath);
if (ret != PS_OK) return ret;
}
}
if (add_label("Initialize_____Plugins_done")) return PS_ERROR;
ret=function_end();
if (ret != PS_OK) return ret;
if (uninstaller_writes_used && !uninstall) {
add_function("un.Initialize_____Plugins");
uninstall = true;
goto again;
}
SCRIPT_MSG("Done!\n");
return PS_OK;
}
#endif // NSIS_CONFIG_PLUGIN_SUPPORT

View file

@ -85,6 +85,11 @@ class CEXEBuild {
int do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override=0);
GrowBuf m_linebuild; // used for concatenating lines
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
// Added by Amir Szekely 9th August 2002
int add_plugin_initializer(void);
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
void ERROR_MSG(const char *s, ...);
void SCRIPT_MSG(const char *s, ...);
void INFO_MSG(const char *s, ...);

View file

@ -300,7 +300,7 @@ int ui_doinstall(void)
{
// Added by Amir Szekely 3rd August 2002
// Multilingual support
char pa=1;
char pa=0;
int num=g_inst_header->str_tables_num;
LANGID user_lang=GetUserDefaultLangID();
int size=num*sizeof(common_strings);
@ -327,14 +327,14 @@ lang_again:
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
cur_uninstall_strings_table+=size;
#endif
pa--;
pa++;
break;
}
common_strings_tables[size].lang_id&=0x3ff; // primary lang
}
if (pa) {
if (!pa) {
user_lang&=0x3ff; // primary lang
pa--;
pa++;
goto lang_again;
}
}

View file

@ -1,4 +1,4 @@
const char *NSIS_VERSION="v2.0a5";
const char *NSIS_VERSION="v2.0a6";
/*
Nullsoft "SuperPimp" Installation System - makensis.cpp - installer compiler code

View file

@ -3296,71 +3296,26 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
return PS_ERROR;
case TOK__PLUGINCOMMAND:
{
static int zero_offset;
if (!zero_offset) zero_offset=add_string("$0");
int ret;
char* dllPath = m_plugins.GetPluginDll(line.gettoken_str(0));
if (dllPath)
{
if (!plugin_used) {
// If no plugin was called up until now init the plugin stuff
// Push $0
ent.which=EW_PUSHPOP;
ent.offsets[0]=zero_offset;
ent.offsets[1]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Get temp file name
ent.which=EW_GETTEMPFILENAME;
ent.offsets[0]=0; // $0
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Delete the temp file created
ent.which=EW_DELETEFILE;
ent.offsets[0]=zero_offset;
ent.offsets[1]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Craete a dir instead of that temp file
ent.which=EW_CREATEDIR;
ent.offsets[0]=zero_offset;
ent.offsets[1]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Copy $0 to $PLUGINSDIR
ent.which=EW_PLUGINCOMMANDPREP;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// Pop $0
ent.which=EW_PUSHPOP;
ent.offsets[0]=0; // $0
ent.offsets[1]=1;
ent.offsets[2]=0;
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// We need to do all of this only once
plugin_used = true;
}
plugin_used = true;
ent.which=EW_CALL;
ent.offsets[0]=ns_func.add(uninstall_mode?"un.Initialize_____Plugins":"Initialize_____Plugins",0);
ret=add_entry(&ent);
if (ret != PS_OK) return ret;
// DLL name on the user machine
char tempDLL[NSIS_MAX_STRLEN];
wsprintf(tempDLL, "$PLUGINSDIR%s", strrchr(dllPath,'\\'));
int tempDLLtab = add_string(tempDLL);
// Add the DLL if not already added
if (!m_plugins.IsDLLStored(strrchr(dllPath,'\\')+1))
{
int error;
int files_added;
if (PS_OK != (error = do_add_file(dllPath,0,0,0,&files_added,tempDLL)))
{
ERROR_MSG("Error: Failed to auto include plugin file \"%s\"\n",dllPath);
return error;
}
m_plugins.DLLStored(strrchr(dllPath,'\\')+1);
}
// Store the DLL
if (uninstall_mode) m_plugins.StoreUninstDLL(dllPath);
else m_plugins.StoreInstDLL(dllPath);
// Finally call the DLL
char* command = strstr(line.gettoken_str(0),"::");