Make plugins loadable from %LOCALAPPDATA%\Notepad++\plugins\

This commit is contained in:
Don HO 2017-07-09 15:56:18 +02:00
parent 19f24d1d65
commit 2c9f096d6d
5 changed files with 82 additions and 0 deletions

View File

@ -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<generic_string> dllNames;
vector<generic_string> 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)

View File

@ -101,6 +101,7 @@ public:
int loadPlugin(const TCHAR *pluginFilePath, std::vector<generic_string> & dll2Remove);
bool loadPlugins(const TCHAR *dir = NULL);
bool loadPluginsV2(const TCHAR *dir);
bool unloadPlugin(int index, HWND nppHandle);

View File

@ -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();

View File

@ -1036,6 +1036,11 @@ bool NppParameters::load()
::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
// Detection cloud settings

View File

@ -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];