diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 33fb0b83..b6c1eb2a 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -343,6 +343,73 @@ bool PluginsManager::loadPlugins(const TCHAR *dir) return true; } +bool PluginsManager::loadPluginsV2(const TCHAR* dir) +{ + if (_isDisabled || !dir || !dir[0]) + return false; + + NppParameters * nppParams = NppParameters::getInstance(); + + vector dllNames; + vector dll2Remove; + + generic_string pluginsFolderFilter = dir; + PathAppend(pluginsFolderFilter, TEXT("*.*")); + + WIN32_FIND_DATA foundData; + HANDLE hFindFolder = ::FindFirstFile(pluginsFolderFilter.c_str(), &foundData); + HANDLE hFindDll = INVALID_HANDLE_VALUE; + if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + generic_string pluginsFullPathFilter = dir; + PathAppend(pluginsFullPathFilter, foundData.cFileName); + generic_string pluginsFolderPath = pluginsFullPathFilter; + PathAppend(pluginsFullPathFilter, TEXT("*.dll")); + + hFindDll = ::FindFirstFile(pluginsFullPathFilter.c_str(), &foundData); + if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + generic_string pluginsFullPath = pluginsFolderPath; + PathAppend(pluginsFullPath, foundData.cFileName); + dllNames.push_back(pluginsFullPath); + + PluginList & pl = nppParams->getPluginList(); + pl.add(foundData.cFileName, false); + } + + while (::FindNextFile(hFindFolder, &foundData)) + { + + generic_string pluginsFullPathFilter2 = dir; + PathAppend(pluginsFullPathFilter2, foundData.cFileName); + generic_string pluginsFolderPath2 = pluginsFullPathFilter2; + PathAppend(pluginsFullPathFilter2, TEXT("*.dll")); + + hFindDll = ::FindFirstFile(pluginsFullPathFilter2.c_str(), &foundData); + if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + generic_string pluginsFullPath2 = pluginsFolderPath2; + PathAppend(pluginsFullPath2, foundData.cFileName); + dllNames.push_back(pluginsFullPath2); + + PluginList & pl = nppParams->getPluginList(); + pl.add(foundData.cFileName, false); + } + } + + } + ::FindClose(hFindFolder); + ::FindClose(hFindDll); + + + for (size_t i = 0, len = dllNames.size(); i < len; ++i) + { + loadPlugin(dllNames[i].c_str(), dll2Remove); + } + + return true; +} + // return true if cmdID found and its shortcut is enable // false otherwise bool PluginsManager::getShortcutByCmdID(int cmdID, ShortcutKey *sk) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index 801be58d..28d9832d 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -101,6 +101,7 @@ public: int loadPlugin(const TCHAR *pluginFilePath, std::vector & dll2Remove); bool loadPlugins(const TCHAR *dir = NULL); + bool loadPluginsV2(const TCHAR *dir); bool unloadPlugin(int index, HWND nppHandle); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 81d16e99..b53f4f22 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -404,6 +404,13 @@ LRESULT Notepad_plus::init(HWND hwnd) if (appDataNpp[0] && isLoadFromAppDataAllow) _pluginsManager.loadPlugins(appDataNpp); + generic_string localAppDataNppPluginsDir = pNppParam->getLocalAppDataNppDir(); + if (!localAppDataNppPluginsDir.empty() && isLoadFromAppDataAllow) + { + PathAppend(localAppDataNppPluginsDir, TEXT("plugins")); + _pluginsManager.loadPluginsV2(localAppDataNppPluginsDir.c_str()); + } + // Load plugins from its installation directory. // All loaded dll will be ignored _pluginsManager.loadPlugins(); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index f2043cc6..468345c0 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1035,6 +1035,11 @@ bool NppParameters::load() if (!PathFileExists(_userPath.c_str())) ::CreateDirectory(_userPath.c_str(), NULL); } + + _localAppdataNppDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA); + PathAppend(_localAppdataNppDir, TEXT("Notepad++")); + if (!PathFileExists(_localAppdataNppDir.c_str())) + ::CreateDirectory(_localAppdataNppDir.c_str(), NULL); _sessionPath = _userPath; // Session stock the absolute file path, it should never be on cloud diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 32ff7d6e..4eb8fee4 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1466,6 +1466,7 @@ public: generic_string getNppPath() const {return _nppPath;}; generic_string getContextMenuPath() const {return _contextMenuPath;}; const TCHAR * getAppDataNppDir() const {return _appdataNppDir.c_str();}; + const TCHAR * getLocalAppDataNppDir() const { return _localAppdataNppDir.c_str(); }; const TCHAR * getWorkingDir() const {return _currentDirectory.c_str();}; const TCHAR * getWorkSpaceFilePath(int i) const { if (i < 0 || i > 2) return nullptr; @@ -1680,6 +1681,7 @@ private: generic_string _userPath; generic_string _stylerPath; generic_string _appdataNppDir; // sentinel of the absence of "doLocalConf.xml" : (_appdataNppDir == TEXT(""))?"doLocalConf.xml present":"doLocalConf.xml absent" + generic_string _localAppdataNppDir; // for plugins generic_string _currentDirectory; generic_string _workSpaceFilePathes[3];