From 57ad3c18b3d54d6fcf248a7341231672a0e64d2c Mon Sep 17 00:00:00 2001 From: oripel Date: Sat, 27 Aug 2005 19:56:00 +0000 Subject: [PATCH] merged from PIEPIEPIE branch: - min/max macros removed - Plugins refactored - more functions in util.{h,cpp} git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4232 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/Platform.h | 6 - Source/Plugins.cpp | 245 ++++++++++++++++++-------------------- Source/Plugins.h | 39 +++--- Source/ResourceEditor.cpp | 1 + Source/ResourceEditor.h | 8 +- Source/build.cpp | 6 +- Source/clzma.cpp | 5 +- Source/growbuf.cpp | 6 +- Source/lang.cpp | 2 + Source/script.cpp | 241 ++++++++++++++++++------------------- Source/util.cpp | 36 ++++-- Source/util.h | 16 ++- 12 files changed, 300 insertions(+), 311 deletions(-) diff --git a/Source/Platform.h b/Source/Platform.h index 7190ea01..9aed59da 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -112,12 +112,6 @@ typedef WORD LANGID; // macros #ifndef _WIN32 -# ifndef min -# define min(x,y) ((xy)?x:y) -# endif # ifndef FIELD_OFFSET # define FIELD_OFFSET(t,f) ((LONG)&(((t*)0)->f)) # endif diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index 88208be0..47e8a3a0 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -1,9 +1,13 @@ #include "exehead/config.h" #ifdef NSIS_CONFIG_PLUGIN_SUPPORT +#include +#include + #include "Plugins.h" #include "Platform.h" #include "util.h" + #include "dirreader.h" #ifdef _WIN32 @@ -12,45 +16,12 @@ # include #endif +using namespace std; + extern FILE *g_output; -int PluginsList::add(const char *name, const char *path) +void Plugins::FindCommands(const string &path, bool displayInfo) { - int pos=SortedStringListND::add(name); - if (pos == -1) return 1; - - ((struct plugin*)gr.get())[pos].path=strings.add(path, strlen(path)+1); - ((struct plugin*)gr.get())[pos].dataHandle=-1; - ((struct plugin*)gr.get())[pos].unDataHandle=-1; - - return 0; -} - -char* PluginsList::get(char **name, int *dataHandle/*=0*/, int *uninstDataHandle/*=0*/) -{ - if (dataHandle) *dataHandle=-1; - if (uninstDataHandle) *uninstDataHandle=-1; - int v=SortedStringListND::find(*name); - if (v==-1) return NULL; - strcpy(*name, (char*)strings.get()+((struct plugin*)gr.get())[v].name); - if (dataHandle) *dataHandle=((struct plugin*)gr.get())[v].dataHandle; - if (uninstDataHandle) *uninstDataHandle=((struct plugin*)gr.get())[v].unDataHandle; - return (char*)strings.get()+((struct plugin*)gr.get())[v].path; -} - -void PluginsList::setDataHandle(const char *name, int dataHandle, int uninstDataHandle) -{ - int v=SortedStringListND::find(name); - if (v==-1) return; - ((struct plugin*)gr.get())[v].dataHandle=dataHandle; - ((struct plugin*)gr.get())[v].unDataHandle=uninstDataHandle; -} - -void Plugins::FindCommands(char* path, bool displayInfo) -{ - if (!path) - return; - dir_reader *dr = new_dir_reader(); dr->read(path); @@ -61,117 +32,129 @@ void Plugins::FindCommands(char* path, bool displayInfo) if (!dir_reader::matches(*files_itr, "*.dll")) continue; - string plugin = string(path) + PLATFORM_PATH_SEPARATOR_C + *files_itr; - - GetExports((char *) plugin.c_str(), displayInfo); + const string plugin = path + PLATFORM_PATH_SEPARATOR_C + *files_itr; + GetExports(plugin, displayInfo); } delete dr; } -void Plugins::GetExports(char* pathToDll, bool displayInfo) +void Plugins::GetExports(const string &pathToDll, bool displayInfo) { - if (pathToDll) + unsigned char* dlldata = 0; + bool loaded = false; + + string dllName = remove_file_extension(get_file_name(pathToDll)); + + FILE* dll = fopen(pathToDll.c_str() ,"rb"); + if (dll == NULL) + return; + + fseek(dll,0,SEEK_END); + long dlldatalen = ftell(dll); + fseek(dll,0,SEEK_SET); + if (dlldatalen > 0) { - unsigned char* dlldata = 0; - long dlldatalen = 0; - bool loaded = false; - char dllName[1024]; - char signature[1024]; + dlldata = new unsigned char [dlldatalen]; + assert(dlldata); - dllName[0] = 0; - char* ptr = strrchr(pathToDll,PLATFORM_PATH_SEPARATOR_C); - if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1); - - // find .dll - int len = strlen(dllName); - if (len > 4 && !stricmp(dllName + len - 4, ".dll")) - { - dllName[len - 4] = 0; - } - - FILE* dll = fopen(pathToDll,"rb"); - if (dll) - { - fseek(dll,0,SEEK_END); - dlldatalen = ftell(dll); - fseek(dll,0,SEEK_SET); - if (dlldatalen > 0) - { - dlldata = new unsigned char [dlldatalen]; - if (dlldata) - { - size_t bytesread = fread((void*)dlldata,1,dlldatalen,dll); - if ((long)bytesread == dlldatalen) - loaded = true; - } - } - fclose(dll); - } - - if (!loaded) - { - if (dlldata) delete[] dlldata; - return; - } - - PIMAGE_NT_HEADERS NTHeaders = PIMAGE_NT_HEADERS(dlldata + PIMAGE_DOS_HEADER(dlldata)->e_lfanew); - if (NTHeaders->Signature == IMAGE_NT_SIGNATURE) - { - if (NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) - { - if (NTHeaders->OptionalHeader.NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_EXPORT) return; - - DWORD ExportDirVA = NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; - DWORD ExportDirSize = NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; - PIMAGE_SECTION_HEADER sections = IMAGE_FIRST_SECTION(NTHeaders); - - for (int i = 0; i < NTHeaders->FileHeader.NumberOfSections; i++) - { - if (sections[i].VirtualAddress <= ExportDirVA - && sections[i].VirtualAddress+sections[i].Misc.VirtualSize >= ExportDirVA+ExportDirSize) - { - PIMAGE_EXPORT_DIRECTORY exports = PIMAGE_EXPORT_DIRECTORY(dlldata + sections[i].PointerToRawData + ExportDirVA - sections[i].VirtualAddress); - unsigned long *names = (unsigned long*)((unsigned long)exports + (char *)exports->AddressOfNames - ExportDirVA); - for (unsigned long j = 0; j < exports->NumberOfNames; j++) - { - char *name = (char*)exports + names[j] - ExportDirVA; - wsprintf(signature, "%s::%s", dllName, name); - m_list.add(signature, pathToDll); - if (displayInfo) - fprintf(g_output, " - %s\n", signature); - } - break; - } - } - } - } + size_t bytesread = fread((void*)dlldata,1,dlldatalen,dll); + if (bytesread == (size_t)dlldatalen) + loaded = true; + } + fclose(dll); + if (!loaded) + { delete[] dlldata; + return; + } + + PIMAGE_NT_HEADERS NTHeaders = PIMAGE_NT_HEADERS(dlldata + PIMAGE_DOS_HEADER(dlldata)->e_lfanew); + if (NTHeaders->Signature == IMAGE_NT_SIGNATURE) + { + if (NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) + { + if (NTHeaders->OptionalHeader.NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_EXPORT) return; + + DWORD ExportDirVA = NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; + DWORD ExportDirSize = NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; + PIMAGE_SECTION_HEADER sections = IMAGE_FIRST_SECTION(NTHeaders); + + for (int i = 0; i < NTHeaders->FileHeader.NumberOfSections; i++) + { + if (sections[i].VirtualAddress <= ExportDirVA + && sections[i].VirtualAddress+sections[i].Misc.VirtualSize >= ExportDirVA+ExportDirSize) + { + PIMAGE_EXPORT_DIRECTORY exports = PIMAGE_EXPORT_DIRECTORY(dlldata + sections[i].PointerToRawData + ExportDirVA - sections[i].VirtualAddress); + unsigned long *names = (unsigned long*)((unsigned long)exports + (char *)exports->AddressOfNames - ExportDirVA); + for (unsigned long j = 0; j < exports->NumberOfNames; j++) + { + const string name = string((char*)exports + names[j] - ExportDirVA); + const string signature = dllName + "::" + name; + m_command_to_path[signature] = pathToDll; + m_command_lowercase_to_command[lowercase(signature)] = signature; + if (displayInfo) + fprintf(g_output, " - %s\n", signature.c_str()); + } + break; + } + } + } + } + + delete[] dlldata; +} + +bool Plugins::IsPluginCommand(const string& token) const { + return m_command_to_path.find(NormalizedCommand(token)) != m_command_to_path.end(); +} + +namespace { +template +Value get_value(const map& the_map, + const Key& key) +{ + assert(the_map.find(key) != the_map.end()); + return the_map.find(key)->second; +} + +template +Value get_value(const map& the_map, + const Key& key, + const Value& defaultValue) +{ + if (the_map.find(key) == the_map.end()) + return defaultValue; + return the_map.find(key)->second; +} +} + +string Plugins::NormalizedCommand(const string& command) const { + return get_value(m_command_lowercase_to_command, lowercase(command)); +} + +int Plugins::GetPluginHandle(bool uninst, const string& command) const { + if (uninst) { + return get_value(m_command_to_uninstall_data_handle, command, -1); + } + else { + return get_value(m_command_to_data_handle, command, -1); } } -bool Plugins::IsPluginCommand(char* token) -{ - return m_list.get(&token) ? true : false; +string Plugins::GetPluginPath(const string& command) const { + return get_value(m_command_to_path, command); } -char* Plugins::GetPluginDll(int uninst, char** command, int* dataHandle) -{ - *dataHandle = -1; - - if (uninst) - return m_list.get(command, 0, dataHandle); - else - return m_list.get(command, dataHandle, 0); -} - -void Plugins::SetDllDataHandle(int uninst, char* command, int dataHandle) +void Plugins::SetDllDataHandle(bool uninst, const string& command, int dataHandle) { - if (uninst) - m_list.setDataHandle(command, -1, dataHandle); - else - m_list.setDataHandle(command, dataHandle, -1); + if (uninst) { + m_command_to_uninstall_data_handle[command] = dataHandle; + } + else { + m_command_to_data_handle[command] = dataHandle; + } } #endif diff --git a/Source/Plugins.h b/Source/Plugins.h index f7ded200..86542d82 100644 --- a/Source/Plugins.h +++ b/Source/Plugins.h @@ -1,36 +1,27 @@ #ifndef __X18_PLUGINS_H #define __X18_PLUGINS_H -#include "Platform.h" -#include "strlist.h" - -struct plugin { - int name; - int path; - int dataHandle; - int unDataHandle; -}; - -class PluginsList : public SortedStringListND -{ - public: - int add(const char *name, const char *path); - char *get(char **name, int *dataHandle=0, int *uninstDataHandle=0); - void setDataHandle(const char *name, int dataHandle, int uninstDataHandle); -}; +#include +#include class Plugins { public: - void FindCommands(char*,bool); - bool IsPluginCommand(char*); - char* GetPluginDll(int, char**, int*); - void SetDllDataHandle(int, char*, int); + void FindCommands(const std::string& path, bool displayInfo); + bool IsPluginCommand(const std::string& command) const; + std::string NormalizedCommand(const std::string& command) const; + int GetPluginHandle(bool uninst, const std::string& command) const; + std::string GetPluginPath(const std::string& command) const; + void SetDllDataHandle(bool uninst, const std::string& command, int dataHandle); - protected: - PluginsList m_list; + private: // methods + void GetExports(const std::string &pathToDll, bool displayInfo); - void GetExports(char*,bool); + private: // data members + std::map m_command_lowercase_to_command; + std::map m_command_to_path; + std::map m_command_to_data_handle; + std::map m_command_to_uninstall_data_handle; }; #endif diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index 8f1b663c..7d00e1bf 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -24,6 +24,7 @@ #include "util.h" #include #include +using namespace std; ////////////////////////////////////////////////////////////////////// // Utilities diff --git a/Source/ResourceEditor.h b/Source/ResourceEditor.h index d456d754..668c0108 100644 --- a/Source/ResourceEditor.h +++ b/Source/ResourceEditor.h @@ -23,12 +23,15 @@ #if !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_) #define AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_ + #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 -#include "Platform.h" + #include + +#include "Platform.h" #ifdef _WIN32 # include #else @@ -82,7 +85,6 @@ typedef struct _MY_IMAGE_RESOURCE_DIRECTORY_ENTRY { #pragma pack() #include -using namespace std; class CResourceDirectory; class CResourceDirectoryEntry; @@ -150,7 +152,7 @@ public: private: IMAGE_RESOURCE_DIRECTORY m_rdDir; - vector m_vEntries; + std::vector m_vEntries; }; class CResourceDirectoryEntry { diff --git a/Source/build.cpp b/Source/build.cpp index b281f7dc..82c6636a 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -8,8 +8,6 @@ #include -using namespace std; - #include "exehead/resource.h" #include "ResourceEditor.h" #include "DialogTemplate.h" @@ -31,6 +29,8 @@ using namespace std; return rc; \ } while (false) +using namespace std; + namespace { // begin anonymous namespace bool isSimpleChar(char ch) @@ -3154,7 +3154,7 @@ void CEXEBuild::build_plugin_table(void) { sprintf(searchPath,"%s" PLATFORM_PATH_SEPARATOR_STR "Plugins",nsisdir); INFO_MSG("Processing plugin dlls: \"%s" PLATFORM_PATH_SEPARATOR_STR "*.dll\"\n",searchPath); - m_plugins.FindCommands(searchPath,display_info?true:false); + m_plugins.FindCommands(searchPath, display_info); INFO_MSG("\n"); delete[] searchPath; } diff --git a/Source/clzma.cpp b/Source/clzma.cpp index 40b40485..d6725e3b 100644 --- a/Source/clzma.cpp +++ b/Source/clzma.cpp @@ -1,3 +1,4 @@ +#include // for std::min #include "clzma.h" #ifndef _WIN32 @@ -342,7 +343,7 @@ HRESULT CLZMA::ReadPart(void *data, UINT32 size, UINT32 *processedSize) if (compressor_finished) return E_ABORT; } - UINT32 l = min(size, avail_in); + UINT32 l = std::min(size, avail_in); memcpy(data, next_in, l); avail_in -= l; size -= l; @@ -371,7 +372,7 @@ HRESULT CLZMA::WritePart(const void *data, UINT32 size, UINT32 *processedSize) if (!avail_out) return E_ABORT; } - UINT32 l = min(size, avail_out); + UINT32 l = std::min(size, avail_out); memcpy(next_out, data, l); avail_out -= l; size -= l; diff --git a/Source/growbuf.cpp b/Source/growbuf.cpp index ecdfba7e..69c204af 100644 --- a/Source/growbuf.cpp +++ b/Source/growbuf.cpp @@ -1,9 +1,11 @@ #include "growbuf.h" -#include "Platform.h" #include // for malloc/free #include // for memcpy #include // for f* +#include // for std::min + +#include "Platform.h" GrowBuf::GrowBuf() { m_alloc=m_used=m_zero=0; m_s=NULL; m_bs=32768; } GrowBuf::~GrowBuf() { free(m_s); } @@ -49,7 +51,7 @@ void GrowBuf::resize(int newlen) } quit(); } - memcpy(n,m_s,min(newlen,os)); + memcpy(n,m_s,std::min(newlen,os)); free(m_s); } m_s=n; diff --git a/Source/lang.cpp b/Source/lang.cpp index a0c71664..fdc0222a 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -6,6 +6,8 @@ #include "DialogTemplate.h" #include "exehead/resource.h" +using namespace std; + // Default English strings. Should match NSIS_DEFAULT_LANG // Do not change the first string in every item, it's the LangString // name for usage in scripts. diff --git a/Source/script.cpp b/Source/script.cpp index 150733f3..fe28dfc6 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2495,7 +2495,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } string compressor_name = line.gettoken_str(a); - transform(compressor_name.begin(), compressor_name.end(), compressor_name.begin(), tolower); + compressor_name = lowercase(compressor_name); if (set_compressor(compressor_name, build_compress_whole) != PS_OK) { @@ -5413,10 +5413,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { SCRIPT_MSG("PluginDir: \"%s\"\n",line.gettoken_str(1)); #ifdef _WIN32 - m_plugins.FindCommands(line.gettoken_str(1),display_info?true:false); + m_plugins.FindCommands(line.gettoken_str(1), display_info); #else char *converted_path = my_convert(line.gettoken_str(1)); - m_plugins.FindCommands(converted_path,display_info?true:false); + m_plugins.FindCommands(converted_path, display_info); my_convert_free(converted_path); #endif return PS_OK; @@ -5425,136 +5425,125 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_ERROR; case TOK__PLUGINCOMMAND: { - int ret, data_handle; - char* command = strdup(line.gettoken_str(0)); - assert(command != 0); - MANAGE_WITH(command, free); + int ret; - char* dllPath = m_plugins.GetPluginDll(uninstall_mode, &command, &data_handle); - if (dllPath) + const string command = m_plugins.NormalizedCommand(line.gettoken_str(0)); + const string dllPath = m_plugins.GetPluginPath(command); + int data_handle = m_plugins.GetPluginHandle(uninstall_mode, command); + + if (uninstall_mode) uninst_plugin_used = true; + else plugin_used = true; + + // Initialize $PLUGINSDIR + 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]; + string dllName = get_file_name(dllPath); + wsprintf(tempDLL, "$PLUGINSDIR%c%s", PATH_SEPARATOR_C, dllName.c_str()); + + // Add the DLL to the installer + if (data_handle == -1) { - if (uninstall_mode) uninst_plugin_used = true; - else plugin_used = true; - - // Initialize $PLUGINSDIR - ent.which=EW_CALL; - ent.offsets[0]=ns_func.add(uninstall_mode?"un.Initialize_____Plugins":"Initialize_____Plugins",0); - ret=add_entry(&ent); + int files_added; + int old_build_allowskipfiles=build_allowskipfiles; + build_allowskipfiles=1; // on + 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.c_str(),0,0,&files_added,tempDLL,2,&data_handle); // 2 means no size add if (ret != PS_OK) { return ret; } - - // DLL name on the user machine - char tempDLL[NSIS_MAX_STRLEN]; - char *dllName = strrchr(dllPath,PLATFORM_PATH_SEPARATOR_C); - if (dllName && *dllName == PLATFORM_PATH_SEPARATOR_C) - dllName++; - wsprintf(tempDLL, "$PLUGINSDIR%c%s", PATH_SEPARATOR_C, dllName); - - // Add the DLL to the installer - if (data_handle == -1) - { - int files_added; - // BEGIN - Added by ramon 23 May 2003 - int old_build_allowskipfiles=build_allowskipfiles; - build_allowskipfiles=1; // on - // END - Added by ramon 23 May 2003 - 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,&files_added,tempDLL,2,&data_handle); // 2 means no size add - if (ret != PS_OK) { - return ret; - } - m_plugins.SetDllDataHandle(uninstall_mode, line.gettoken_str(0),data_handle); - build_overwrite=old_build_overwrite; - build_datesave=old_build_datesave; - // Added by ramon 23 May 2003 - build_allowskipfiles=old_build_allowskipfiles; - } - else - { - ent.which=EW_EXTRACTFILE; - - DefineInnerLangString(NLF_SKIPPED); - DefineInnerLangString(NLF_ERR_DECOMPRESSING); - DefineInnerLangString(NLF_ERR_WRITING); - DefineInnerLangString(NLF_EXTRACT); - DefineInnerLangString(NLF_CANT_WRITE); - - ent.offsets[0]=1; // overwrite off - ent.offsets[0]|=(MB_RETRYCANCEL|MB_ICONSTOP|(IDCANCEL<<21))<<3; - ent.offsets[1]=add_string(tempDLL); - ent.offsets[2]=data_handle; - ent.offsets[3]=0xffffffff; - ent.offsets[4]=0xffffffff; - ent.offsets[5]=DefineInnerLangString(NLF_FILE_ERROR); - 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; - } - - // Call the DLL - char* funcname = strstr(command,"::"); - if (funcname) funcname += 2; - else funcname = command; - SCRIPT_MSG("Plugin Command: %s",funcname); - - int i = 1; - int nounload = 0; - if (!strcmpi(line.gettoken_str(i), "/NOUNLOAD")) { - i++; - nounload++; - } - - // First push dll args - - int parmst=i; // we push em in reverse order - int nounloadmisused=0; - for (; i < line.getnumtokens(); i++) { - int w=parmst + (line.getnumtokens()-i - 1); - ent.which=EW_PUSHPOP; - ent.offsets[0]=add_string(line.gettoken_str(w)); - if (!strcmpi(line.gettoken_str(w), "/NOUNLOAD")) nounloadmisused=1; - ent.offsets[1]=0; - ret=add_entry(&ent); - if (ret != PS_OK) { - return ret; - } - SCRIPT_MSG(" %s",line.gettoken_str(i)); - } - SCRIPT_MSG("\n"); - if (nounloadmisused) - warning_fl("/NOUNLOAD must come first before any plugin parameter. Unless the plugin you are trying to use has a parameter /NOUNLOAD, you are doing something wrong"); - - // next, call it - ent.which=EW_REGISTERDLL; - ent.offsets[0]=add_string(tempDLL);; - ent.offsets[1]=add_string(funcname); - ent.offsets[2]=0; - ent.offsets[3]=nounload|build_plugin_unload; - ent.offsets[4]=1; - ret=add_entry(&ent); - if (ret != PS_OK) { - return ret; - } - - return PS_OK; + m_plugins.SetDllDataHandle(uninstall_mode, line.gettoken_str(0), data_handle); + build_overwrite=old_build_overwrite; + build_datesave=old_build_datesave; + // Added by ramon 23 May 2003 + build_allowskipfiles=old_build_allowskipfiles; } else - ERROR_MSG("Error: Plugin dll for command \"%s\" not found.\n",line.gettoken_str(0)); + { + ent.which=EW_EXTRACTFILE; + + DefineInnerLangString(NLF_SKIPPED); + DefineInnerLangString(NLF_ERR_DECOMPRESSING); + DefineInnerLangString(NLF_ERR_WRITING); + DefineInnerLangString(NLF_EXTRACT); + DefineInnerLangString(NLF_CANT_WRITE); + + ent.offsets[0]=1; // overwrite off + ent.offsets[0]|=(MB_RETRYCANCEL|MB_ICONSTOP|(IDCANCEL<<21))<<3; + ent.offsets[1]=add_string(tempDLL); + ent.offsets[2]=data_handle; + ent.offsets[3]=0xffffffff; + ent.offsets[4]=0xffffffff; + ent.offsets[5]=DefineInnerLangString(NLF_FILE_ERROR); + 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; + } + + // Call the DLL + string funcname = get_string_suffix(command, "::"); + SCRIPT_MSG("Plugin Command: %s",funcname.c_str()); + + int i = 1; + int nounload = 0; + if (!strcmpi(line.gettoken_str(i), "/NOUNLOAD")) { + i++; + nounload++; + } + + // First push dll args + + int parmst=i; // we push em in reverse order + int nounloadmisused=0; + for (; i < line.getnumtokens(); i++) { + int w=parmst + (line.getnumtokens()-i - 1); + ent.which=EW_PUSHPOP; + ent.offsets[0]=add_string(line.gettoken_str(w)); + if (!strcmpi(line.gettoken_str(w), "/NOUNLOAD")) nounloadmisused=1; + ent.offsets[1]=0; + ret=add_entry(&ent); + if (ret != PS_OK) { + return ret; + } + SCRIPT_MSG(" %s",line.gettoken_str(i)); + } + SCRIPT_MSG("\n"); + if (nounloadmisused) + warning_fl("/NOUNLOAD must come first before any plugin parameter. Unless the plugin you are trying to use has a parameter /NOUNLOAD, you are doing something wrong"); + + // next, call it + ent.which=EW_REGISTERDLL; + ent.offsets[0]=add_string(tempDLL);; + ent.offsets[1]=add_string(funcname.c_str()); + ent.offsets[2]=0; + ent.offsets[3]=nounload|build_plugin_unload; + ent.offsets[4]=1; + ret=add_entry(&ent); + if (ret != PS_OK) { + return ret; + } + + return PS_OK; } return PS_ERROR; case TOK_INITPLUGINSDIR: diff --git a/Source/util.cpp b/Source/util.cpp index 74663129..5525c6b2 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -16,7 +16,7 @@ #include // for assert -using std::string; +using namespace std; int g_dopause=0; extern int g_display_errors; @@ -611,18 +611,26 @@ string get_full_path(const string &path) { #endif//_WIN32 } -string get_dir_name(const string& path) { - string::size_type last_separator_pos = path.rfind(PLATFORM_PATH_SEPARATOR_C); +string get_string_prefix(const string& str, const string& separator) { + const string::size_type last_separator_pos = str.rfind(separator); if (last_separator_pos == string::npos) - return path; - return path.substr(0, last_separator_pos); + return str; + return str.substr(0, last_separator_pos); +} + +string get_string_suffix(const string& str, const string& separator) { + const string::size_type last_separator_pos = str.rfind(separator); + if (last_separator_pos == string::npos) + return str; + return str.substr(last_separator_pos + separator.size(), string::npos); +} + +string get_dir_name(const string& path) { + return get_string_prefix(path, PLATFORM_PATH_SEPARATOR_STR); } string get_file_name(const string& path) { - string::size_type last_separator_pos = path.rfind(PLATFORM_PATH_SEPARATOR_C); - if (last_separator_pos == string::npos) - return path; - return path.substr(last_separator_pos + 1, string::npos); + return get_string_suffix(path, PLATFORM_PATH_SEPARATOR_STR); } string get_executable_path(const char* argv0) { @@ -640,3 +648,13 @@ string get_executable_path(const char* argv0) { string get_executable_dir(const char *argv0) { return get_dir_name(get_executable_path(argv0)); } + +string remove_file_extension(const string& path) { + return get_string_prefix(path, "."); +} + +string lowercase(const string &str) { + string result = str; + transform(str.begin(), str.end(), result.begin(), tolower); + return result; +} diff --git a/Source/util.h b/Source/util.h index 7259fdde..94b2f305 100644 --- a/Source/util.h +++ b/Source/util.h @@ -1,16 +1,17 @@ #ifndef _UTIL_H_ #define _UTIL_H_ +#include // for std::string + +#include "boost/scoped_ptr.hpp" // for boost::scoped_ptr +#include "ResourceEditor.h" + #ifndef _WIN32 # include # include # include #endif -#include "ResourceEditor.h" -#include // for std::string - -#include "boost/scoped_ptr.hpp" // for boost::scoped_ptr // these are the standard pause-before-quit shit. extern int g_dopause; @@ -49,10 +50,15 @@ size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm); (((x)&0x0000FF00) << 8) | \ (((x)&0x000000FF) << 24) ) -std::string get_full_path(const std::string &path); +std::string get_full_path(const std::string& path); std::string get_dir_name(const std::string& path); std::string get_file_name(const std::string& path); std::string get_executable_dir(const char *argv0); +std::string remove_file_extension(const std::string& path); +std::string lowercase(const std::string&); + +std::string get_string_prefix(const std::string& str, const std::string& separator); +std::string get_string_suffix(const std::string& str, const std::string& separator); #ifndef _WIN32 char *CharPrev(const char *s, const char *p);