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
pull/7792/head
Don HO 5 years ago
parent a1d048fdd9
commit 14074e1487
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

@ -27,6 +27,7 @@
#include "Common.h" #include "Common.h"
#include "regExtDlg.h" #include "regExtDlg.h"
#include "resource.h" #include "resource.h"
#include "Parameters.h"
@ -78,10 +79,6 @@ const TCHAR defExtArray[nbSupportedLang][nbExtMax][extNameMax] =
{TEXT("customize")} {TEXT("customize")}
}; };
void RegExtDlg::doDialog(bool isRTL) void RegExtDlg::doDialog(bool isRTL)
{ {
if (isRTL) if (isRTL)
@ -95,7 +92,6 @@ void RegExtDlg::doDialog(bool isRTL)
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)); ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
} }
INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{ {
switch (Message) switch (Message)
@ -104,10 +100,23 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
{ {
getRegisteredExts(); getRegisteredExts();
getDefSupportedExts(); getDefSupportedExts();
//goToCenter();
::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false);
::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_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; return TRUE;
} }
@ -292,7 +301,6 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
//return FALSE; //return FALSE;
} }
void RegExtDlg::getRegisteredExts() void RegExtDlg::getRegisteredExts()
{ {
int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT); int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT);

@ -34,6 +34,7 @@ IDD_REGEXT_BOX DIALOGEX 0, 0, 370, 180
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | DS_CONTROL STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | DS_CONTROL
FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1
BEGIN 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 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_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 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 PUSHBUTTON "<-",IDC_REMOVEEXT_BUTTON,265,96,25,14
LTEXT "Registered extensions:",IDC_REGISTEREDEXTS_STATIC,300,18,80,8 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 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 END

@ -37,7 +37,7 @@
#define IDI_POUPELLE_ICON (IDD_REGEXT_BOX + 5) #define IDI_POUPELLE_ICON (IDD_REGEXT_BOX + 5)
#define IDC_CUSTOMEXT_EDIT (IDD_REGEXT_BOX + 6) #define IDC_CUSTOMEXT_EDIT (IDD_REGEXT_BOX + 6)
#define IDC_REMOVEEXT_BUTTON (IDD_REGEXT_BOX + 7) #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_SUPPORTEDEXTS_STATIC (IDD_REGEXT_BOX + 9)
#define IDC_REGISTEREDEXTS_STATIC (IDD_REGEXT_BOX + 10) #define IDC_REGISTEREDEXTS_STATIC (IDD_REGEXT_BOX + 10)

@ -134,20 +134,20 @@ Notepad_plus::Notepad_plus()
{ {
ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange));
NppParameters& nppParam = NppParameters::getInstance();
TiXmlDocumentA *nativeLangDocRootA = (NppParameters::getInstance()).getNativeLangA(); TiXmlDocumentA *nativeLangDocRootA = nppParam.getNativeLangA();
_nativeLangSpeaker.init(nativeLangDocRootA); _nativeLangSpeaker.init(nativeLangDocRootA);
LocalizationSwitcher & localizationSwitcher = (NppParameters::getInstance()).getLocalizationSwitcher(); LocalizationSwitcher & localizationSwitcher = nppParam.getLocalizationSwitcher();
const char *fn = _nativeLangSpeaker.getFileName(); const char *fn = _nativeLangSpeaker.getFileName();
if (fn) if (fn)
{ {
localizationSwitcher.setFileName(fn); localizationSwitcher.setFileName(fn);
} }
(NppParameters::getInstance()).setNativeLangSpeaker(&_nativeLangSpeaker); nppParam.setNativeLangSpeaker(&_nativeLangSpeaker);
TiXmlDocument *toolIconsDocRoot = (NppParameters::getInstance()).getToolIcons(); TiXmlDocument *toolIconsDocRoot = nppParam.getToolIcons();
if (toolIconsDocRoot) if (toolIconsDocRoot)
{ {
@ -172,6 +172,7 @@ Notepad_plus::Notepad_plus()
else else
is_admin = false; is_admin = false;
nppParam.setAdminMode(is_admin);
_isAdministrator = is_admin ? true : false; _isAdministrator = is_admin ? true : false;
} }

@ -1735,6 +1735,9 @@ private:
public: public:
void setShortcutDirty() { _isAnyShortcutModified = true; }; void setShortcutDirty() { _isAnyShortcutModified = true; };
void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; }
bool isAdmin() const { return _isAdminMode; }
private: private:
bool _isAnyShortcutModified = false; bool _isAnyShortcutModified = false;
std::vector<CommandShortcut> _shortcuts; //main menu shortuts. Static size std::vector<CommandShortcut> _shortcuts; //main menu shortuts. Static size
@ -1794,6 +1797,7 @@ private:
generic_string _wingupParams; generic_string _wingupParams;
generic_string _wingupDir; generic_string _wingupDir;
bool _isElevationRequired = false; bool _isElevationRequired = false;
bool _isAdminMode = false;
public: public:
generic_string getWingupFullPath() const { return _wingupFullPath; }; generic_string getWingupFullPath() const { return _wingupFullPath; };

Loading…
Cancel
Save