diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index c77789ac..1fb80226 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -48,6 +48,9 @@ void Plugins::FindCommands(char* path,bool displayInfo) delete[] pathAndWildcard; delete[] basePath; } + + m_dataHandles.resize(m_funcsCount*sizeof(int)); + memset(m_dataHandles.get(), -1, m_funcsCount*sizeof(int)); } } @@ -115,9 +118,7 @@ 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); - char *dll = new char[lstrlen(dllName)]; - lstrcpy(dll, dllName); - m_storedDLLs.push_back(dll); + m_funcsCount++; if (displayInfo) fprintf(g_output, " - %s\n", signature); } @@ -133,12 +134,23 @@ void Plugins::GetExports(char* pathToDll,bool displayInfo) bool Plugins::IsPluginCommand(char* token) { - return GetPluginDll(token) ? true : false; + return GetPluginDll(token, 0) ? true : false; } -char* Plugins::GetPluginDll(char* command) +char* Plugins::GetPluginDll(char* command, int* dataHandle) { - return m_commands.find(command); + char* ret = m_commands.find(command, dataHandle); + if (dataHandle && ret) + *dataHandle = ((int*)m_dataHandles.get())[*dataHandle]; + return ret; +} + +void Plugins::SetDllDataHandle(char* command, int dataHandle) +{ + int idx = -1; + m_commands.find(command, &idx); + if (idx == -1) return; + ((int*)m_dataHandles.get())[idx] = dataHandle; } #endif \ No newline at end of file diff --git a/Source/Plugins.h b/Source/Plugins.h index 875b02fa..771510f9 100644 --- a/Source/Plugins.h +++ b/Source/Plugins.h @@ -14,17 +14,13 @@ class Plugins public: void FindCommands(char*,bool); bool IsPluginCommand(char*); - char* GetPluginDll(char*); - void StoreInstDLL(char*); - void StoreUninstDLL(char*); - char* GetInstDLL(int); - char* GetUninstDLL(int); + char* GetPluginDll(char*, int*); + void SetDllDataHandle(char*, int); protected: - DefineList m_commands; - std::vector m_storedDLLs; - std::vector m_installDLLs; - std::vector m_uninstallDLLs; + DefineList m_commands; + GrowBuf m_dataHandles; + int m_funcsCount; void GetExports(char*,bool); }; diff --git a/Source/build.h b/Source/build.h index 0f1d0d1a..02764368 100644 --- a/Source/build.h +++ b/Source/build.h @@ -84,7 +84,7 @@ class CEXEBuild { void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist); int doParse(const char *str, FILE *fp, const char *curfilename, int *lineptr); int doCommand(int which_token, LineParser &line, FILE *fp, const char *curfilename, int linecnt); - int do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override=0, int generatecode=1); + int do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override=0, int generatecode=1, int *data_handle=0); GrowBuf m_linebuild; // used for concatenating lines #ifdef NSIS_CONFIG_PLUGIN_SUPPORT diff --git a/Source/script.cpp b/Source/script.cpp index cc9f34a3..8a2279b9 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -3720,9 +3720,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char return PS_ERROR; case TOK__PLUGINCOMMAND: { - int ret; + int ret, data_handle; - char* dllPath = m_plugins.GetPluginDll(line.gettoken_str(0)); + char* dllPath = m_plugins.GetPluginDll(line.gettoken_str(0), &data_handle); if (dllPath) { if (uninstall_mode) uninst_plugin_used = true; @@ -3739,17 +3739,34 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char wsprintf(tempDLL, "$PLUGINSDIR%s", strrchr(dllPath,'\\')); // Add the DLL to the installer - int files_added; - int old_build_overwrite=build_overwrite; - build_overwrite=1; - ret=do_add_file(dllPath,0,0,0,&files_added,tempDLL,2); // 2 means no size add - if (ret != PS_OK) return ret; - build_overwrite=old_build_overwrite; + if (data_handle == -1) + { + int files_added; + int old_build_overwrite=build_overwrite; + build_overwrite=1; // off + int old_build_datesave=build_datesave; + build_datesave=0; // off + ret=do_add_file(dllPath,0,0,linecnt,&files_added,tempDLL,2,&data_handle); // 2 means no size add + if (ret != PS_OK) return ret; + m_plugins.SetDllDataHandle(line.gettoken_str(0),data_handle); + build_overwrite=old_build_overwrite; + build_datesave=old_build_datesave; + } + else + { + ent.which=EW_EXTRACTFILE; + ent.offsets[0]=1; // overwrite off + ent.offsets[1]=add_string(tempDLL); + ent.offsets[2]=data_handle; + ret=add_entry(&ent); + if (ret != PS_OK) return ret; + } // SetDetailsPrint lastused ent.which=EW_UPDATETEXT; ent.offsets[0]=0; ent.offsets[1]=8; // lastused + ent.offsets[2]=0; ret=add_entry(&ent); if (ret != PS_OK) return ret; @@ -3834,7 +3851,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char } #ifdef NSIS_SUPPORT_FILE -int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override, int generatecode) +int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override, int generatecode, int *data_handle) { char dir[1024]; char newfn[1024], *s; @@ -4009,6 +4026,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn return PS_ERROR; } + if (data_handle) + { + *data_handle=ent.offsets[2]; + } + { DWORD s=getcurdbsize()-last_build_datablock_used; if (s) s-=4; diff --git a/Source/strlist.h b/Source/strlist.h index dababe69..4f947ef9 100644 --- a/Source/strlist.h +++ b/Source/strlist.h @@ -186,13 +186,14 @@ public: return 0; } - char *find(const char *str) // returns NULL if not found + char *find(const char *str, int *idx=0) // returns NULL if not found { int id; int v=defines.find(str,0,&id); if (v<0) return NULL; v=values.idx2pos(id); if (v<0) return NULL; + if (idx) *idx=id; return (char*)values.get()+v; }