From 93a5fa4c1c732b7bf236cd703ae517684dc37744 Mon Sep 17 00:00:00 2001 From: kichik Date: Thu, 8 Aug 2002 16:35:53 +0000 Subject: [PATCH] Sunjammer's code is now fully optimized git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@668 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/Plugins.cpp | 28 +++++++++++++++------------- Source/Plugins.h | 10 +++++++--- Source/script.cpp | 8 ++++---- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index 0dff74d3..76725055 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -111,8 +111,11 @@ void Plugins::GetExports(char* pathToDll,bool displayInfo) for (unsigned long j = 0; j < exports->NumberOfNames; j++) { char *name = (char*)exports + names[j] - ExportDirVA; - wsprintf(signature,"%s::%s", dllName, name); + 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); if (displayInfo) fprintf(g_output, " - %s\n", signature); } @@ -153,23 +156,22 @@ char* Plugins::GetPluginDll(char* command) return 0; } -void Plugins::StoreDllDataHandle(char* signature,int handle) +void Plugins::DLLStored(char* dllName) { - int idx = -1; - m_commands.defines.find(signature,0,&idx); - if (idx > -1) - { - m_dataHandles.reserve(idx+1); - m_dataHandles[idx] = handle; + for (int i = 0; i < m_storedDLLs.size(); i++) { + if (!strcmp(m_storedDLLs[i].name, dllName)) { + m_storedDLLs[i].stored = true; + return; + } } } -int Plugins::GetDllDataHandle(char* signature) +bool Plugins::IsDLLStored(char* dllName) { - int idx = -1; - if (-1 != m_commands.defines.find(signature,0,&idx)) - return m_dataHandles[idx]; - return -1; + for (int i = 0; i < m_storedDLLs.size(); i++) + if (!strcmp(m_storedDLLs[i].name, dllName)) + return m_storedDLLs[i].stored; + return false; } #endif \ No newline at end of file diff --git a/Source/Plugins.h b/Source/Plugins.h index 9f920b17..42d57b83 100644 --- a/Source/Plugins.h +++ b/Source/Plugins.h @@ -9,6 +9,10 @@ #include "strlist.h" #include +struct DLL { + char *name; + bool stored; +}; class Plugins { @@ -16,12 +20,12 @@ class Plugins void FindCommands(char*,bool); bool IsPluginCommand(char*); char* GetPluginDll(char*); - int GetDllDataHandle(char*); - void StoreDllDataHandle(char*,int); + void DLLStored(char*); + bool IsDLLStored(char*); protected: DefineList m_commands; - std::vector m_dataHandles; + std::vector m_storedDLLs; void GetExports(char*,bool); }; diff --git a/Source/script.cpp b/Source/script.cpp index 36612965..a4fe8074 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -3336,19 +3336,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char if (ret != PS_OK) return ret; // Add the DLL if not already added - int dataHandle = m_plugins.GetDllDataHandle(dllPath); - if (dataHandle == -1) + if (!m_plugins.IsDLLStored(strrchr(dllPath,'\\')+1)) { int error; + int files_added; char file[NSIS_MAX_STRLEN]; wsprintf(file,"$0\\%s",strrchr(dllPath,'\\')+1); - if (PS_OK != (error = do_add_file(dllPath,0,0,0,&dataHandle,file))) + if (PS_OK != (error = do_add_file(dllPath,0,0,0,&files_added,file))) { ERROR_MSG("Error: Failed to auto include plugin file \"%s\"\n",dllPath); return error; } - m_plugins.StoreDllDataHandle(line.gettoken_str(0),dataHandle); + m_plugins.DLLStored(strrchr(dllPath,'\\')+1); } if (!plugin_used) {