From 7e555b67fca6347c1e09e491c7465f76c6d8ae6c Mon Sep 17 00:00:00 2001 From: Don HO <don.h@free.fr> Date: Sat, 3 Nov 2018 12:39:23 +0100 Subject: [PATCH] Remove the legasy plugin loading way and apply only the new plugin loading method 1. Load plugins only from the new plugin folder structure. example: Notepad++\plugins\myAwesomePlugin\myAwesomePlugin.dll 2. Load plugins from only one directory. If doLocalConf.xml is present, then it will be <NPP_INSTALLATION_DIR>\plugins\ otherwise %USERPROFILE%\AppData\Local\Notepad++\plugins\ --- .../MISC/PluginsManager/PluginsManager.cpp | 60 ------------------- .../src/MISC/PluginsManager/PluginsManager.h | 1 - PowerEditor/src/Notepad_plus.cpp | 19 ++---- 3 files changed, 6 insertions(+), 74 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 5a4413979..eb8a0b037 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -289,67 +289,11 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin } } - -bool PluginsManager::loadPlugins(const TCHAR *dir) -{ - if (_isDisabled) - return false; - - vector<generic_string> dllNames; - vector<generic_string> dll2Remove; - NppParameters * nppParams = NppParameters::getInstance(); - generic_string nppPath = nppParams->getNppPath(); - generic_string pluginsFullPathFilter = (dir && dir[0])?dir:nppPath; - - pluginsFullPathFilter += TEXT("\\plugins\\*.dll"); - - WIN32_FIND_DATA foundData; - HANDLE hFindFile = ::FindFirstFile(pluginsFullPathFilter.c_str(), &foundData); - if (hFindFile != INVALID_HANDLE_VALUE) - { - generic_string plugins1stFullPath = (dir && dir[0])?dir:nppPath; - plugins1stFullPath += TEXT("\\plugins\\"); - plugins1stFullPath += foundData.cFileName; - dllNames.push_back(plugins1stFullPath); - - while (::FindNextFile(hFindFile, &foundData)) - { - bool isInBlackList = nppParams->isInBlackList(foundData.cFileName); - if (!isInBlackList) - { - generic_string fullPath = (dir && dir[0])?dir:nppPath; - fullPath += TEXT("\\plugins\\"); - - fullPath += foundData.cFileName; - dllNames.push_back(fullPath); - } - PluginList & pl = nppParams->getPluginList(); - pl.add(foundData.cFileName, isInBlackList); - } - ::FindClose(hFindFile); - - - for (size_t i = 0, len = dllNames.size(); i < len ; ++i) - { - loadPlugin(dllNames[i].c_str(), dll2Remove); - } - - } - - for (size_t j = 0, len = dll2Remove.size() ; j < len ; ++j) - ::DeleteFile(dll2Remove[j].c_str()); - - std::sort(_pluginInfos.begin(), _pluginInfos.end(), [](const PluginInfo *a, const PluginInfo *b) { return a->_funcName < b->_funcName; }); - - return true; -} - bool PluginsManager::loadPluginsV2(const TCHAR* dir) { if (_isDisabled) return false; - vector<generic_string> dllNames; vector<generic_string> dll2Remove; @@ -517,10 +461,6 @@ void PluginsManager::addInMenuFromPMIndex(int i) if (_pluginInfos[i]->_funcItems[j]._init2Check) ::CheckMenuItem(_hPluginsMenu, cmdID, MF_BYCOMMAND | MF_CHECKED); } - /*UNLOAD - ::InsertMenu(_pluginInfos[i]->_pluginMenu, j++, MF_BYPOSITION | MF_SEPARATOR, 0, TEXT("")); - ::InsertMenu(_pluginInfos[i]->_pluginMenu, j, MF_BYPOSITION, ID_PLUGINS_REMOVING + i, TEXT("Remove this plugin")); - */ } HMENU PluginsManager::setMenu(HMENU hMenu, const TCHAR *menuName, bool enablePluginAdmin) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index f47c5e75e..db5a03e39 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -100,7 +100,6 @@ public: } int loadPlugin(const TCHAR *pluginFilePath, std::vector<generic_string> & dll2Remove); - bool loadPlugins(const TCHAR *dir = NULL); bool loadPluginsV2(const TCHAR *dir = NULL); bool unloadPlugin(int index, HWND nppHandle); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 968950f1f..fc63a94fc 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -406,19 +406,12 @@ LRESULT Notepad_plus::init(HWND hwnd) PathAppend(localAppDataNppPluginsDir, TEXT("plugins")); _pluginsManager.loadPluginsV2(localAppDataNppPluginsDir.c_str()); } - - // obsolet - bool isLoadFromAppDataAllow = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETAPPDATAPLUGINSALLOWED, 0, 0) == TRUE; - const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); - if (appDataNpp[0] && isLoadFromAppDataAllow) - _pluginsManager.loadPlugins(appDataNpp); - - - // Load plugins from its installation directory. - // All loaded dll will be ignored - _pluginsManager.loadPluginsV2(); - _pluginsManager.loadPlugins(); // obsolet - + else // localConf mode + { + // Load plugins from its installation directory. + // All loaded dll will be ignored + _pluginsManager.loadPluginsV2(); + } _restoreButton.init(_pPublicInterface->getHinst(), hwnd);