diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index fda67b8a..306c109c 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -180,7 +180,11 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 }; //BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) #define NPPM_GETPLUGINSCONFIGDIR (NPPMSG + 46) - //void NPPM_GETPLUGINSCONFIGDIR(int strLen, TCHAR *str) + //INT NPPM_GETPLUGINSCONFIGDIR(int strLen, TCHAR *str) + // Get user's plugin config directory path. It's useful if plugins want to save/load parameters for the current user + // Returns the number of TCHAR copied/to copy. + // Users should call it with "str" be NULL to get the required number of TCHAR (not including the terminating nul character), + // allocate "str" buffer with the return value + 1, then call it again to get the path. #define NPPM_MSGTOPLUGIN (NPPMSG + 47) //BOOL NPPM_MSGTOPLUGIN(TCHAR *destModuleName, CommunicationInfo *info) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index bf4a3096..538b3368 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2040,25 +2040,21 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_GETPLUGINSCONFIGDIR: { - if (!lParam || !wParam) - return FALSE; + generic_string userPluginConfDir = pNppParam->getUserPluginConfDir(); + if (lParam != 0) + { + if (userPluginConfDir.length() >= static_cast(wParam)) + { + // Not message for users so no translation + ::MessageBox(hwnd, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETPLUGINSCONFIGDIR error"), MB_OK); + return 0; + } + lstrcpy(reinterpret_cast(lParam), userPluginConfDir.c_str()); - generic_string pluginsConfigDirPrefix = pNppParam->getAppDataNppDir(); - - if (pluginsConfigDirPrefix == TEXT("")) - pluginsConfigDirPrefix = pNppParam->getNppPath(); - - const TCHAR *secondPart = TEXT("plugins\\Config"); - - size_t len = wParam; - if (len < pluginsConfigDirPrefix.length() + lstrlen(secondPart)) - return FALSE; - - TCHAR *pluginsConfigDir = reinterpret_cast(lParam); - lstrcpy(pluginsConfigDir, pluginsConfigDirPrefix.c_str()); - - ::PathAppend(pluginsConfigDir, secondPart); - return TRUE; + // For the retro-compatibility + return TRUE; + } + return userPluginConfDir.length(); } case NPPM_GETPLUGINHOMEPATH: diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 83ab510f..3d370a8a 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1019,13 +1019,18 @@ bool NppParameters::load() _pluginRootDir = _nppPath; PathAppend(_pluginRootDir, TEXT("plugins")); + + _userPluginConfDir = _pluginRootDir; + PathAppend(_userPluginConfDir, TEXT("Config")); } else { _userPath = getSpecialFolderLocation(CSIDL_APPDATA); PathAppend(_userPath, TEXT("Notepad++")); - _appdataNppDir = _userPath; + _appdataNppDir = _userPluginConfDir = _userPath; + PathAppend(_userPluginConfDir, TEXT("plugins")); + PathAppend(_userPluginConfDir, TEXT("Config")); if (!PathFileExists(_userPath.c_str())) ::CreateDirectory(_userPath.c_str(), NULL); @@ -1040,6 +1045,9 @@ bool NppParameters::load() setElevationRequired(true); } + _pluginConfDir = _pluginRootDir; + PathAppend(_pluginConfDir, TEXT("Config")); + if (!PathFileExists(nppPluginRootParent.c_str())) ::CreateDirectory(nppPluginRootParent.c_str(), NULL); if (!PathFileExists(_pluginRootDir.c_str())) diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 18f7da15..6e1ee46a 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1494,6 +1494,8 @@ public: generic_string getContextMenuPath() const {return _contextMenuPath;}; const TCHAR * getAppDataNppDir() const {return _appdataNppDir.c_str();}; const TCHAR * getPluginRootDir() const { return _pluginRootDir.c_str(); }; + const TCHAR * getPluginConfDir() const { return _pluginConfDir.c_str(); }; + const TCHAR * getUserPluginConfDir() const { return _userPluginConfDir.c_str(); }; const TCHAR * getWorkingDir() const {return _currentDirectory.c_str();}; const TCHAR * getWorkSpaceFilePath(int i) const { if (i < 0 || i > 2) return nullptr; @@ -1724,7 +1726,9 @@ 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 _pluginRootDir; + generic_string _pluginRootDir; // plugins root where all the plugins are installed + generic_string _pluginConfDir; // plugins config dir where the plugin list is installed + generic_string _userPluginConfDir; // plugins config dir for per user where the plugin parameters are saved / loaded generic_string _currentDirectory; generic_string _workSpaceFilePathes[3]; diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index c97c33f6..d5cfb038 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -427,7 +427,7 @@ PluginsAdminDlg::PluginsAdminDlg() PathAppend(_updaterFullPath, TEXT("gup.exe")); // get plugin-list path - _pluginListFullPath = getPluginConfigPath(); + _pluginListFullPath = pNppParameters->getPluginConfDir(); #ifdef DEBUG // if not debug, then it's release // load from nppPluginList.json instead of nppPluginList.dll @@ -437,31 +437,6 @@ PluginsAdminDlg::PluginsAdminDlg() #endif } -generic_string PluginsAdminDlg::getPluginConfigPath() const -{ - NppParameters *pNppParameters = NppParameters::getInstance(); - generic_string nppPluginsConfDir; - - if (pNppParameters->isLocal()) - { - nppPluginsConfDir = pNppParameters->getNppPath(); - } - else - { - nppPluginsConfDir = pNppParameters->getAppDataNppDir(); - } - - PathAppend(nppPluginsConfDir, TEXT("plugins")); - PathAppend(nppPluginsConfDir, TEXT("Config")); - - if (!::PathFileExists(nppPluginsConfDir.c_str())) - { - ::CreateDirectory(nppPluginsConfDir.c_str(), NULL); - } - - return nppPluginsConfDir; -} - bool PluginsAdminDlg::exitToInstallRemovePlugins(Operation op, const vector& puis) { generic_string opStr; diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h index 7651cd62..594f4cdc 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h @@ -188,7 +188,6 @@ public : bool updateListAndLoadFromJson(); void setAdminMode(bool isAdm) { _nppCurrentStatus._isAdminMode = isAdm; }; - generic_string getPluginConfigPath() const; bool installPlugins(); bool updatePlugins();