Skip to content

Commit

Permalink
[MODIF_BEHAVIOUR] Make plugins in %APPDATA%/Notepad++/plugins/ overri…
Browse files Browse the repository at this point in the history
…de les plugins in Notepad++ installation directory.

- Notepad-plus svn trunk @ 844
  • Loading branch information
donho committed Nov 16, 2011
1 parent 2271f33 commit f69964d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
12 changes: 7 additions & 5 deletions PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ bool PluginsManager::unloadPlugin(int index, HWND nppHandle)

int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_string> & dll2Remove)
{
const TCHAR *pluginFileName = ::PathFindFileName(pluginFilePath);
if (isInLoadedDlls(pluginFileName))
return 0;

PluginInfo *pi = new PluginInfo;
try {
pi->_moduleName = PathFindFileName(pluginFilePath);
Expand Down Expand Up @@ -181,7 +185,7 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin
::SendMessage(_nppData._scintillaMainHandle, SCI_LOADLEXERLIBRARY, 0, (LPARAM)pDllName);

}

addInLoadedDlls(pluginFileName);
_pluginInfos.push_back(pi);
return (_pluginInfos.size() - 1);
} catch(std::exception e) {
Expand Down Expand Up @@ -217,8 +221,8 @@ bool PluginsManager::loadPlugins(const TCHAR *dir)

vector<generic_string> dllNames;
vector<generic_string> dll2Remove;
generic_string nppPath = (NppParameters::getInstance())->getNppPath();

NppParameters * nppParams = NppParameters::getInstance();
generic_string nppPath = nppParams->getNppPath();
generic_string pluginsFullPathFilter = (dir && dir[0])?dir:nppPath;

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

NppParameters * nppParams = NppParameters::getInstance();

while (::FindNextFile(hFindFile, &foundData))
{
bool isInBlackList = nppParams->isInBlackList(foundData.cFileName);
Expand Down
11 changes: 11 additions & 0 deletions PowerEditor/src/MISC/PluginsManager/PluginsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class PluginsManager {

vector<PluginInfo *> _pluginInfos;
vector<PluginCommand> _pluginsCommands;
vector<generic_string> _loadedDlls;
bool _isDisabled;
IDAllocator _dynamicIDAlloc;
IDAllocator _markerAlloc;
Expand All @@ -129,6 +130,16 @@ class PluginsManager {
msg += funcSignature;
::MessageBox(NULL, msg.c_str(), TEXT(" just crash in\r"), MB_OK|MB_ICONSTOP);
};
bool isInLoadedDlls(const TCHAR *fn) const {
for (size_t i = 0; i < _loadedDlls.size(); i++)
if (generic_stricmp(fn, _loadedDlls[i].c_str()) == 0)
return true;
return false;
};

void addInLoadedDlls(const TCHAR *fn) {
_loadedDlls.push_back(fn);
};
};

#define EXT_LEXER_DECL __stdcall
Expand Down
10 changes: 9 additions & 1 deletion PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,19 @@ LRESULT Notepad_plus::init(HWND hwnd)

_scintillaCtrls4Plugins.init(_pPublicInterface->getHinst(), hwnd);
_pluginsManager.init(nppData);
_pluginsManager.loadPlugins();

// Load plugins firstly from "%APPDATA%/Notepad++/plugins"
// if Notepad++ is not in localConf mode.
// All the dll loaded are marked.
const TCHAR *appDataNpp = pNppParam->getAppDataNppDir();
if (appDataNpp[0])
_pluginsManager.loadPlugins(appDataNpp);

// Load plugins from its installation directory.
// All loaded dll will be ignored
_pluginsManager.loadPlugins();


_restoreButton.init(_pPublicInterface->getHinst(), hwnd);


Expand Down
8 changes: 4 additions & 4 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,11 +771,11 @@ bool NppParameters::load()
PathAppend(localConfPath, localConfFile);

// Test if localConf.xml exist
bool isLocal = (PathFileExists(localConfPath.c_str()) == TRUE);
_isLocal = (PathFileExists(localConfPath.c_str()) == TRUE);

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

if (lstrcmp(progPath, nppDirLocation) == 0)
isLocal = false;
_isLocal = false;
}
}

if (isLocal)
if (_isLocal)
{
_userPath = _nppPath;
}
Expand Down
5 changes: 5 additions & 0 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,10 @@ class NppParameters
_pNativeLangSpeaker = nls;
};

bool isLocal() const {
return _isLocal;
};

private:
NppParameters();
~NppParameters();
Expand Down Expand Up @@ -1478,6 +1482,7 @@ class NppParameters

WNDPROC _transparentFuncAddr;
WNDPROC _enableThemeDialogTextureFuncAddr;
bool _isLocal;


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

0 comments on commit f69964d

Please sign in to comment.