From 0d1e06dd2d3b8ddafb8a3e19f498b09892e54d6f Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 1 Jul 2005 21:24:32 +0000 Subject: [PATCH] use dir_reader for Plugins::FindCommands git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4153 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/Plugins.cpp | 73 +++++++++------------------------------------- 1 file changed, 14 insertions(+), 59 deletions(-) diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index a6201b02..88208be0 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -4,12 +4,12 @@ #include "Plugins.h" #include "Platform.h" #include "util.h" +#include "dirreader.h" #ifdef _WIN32 # include #else # include -# include #endif extern FILE *g_output; @@ -48,70 +48,25 @@ void PluginsList::setDataHandle(const char *name, int dataHandle, int uninstData void Plugins::FindCommands(char* path, bool displayInfo) { - if (path) - { - int length = strlen(path); + if (!path) + return; - if (length > 0) - { - char *lc = CharPrev(path, path + strlen(path)); - if (*lc == '\\' || *lc == '/') - { - length--; - } + dir_reader *dr = new_dir_reader(); + dr->read(path); - char* basePath = new char [length+1]; - strncpy(basePath,path,length); - basePath[length] = 0; + dir_reader::iterator files_itr = dr->files().begin(); + dir_reader::iterator files_end = dr->files().end(); - char* pathAndWildcard = new char [length+7]; - strcpy(pathAndWildcard,basePath); - strcat(pathAndWildcard,PLATFORM_PATH_SEPARATOR_STR "*.dll"); + for (; files_itr != files_end; files_itr++) { + if (!dir_reader::matches(*files_itr, "*.dll")) + continue; -#ifdef _WIN32 - WIN32_FIND_DATA data; - HANDLE handle; + string plugin = string(path) + PLATFORM_PATH_SEPARATOR_C + *files_itr; - handle = FindFirstFile(pathAndWildcard,&data); - if (handle != INVALID_HANDLE_VALUE) - { - do -#else - glob_t globbuf; - globbuf.gl_offs = 0; - globbuf.gl_pathc = 0; - if (!glob(pathAndWildcard, 0, NULL, &globbuf)) - { - struct stat s; - for (unsigned int i = 0; i < globbuf.gl_pathc; i++) - { - if (stat(globbuf.gl_pathv[i], &s) || !S_ISREG(s.st_mode)) - continue; -#endif -#ifdef _WIN32 - { - char* dllPath = new char [length+strlen(data.cFileName)+2]; - wsprintf(dllPath,"%s" PLATFORM_PATH_SEPARATOR_STR "%s",basePath,data.cFileName); -#else - char *dllPath = new char [strlen(globbuf.gl_pathv[i])+1]; - strcpy(dllPath,globbuf.gl_pathv[i]); -#endif - GetExports(dllPath,displayInfo); - delete[] dllPath; - } -#ifdef _WIN32 - while (FindNextFile(handle,&data)); -#else - globfree(&globbuf); -#endif - } - -#ifdef _WIN32 - delete[] pathAndWildcard; -#endif - delete[] basePath; - } + GetExports((char *) plugin.c_str(), displayInfo); } + + delete dr; } void Plugins::GetExports(char* pathToDll, bool displayInfo)