From 3325da03a0bad59527a778a4aa0601bd1db3ef06 Mon Sep 17 00:00:00 2001 From: Don HO Date: Sun, 19 Aug 2018 18:04:16 +0200 Subject: [PATCH] Fix a plugin installation problem Add a new plugins loadding behaviour: if it's not doLocalConf mode, then plugins can be loadded from "AppData\Local\Notepad++\plugins\", without presence of "allowAppDataPlugins.xml". --- PowerEditor/src/EncodingMapper.h | 4 +- PowerEditor/src/Notepad_plus.cpp | 42 +++++----- PowerEditor/src/NppBigSwitch.cpp | 6 +- PowerEditor/src/Parameters.cpp | 82 +++++++++++++------ .../src/WinControls/FileBrowser/fileBrowser.h | 5 +- .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 24 ++++-- 6 files changed, 98 insertions(+), 65 deletions(-) diff --git a/PowerEditor/src/EncodingMapper.h b/PowerEditor/src/EncodingMapper.h index aa5c3d32d..2f8679339 100644 --- a/PowerEditor/src/EncodingMapper.h +++ b/PowerEditor/src/EncodingMapper.h @@ -26,8 +26,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -#ifndef ENCODINGMAPPER_H -#define ENCODINGMAPPER_H +#pragma once struct EncodingUnit { int _codePage; @@ -48,4 +47,3 @@ private: EncodingUnit *_encodings; }; -#endif // ENCODINGMAPPER_H diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 1e395497b..f5dacbc50 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -235,7 +235,7 @@ LRESULT Notepad_plus::init(HWND hwnd) int tabBarStatus = nppGUI._tabStatus; _toReduceTabBar = ((tabBarStatus & TAB_REDUCE) != 0); - int iconDpiDynamicalSize = NppParameters::getInstance()->_dpiManager.scaleY(_toReduceTabBar?13:20); + int iconDpiDynamicalSize = pNppParam->_dpiManager.scaleY(_toReduceTabBar?13:20); _docTabIconList.create(iconDpiDynamicalSize, _pPublicInterface->getHinst(), docTabIconIDs, sizeof(docTabIconIDs)/sizeof(int)); _mainDocTab.init(_pPublicInterface->getHinst(), hwnd, &_mainEditView, &_docTabIconList); @@ -345,8 +345,8 @@ LRESULT Notepad_plus::init(HWND hwnd) ::SendMessage(_mainDocTab.getHSelf(), WM_SETFONT, reinterpret_cast(hf), MAKELPARAM(TRUE, 0)); ::SendMessage(_subDocTab.getHSelf(), WM_SETFONT, reinterpret_cast(hf), MAKELPARAM(TRUE, 0)); } - int tabDpiDynamicalHeight = NppParameters::getInstance()->_dpiManager.scaleY(22); - int tabDpiDynamicalWidth = NppParameters::getInstance()->_dpiManager.scaleX(45); + int tabDpiDynamicalHeight = pNppParam->_dpiManager.scaleY(22); + int tabDpiDynamicalWidth = pNppParam->_dpiManager.scaleX(45); TabCtrl_SetItemSize(_mainDocTab.getHSelf(), tabDpiDynamicalWidth, tabDpiDynamicalHeight); TabCtrl_SetItemSize(_subDocTab.getHSelf(), tabDpiDynamicalWidth, tabDpiDynamicalHeight); } @@ -370,11 +370,11 @@ LRESULT Notepad_plus::init(HWND hwnd) //--Status Bar Section--// bool willBeShown = nppGUI._statusBarShow; _statusBar.init(_pPublicInterface->getHinst(), hwnd, 6); - _statusBar.setPartWidth(STATUSBAR_DOC_SIZE, NppParameters::getInstance()->_dpiManager.scaleX(200)); - _statusBar.setPartWidth(STATUSBAR_CUR_POS, NppParameters::getInstance()->_dpiManager.scaleX(260)); - _statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, NppParameters::getInstance()->_dpiManager.scaleX(110)); - _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, NppParameters::getInstance()->_dpiManager.scaleX(120)); - _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, NppParameters::getInstance()->_dpiManager.scaleX(30)); + _statusBar.setPartWidth(STATUSBAR_DOC_SIZE, pNppParam->_dpiManager.scaleX(200)); + _statusBar.setPartWidth(STATUSBAR_CUR_POS, pNppParam->_dpiManager.scaleX(260)); + _statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, pNppParam->_dpiManager.scaleX(110)); + _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, pNppParam->_dpiManager.scaleX(120)); + _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, pNppParam->_dpiManager.scaleX(30)); _statusBar.display(willBeShown); _pMainWindow = &_mainDocTab; @@ -398,26 +398,26 @@ LRESULT Notepad_plus::init(HWND hwnd) _scintillaCtrls4Plugins.init(_pPublicInterface->getHinst(), hwnd); _pluginsManager.init(nppData); - // If Notepad++ is not in localConf mode, load plugins firstly from "%APPDATA%/Notepad++/plugins" + // If Notepad++ is not in localConf mode, load plugins firstly from "%APPDATA%/Local/Notepad++/plugins" // All the dll loaded are marked. - bool isLoadFromAppDataAllow = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETAPPDATAPLUGINSALLOWED, 0, 0) == TRUE; - - const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); - if (appDataNpp[0] && isLoadFromAppDataAllow) - _pluginsManager.loadPlugins(appDataNpp); - generic_string localAppDataNppPluginsDir = pNppParam->getLocalAppDataNppDir(); - if (!localAppDataNppPluginsDir.empty() && isLoadFromAppDataAllow) + if (!localAppDataNppPluginsDir.empty() && !pNppParam->isLocal()) { PathAppend(localAppDataNppPluginsDir, TEXT("plugins")); _pluginsManager.loadPluginsV2(localAppDataNppPluginsDir.c_str()); } + // obsolet + bool isLoadFromAppDataAllow = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETAPPDATAPLUGINSALLOWED, 0, 0) == TRUE; + const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); + if (appDataNpp[0] && isLoadFromAppDataAllow) + _pluginsManager.loadPlugins(appDataNpp); + + // Load plugins from its installation directory. // All loaded dll will be ignored - _pluginsManager.loadPlugins(); _pluginsManager.loadPluginsV2(); - + _pluginsManager.loadPlugins(); // obsolet _restoreButton.init(_pPublicInterface->getHinst(), hwnd); @@ -691,13 +691,13 @@ LRESULT Notepad_plus::init(HWND hwnd) // Initialize the default foreground & background color // { - StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers(); + StyleArray & globalStyles = pNppParam->getGlobalStylers(); int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT); if (i != -1) { Style & style = globalStyles.getStyler(i); - (NppParameters::getInstance())->setCurrentDefaultFgColor(style._fgColor); - (NppParameters::getInstance())->setCurrentDefaultBgColor(style._bgColor); + pNppParam->setCurrentDefaultFgColor(style._fgColor); + pNppParam->setCurrentDefaultBgColor(style._bgColor); } } diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index a780ce3ea..a24ed01bc 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2263,10 +2263,10 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return _pFileSwitcherPanel->isVisible(); } - case NPPM_GETAPPDATAPLUGINSALLOWED: - { + case NPPM_GETAPPDATAPLUGINSALLOWED: // if doLocal, it's always false - having doLocal environment cannot load plugins outside + { // the presence of file "allowAppDataPlugins.xml" will be checked only when not doLocal const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); - if (appDataNpp[0]) + if (appDataNpp[0]) // if not doLocal { generic_string allowAppDataPluginsPath(pNppParam->getNppPath()); PathAppend(allowAppDataPluginsPath, allowAppDataPluginsFile); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index e60c9408a..6ab7e06f9 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -890,14 +890,20 @@ bool NppParameters::reloadStylers(TCHAR* stylePath) bool loadOkay = _pXmlUserStylerDoc->LoadFile(); if (!loadOkay) { - _pNativeLangSpeaker->messageBox("LoadStylersFailed", - NULL, - TEXT("Load \"$STR_REPLACE$\" failed!"), - TEXT("Load stylers.xml failed"), - MB_OK, - 0, - stylePathToLoad); - + if (!_pNativeLangSpeaker) + { + ::MessageBox(NULL, stylePathToLoad, TEXT("Load stylers.xml failed"), MB_OK); + } + else + { + _pNativeLangSpeaker->messageBox("LoadStylersFailed", + NULL, + TEXT("Load \"$STR_REPLACE$\" failed!"), + TEXT("Load stylers.xml failed"), + MB_OK, + 0, + stylePathToLoad); + } delete _pXmlUserStylerDoc; _pXmlUserStylerDoc = NULL; return false; @@ -1079,12 +1085,23 @@ bool NppParameters::load() WIN32_FILE_ATTRIBUTE_DATA attributes; if (GetFileAttributesEx(langs_xml_path.c_str(), GetFileExInfoStandard, &attributes) != 0) + { if (attributes.nFileSizeLow == 0 && attributes.nFileSizeHigh == 0) - doRecover = _pNativeLangSpeaker->messageBox("LoadLangsFailed", - NULL, - TEXT("Load langs.xml failed!\rDo you want to recover your langs.xml?"), - TEXT("Configurator"), - MB_YESNO); + { + if (_pNativeLangSpeaker) + { + doRecover = _pNativeLangSpeaker->messageBox("LoadLangsFailed", + NULL, + TEXT("Load langs.xml failed!\rDo you want to recover your langs.xml?"), + TEXT("Configurator"), + MB_YESNO); + } + else + { + doRecover = ::MessageBox(NULL, TEXT("Load langs.xml failed!\rDo you want to recover your langs.xml?"), TEXT("Configurator"), MB_YESNO); + } + } + } } else doRecover = true; @@ -1102,11 +1119,18 @@ bool NppParameters::load() bool loadOkay = _pXmlDoc->LoadFile(); if (!loadOkay) { - _pNativeLangSpeaker->messageBox("LoadLangsFailedFinal", - NULL, - TEXT("Load langs.xml failed!"), - TEXT("Configurator"), - MB_OK); + if (_pNativeLangSpeaker) + { + _pNativeLangSpeaker->messageBox("LoadLangsFailedFinal", + NULL, + TEXT("Load langs.xml failed!"), + TEXT("Configurator"), + MB_OK); + } + else + { + ::MessageBox(NULL, TEXT("Load langs.xml failed!"), TEXT("Configurator"), MB_OK); + } delete _pXmlDoc; _pXmlDoc = nullptr; @@ -1163,14 +1187,20 @@ bool NppParameters::load() loadOkay = _pXmlUserStylerDoc->LoadFile(); if (!loadOkay) { - _pNativeLangSpeaker->messageBox("LoadStylersFailed", - NULL, - TEXT("Load \"$STR_REPLACE$\" failed!"), - TEXT("Load stylers.xml failed"), - MB_OK, - 0, - _stylerPath.c_str()); - + if (_pNativeLangSpeaker) + { + _pNativeLangSpeaker->messageBox("LoadStylersFailed", + NULL, + TEXT("Load \"$STR_REPLACE$\" failed!"), + TEXT("Load stylers.xml failed"), + MB_OK, + 0, + _stylerPath.c_str()); + } + else + { + ::MessageBox(NULL, _stylerPath.c_str(), TEXT("Load stylers.xml failed"), MB_OK); + } delete _pXmlUserStylerDoc; _pXmlUserStylerDoc = NULL; isAllLaoded = false; diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h index e78a4d9a9..39c0108ee 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h @@ -26,8 +26,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -#ifndef FILEBROWSER_H -#define FILEBROWSER_H +#pragma once //#include #ifndef DOCKINGDLGINTERFACE_H @@ -179,5 +178,3 @@ protected: void getDirectoryStructure(const TCHAR *dir, const std::vector & patterns, FolderInfo & directoryStructure, bool isRecursive, bool isInHiddenDir); HTREEITEM createFolderItemsFromDirStruct(HTREEITEM hParentItem, const FolderInfo & directoryStructure); }; - -#endif // FILEBROWSER_H diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index f80cc0529..4e7fdf9fc 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -384,8 +384,18 @@ bool PluginsAdminDlg::installPlugins() vector puis = _availableList.fromUiIndexesToPluginInfos(indexes); generic_string updaterParams = TEXT("-unzipTo "); + NppParameters *pNppParameters = NppParameters::getInstance(); + generic_string nppPluginsDir; + + if (pNppParameters->isLocal()) + { + nppPluginsDir = pNppParameters->getNppPath(); + } + else + { + nppPluginsDir = pNppParameters->getLocalAppDataNppDir(); + } - generic_string nppPluginsDir = NppParameters::getInstance()->getUserPath(); PathAppend(nppPluginsDir, TEXT("plugins")); if (!::PathFileExists(nppPluginsDir.c_str())) @@ -393,13 +403,13 @@ bool PluginsAdminDlg::installPlugins() ::CreateDirectory(nppPluginsDir.c_str(), NULL); } + generic_string quoted_nppPluginsDir = TEXT("\""); + quoted_nppPluginsDir += nppPluginsDir; + quoted_nppPluginsDir += TEXT("\""); + for (auto i : puis) { - // add folder to operate - generic_string destFolder = nppPluginsDir; - PathAppend(destFolder, i->_folderName); - - updaterParams += destFolder; + updaterParams += quoted_nppPluginsDir; // add zipFile's url updaterParams += TEXT(" "); @@ -407,8 +417,6 @@ bool PluginsAdminDlg::installPlugins() Process updater(_updaterFullPath.c_str(), updaterParams.c_str(), _updaterDir.c_str()); - printStr(updaterParams.c_str()); - printStr(_updaterDir.c_str()); int result = updater.runSync(); if (result == 0) // wingup return 0 -> OK {