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
This commit is contained in:
Don HO 2019-12-27 00:35:16 +05:00
parent a1d048fdd9
commit 14074e1487
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
5 changed files with 28 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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<CommandShortcut> _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; };