From 14074e14872642490c7e9e6483e06f87b3d3e07d Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 27 Dec 2019 00:35:16 +0500 Subject: [PATCH] Disable file association settings when Notepad++'s no admin right File association feature under Windows 10 needs the Administrator's preivilege. This commit add an explicit message to users who want to use this feature, and disable this feature if Notepad++ has no Administrator's preivilege. Fix #4984, fix #5192, fix #4542 --- PowerEditor/src/MISC/RegExt/regExtDlg.cpp | 24 +++++++++++++++-------- PowerEditor/src/MISC/RegExt/regExtDlg.rc | 2 +- PowerEditor/src/MISC/RegExt/regExtDlgRc.h | 2 +- PowerEditor/src/Notepad_plus.cpp | 11 ++++++----- PowerEditor/src/Parameters.h | 4 ++++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp index 1b568a6d6..73ecfd444 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp @@ -27,6 +27,7 @@ #include "Common.h" #include "regExtDlg.h" #include "resource.h" +#include "Parameters.h" @@ -78,10 +79,6 @@ const TCHAR defExtArray[nbSupportedLang][nbExtMax][extNameMax] = {TEXT("customize")} }; - - - - void RegExtDlg::doDialog(bool isRTL) { if (isRTL) @@ -95,7 +92,6 @@ void RegExtDlg::doDialog(bool isRTL) ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, dlgProc, reinterpret_cast(this)); } - INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) @@ -104,10 +100,23 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar { getRegisteredExts(); getDefSupportedExts(); - //goToCenter(); ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); - ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETLIMITTEXT, extNameMax-1, 0); + + NppParameters& nppParam = NppParameters::getInstance(); + if (!nppParam.isAdmin()) + { + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANG_LIST), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SUPPORTEDEXTS_STATIC), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REGISTEREDEXTS_STATIC), false); + } + else + { + ::ShowWindow(::GetDlgItem(_hSelf, IDC_ADMINMUSTBEONMSG_STATIC), SW_HIDE); + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETLIMITTEXT, extNameMax - 1, 0); + } return TRUE; } @@ -292,7 +301,6 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar //return FALSE; } - void RegExtDlg::getRegisteredExts() { int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT); diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.rc b/PowerEditor/src/MISC/RegExt/regExtDlg.rc index 59d13b72c..eb6f685c6 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlg.rc +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.rc @@ -34,6 +34,7 @@ IDD_REGEXT_BOX DIALOGEX 0, 0, 370, 180 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | DS_CONTROL FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 BEGIN + LTEXT "Please exit Notepad++ and relaunch Notepad++ in Administrator mode to use this feature.",IDC_ADMINMUSTBEONMSG_STATIC,20,0,300,16 LTEXT "Supported extensions:",IDC_SUPPORTEDEXTS_STATIC,70,18,80,8 LISTBOX IDC_REGEXT_LANG_LIST,70,30,100,125,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP LISTBOX IDC_REGEXT_LANGEXT_LIST,175,30,80,125,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP @@ -42,7 +43,6 @@ BEGIN PUSHBUTTON "<-",IDC_REMOVEEXT_BUTTON,265,96,25,14 LTEXT "Registered extensions:",IDC_REGISTEREDEXTS_STATIC,300,18,80,8 LISTBOX IDC_REGEXT_REGISTEREDEXTS_LIST,300,30,80,125,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP - //CONTROL "",IDC_POUPELLE_STATIC,"Static",SS_OWNERDRAW,301,82,20,20 END diff --git a/PowerEditor/src/MISC/RegExt/regExtDlgRc.h b/PowerEditor/src/MISC/RegExt/regExtDlgRc.h index 3f16d0bd8..79efbddd5 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlgRc.h +++ b/PowerEditor/src/MISC/RegExt/regExtDlgRc.h @@ -37,7 +37,7 @@ #define IDI_POUPELLE_ICON (IDD_REGEXT_BOX + 5) #define IDC_CUSTOMEXT_EDIT (IDD_REGEXT_BOX + 6) #define IDC_REMOVEEXT_BUTTON (IDD_REGEXT_BOX + 7) - #define IDC_POUPELLE_STATIC (IDD_REGEXT_BOX + 8) + #define IDC_ADMINMUSTBEONMSG_STATIC (IDD_REGEXT_BOX + 8) #define IDC_SUPPORTEDEXTS_STATIC (IDD_REGEXT_BOX + 9) #define IDC_REGISTEREDEXTS_STATIC (IDD_REGEXT_BOX + 10) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e0e529a4e..329003ddd 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -134,20 +134,20 @@ Notepad_plus::Notepad_plus() { ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); - - TiXmlDocumentA *nativeLangDocRootA = (NppParameters::getInstance()).getNativeLangA(); + NppParameters& nppParam = NppParameters::getInstance(); + TiXmlDocumentA *nativeLangDocRootA = nppParam.getNativeLangA(); _nativeLangSpeaker.init(nativeLangDocRootA); - LocalizationSwitcher & localizationSwitcher = (NppParameters::getInstance()).getLocalizationSwitcher(); + LocalizationSwitcher & localizationSwitcher = nppParam.getLocalizationSwitcher(); const char *fn = _nativeLangSpeaker.getFileName(); if (fn) { localizationSwitcher.setFileName(fn); } - (NppParameters::getInstance()).setNativeLangSpeaker(&_nativeLangSpeaker); + nppParam.setNativeLangSpeaker(&_nativeLangSpeaker); - TiXmlDocument *toolIconsDocRoot = (NppParameters::getInstance()).getToolIcons(); + TiXmlDocument *toolIconsDocRoot = nppParam.getToolIcons(); if (toolIconsDocRoot) { @@ -172,6 +172,7 @@ Notepad_plus::Notepad_plus() else is_admin = false; + nppParam.setAdminMode(is_admin); _isAdministrator = is_admin ? true : false; } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 2493d808a..ff0c94afd 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1735,6 +1735,9 @@ private: public: void setShortcutDirty() { _isAnyShortcutModified = true; }; + void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; } + bool isAdmin() const { return _isAdminMode; } + private: bool _isAnyShortcutModified = false; std::vector _shortcuts; //main menu shortuts. Static size @@ -1794,6 +1797,7 @@ private: generic_string _wingupParams; generic_string _wingupDir; bool _isElevationRequired = false; + bool _isAdminMode = false; public: generic_string getWingupFullPath() const { return _wingupFullPath; };