Skip to content

Commit f69964d

Browse files
committed
[MODIF_BEHAVIOUR] Make plugins in %APPDATA%/Notepad++/plugins/ override les plugins in Notepad++ installation directory.
- Notepad-plus svn trunk @ 844
1 parent 2271f33 commit f69964d

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ bool PluginsManager::unloadPlugin(int index, HWND nppHandle)
4747

4848
int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_string> & dll2Remove)
4949
{
50+
const TCHAR *pluginFileName = ::PathFindFileName(pluginFilePath);
51+
if (isInLoadedDlls(pluginFileName))
52+
return 0;
53+
5054
PluginInfo *pi = new PluginInfo;
5155
try {
5256
pi->_moduleName = PathFindFileName(pluginFilePath);
@@ -181,7 +185,7 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin
181185
::SendMessage(_nppData._scintillaMainHandle, SCI_LOADLEXERLIBRARY, 0, (LPARAM)pDllName);
182186

183187
}
184-
188+
addInLoadedDlls(pluginFileName);
185189
_pluginInfos.push_back(pi);
186190
return (_pluginInfos.size() - 1);
187191
} catch(std::exception e) {
@@ -217,8 +221,8 @@ bool PluginsManager::loadPlugins(const TCHAR *dir)
217221

218222
vector<generic_string> dllNames;
219223
vector<generic_string> dll2Remove;
220-
generic_string nppPath = (NppParameters::getInstance())->getNppPath();
221-
224+
NppParameters * nppParams = NppParameters::getInstance();
225+
generic_string nppPath = nppParams->getNppPath();
222226
generic_string pluginsFullPathFilter = (dir && dir[0])?dir:nppPath;
223227

224228
pluginsFullPathFilter += TEXT("\\plugins\\*.dll");
@@ -232,8 +236,6 @@ bool PluginsManager::loadPlugins(const TCHAR *dir)
232236
plugins1stFullPath += foundData.cFileName;
233237
dllNames.push_back(plugins1stFullPath);
234238

235-
NppParameters * nppParams = NppParameters::getInstance();
236-
237239
while (::FindNextFile(hFindFile, &foundData))
238240
{
239241
bool isInBlackList = nppParams->isInBlackList(foundData.cFileName);

PowerEditor/src/MISC/PluginsManager/PluginsManager.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class PluginsManager {
120120

121121
vector<PluginInfo *> _pluginInfos;
122122
vector<PluginCommand> _pluginsCommands;
123+
vector<generic_string> _loadedDlls;
123124
bool _isDisabled;
124125
IDAllocator _dynamicIDAlloc;
125126
IDAllocator _markerAlloc;
@@ -129,6 +130,16 @@ class PluginsManager {
129130
msg += funcSignature;
130131
::MessageBox(NULL, msg.c_str(), TEXT(" just crash in\r"), MB_OK|MB_ICONSTOP);
131132
};
133+
bool isInLoadedDlls(const TCHAR *fn) const {
134+
for (size_t i = 0; i < _loadedDlls.size(); i++)
135+
if (generic_stricmp(fn, _loadedDlls[i].c_str()) == 0)
136+
return true;
137+
return false;
138+
};
139+
140+
void addInLoadedDlls(const TCHAR *fn) {
141+
_loadedDlls.push_back(fn);
142+
};
132143
};
133144

134145
#define EXT_LEXER_DECL __stdcall

PowerEditor/src/Notepad_plus.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,19 @@ LRESULT Notepad_plus::init(HWND hwnd)
341341

342342
_scintillaCtrls4Plugins.init(_pPublicInterface->getHinst(), hwnd);
343343
_pluginsManager.init(nppData);
344-
_pluginsManager.loadPlugins();
344+
345+
// Load plugins firstly from "%APPDATA%/Notepad++/plugins"
346+
// if Notepad++ is not in localConf mode.
347+
// All the dll loaded are marked.
345348
const TCHAR *appDataNpp = pNppParam->getAppDataNppDir();
346349
if (appDataNpp[0])
347350
_pluginsManager.loadPlugins(appDataNpp);
348351

352+
// Load plugins from its installation directory.
353+
// All loaded dll will be ignored
354+
_pluginsManager.loadPlugins();
355+
356+
349357
_restoreButton.init(_pPublicInterface->getHinst(), hwnd);
350358

351359

PowerEditor/src/Parameters.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,11 @@ bool NppParameters::load()
771771
PathAppend(localConfPath, localConfFile);
772772

773773
// Test if localConf.xml exist
774-
bool isLocal = (PathFileExists(localConfPath.c_str()) == TRUE);
774+
_isLocal = (PathFileExists(localConfPath.c_str()) == TRUE);
775775

776776
// Under vista and windows 7, the usage of doLocalConf.xml is not allowed
777777
// if Notepad++ is installed in "program files" directory, because of UAC
778-
if (isLocal)
778+
if (_isLocal)
779779
{
780780
// We check if OS is Vista or above
781781
if (_winVersion >= WV_VISTA)
@@ -789,11 +789,11 @@ bool NppParameters::load()
789789
::PathRemoveFileSpec(nppDirLocation);
790790

791791
if (lstrcmp(progPath, nppDirLocation) == 0)
792-
isLocal = false;
792+
_isLocal = false;
793793
}
794794
}
795795

796-
if (isLocal)
796+
if (_isLocal)
797797
{
798798
_userPath = _nppPath;
799799
}

PowerEditor/src/Parameters.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,10 @@ class NppParameters
14221422
_pNativeLangSpeaker = nls;
14231423
};
14241424

1425+
bool isLocal() const {
1426+
return _isLocal;
1427+
};
1428+
14251429
private:
14261430
NppParameters();
14271431
~NppParameters();
@@ -1478,6 +1482,7 @@ class NppParameters
14781482

14791483
WNDPROC _transparentFuncAddr;
14801484
WNDPROC _enableThemeDialogTextureFuncAddr;
1485+
bool _isLocal;
14811486

14821487

14831488
vector<CommandShortcut> _shortcuts; //main menu shortuts. Static size

0 commit comments

Comments
 (0)