Change loading plugin list location

Loading plugin list location is changed from %LOCALAPPDATA%\Notepad++\plugins\Config\ to
%PROGRAMDATA%\Notepad++\plugins\Config\

Enhance API NPPM_GETPLUGINSCONFIGDIR
This commit is contained in:
Don HO 2018-12-04 13:38:25 +01:00
parent 4f67c09859
commit 775d204ef9
6 changed files with 34 additions and 48 deletions

View File

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

View File

@ -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<size_t>(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<TCHAR *>(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<TCHAR *>(lParam);
lstrcpy(pluginsConfigDir, pluginsConfigDirPrefix.c_str());
::PathAppend(pluginsConfigDir, secondPart);
return TRUE;
// For the retro-compatibility
return TRUE;
}
return userPluginConfDir.length();
}
case NPPM_GETPLUGINHOMEPATH:

View File

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

View File

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

View File

@ -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<PluginUpdateInfo*>& puis)
{
generic_string opStr;

View File

@ -188,7 +188,6 @@ public :
bool updateListAndLoadFromJson();
void setAdminMode(bool isAdm) { _nppCurrentStatus._isAdminMode = isAdm; };
generic_string getPluginConfigPath() const;
bool installPlugins();
bool updatePlugins();