Skip to content
Permalink
Browse files

Fix sf.net ticket 2234: "Run as Administrator" incompatible with "She…

…ll integration" (ver 2.16.4)
  • Loading branch information...
sdottaka committed Oct 8, 2019
1 parent 6d924dc commit 0bcd33baae1280eea3d30e65d8fc51d33b4045e5
@@ -38,16 +38,16 @@ LANGUAGE LANG_ITALIAN, SUBLANG_ITALIAN
//
STRINGTABLE
BEGIN
IDS_PROJNAME "ShellExtension"
IDS_PROJNAME "Estensione shell"
IDS_CONTEXT_MENU "WinMerge"
IDS_CONTEXT_HELP "Apri con WinMerge"
IDS_CONTEXT_HELP_MANYITEMS "Seleziona un massimo di 2 elementi"
IDS_CONTEXT_HELP_MANYITEMS "Seleziona massimo 2 elementi"
IDS_COMPARE "Confronta"
IDS_COMPARE_ELLIPSIS "Confronta..."
IDS_COMPARE_TO "Confronta con"
IDS_HELP_SAVETHIS "Salva questo percorso. Selezionane poi un altro da confrontare con questo."
IDS_HELP_SAVETHIS "Salva questo percorso.\nSeleziona un altro da confrontare con questo."
IDS_HELP_COMPARESAVED "Confronta con il percorso salvato (%1)"
IDS_RESELECT_FIRST "Torna a selezionare il primo"
IDS_RESELECT_FIRST "Riseleziona il primo percorso"
END

#endif // Resources
@@ -325,8 +325,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,17,9,0
PRODUCTVERSION 1,17,9,0
FILEVERSION 1,17,10,0
PRODUCTVERSION 1,17,10,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -343,12 +343,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "http://winmerge.org"
VALUE "FileDescription", "WinMerge Shell Integration library"
VALUE "FileVersion", "1.17.9.0"
VALUE "FileVersion", "1.17.10.0"
VALUE "InternalName", "ShellExtension"
VALUE "LegalCopyright", "Copyright 2003-2019"
VALUE "OriginalFilename", "ShellExtension.DLL"
VALUE "ProductName", "WinMerge Shell Integration library"
VALUE "ProductVersion", "1.17.9.0"
VALUE "ProductVersion", "1.17.10.0"
END
END
BLOCK "VarFileInfo"
@@ -215,6 +215,9 @@ HRESULT CWinMergeShell::Initialize(LPCITEMIDLIST pidlFolder,
{
HRESULT hr = E_INVALIDARG;

for (auto& path: m_strPaths)
path.erase();

// Files/folders selected normally from the explorer
if (pDataObj)
{
@@ -445,6 +448,7 @@ HRESULT CWinMergeShell::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
default:
// "Compare..." - user wants to compare this single item and open WinMerge
m_strPaths[1].erase();
m_strPaths[2].erase();
bCompare = TRUE;
break;
}
@@ -458,11 +462,8 @@ HRESULT CWinMergeShell::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0)
bAlterSubFolders = TRUE;

String strCommandLine = FormatCmdLine(strWinMergePath, m_strPaths[0],
m_strPaths[1], bAlterSubFolders);

if (!m_strPaths[2].empty())
strCommandLine += _T(" \"") + m_strPaths[2] + _T("\"");
String strCommandLine = FormatCmdLine(strWinMergePath,
m_strPaths[0], m_strPaths[1], m_strPaths[2], bAlterSubFolders);

// Finally start a new WinMerge process
BOOL retVal = FALSE;
@@ -474,11 +475,24 @@ HRESULT CWinMergeShell::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL,
&stInfo, &processInfo);

if (!retVal)
if (retVal)
{
CloseHandle(processInfo.hThread);
CloseHandle(processInfo.hProcess);
}
else if (GetLastError() == ERROR_ELEVATION_REQUIRED)
{
String strCommandLine = FormatCmdLine(_T(""),
m_strPaths[0], m_strPaths[1], m_strPaths[2], bAlterSubFolders);
HINSTANCE hInstance = ShellExecute(nullptr, _T("runas"), strWinMergePath.c_str(), strCommandLine.c_str(), 0, SW_SHOWNORMAL);
if (reinterpret_cast<intptr_t>(hInstance) < 32)
return S_FALSE;
}
else
{
return S_FALSE;
}

CloseHandle(processInfo.hThread);
CloseHandle(processInfo.hProcess);
return S_OK;
}

@@ -644,9 +658,9 @@ String CWinMergeShell::GetHelpText(UINT_PTR idCmd)

/// Format commandline used to start WinMerge
String CWinMergeShell::FormatCmdLine(const String &winmergePath,
const String &path1, const String &path2, BOOL bAlterSubFolders)
const String &path1, const String &path2, const String &path3, BOOL bAlterSubFolders)
{
String strCommandline = _T("\"") + winmergePath + _T("\"");
String strCommandline = winmergePath.empty() ? _T("") : _T("\"") + winmergePath + _T("\"");

// Check if user wants to use context menu
BOOL bSubfoldersByDefault = FALSE;
@@ -664,5 +678,8 @@ String CWinMergeShell::FormatCmdLine(const String &winmergePath,
if (!m_strPaths[1].empty())
strCommandline += _T(" \"") + path2 + _T("\"");

if (!m_strPaths[2].empty())
strCommandline += _T(" \"") + path3 + _T("\"");

return strCommandline;
}
@@ -72,7 +72,7 @@ class ATL_NO_VTABLE CWinMergeShell :
int DrawAdvancedMenu(HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd);
String GetHelpText(UINT_PTR idCmd);
String FormatCmdLine(const String &winmergePath,
const String &path1, const String &path2, BOOL bAlterSubFolders);
const String &path1, const String &path2, const String &path3, BOOL bAlterSubFolders);

public:
// IShellExtInit

0 comments on commit 0bcd33b

Please sign in to comment.
You can’t perform that action at this time.