From 5aea1c71184ba2138799bd391bfc9f084b8f5c2e Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 11 Dec 2018 16:35:45 +0900 Subject: [PATCH] [0.4.11] [SHELL32] Enable environment variables in 'Run' dialog (#1111) CORE-15431 (1 of 2) cherry picked from commit 0.4.12-dev-19-g 06d717e3bc3923d6c1fc2e3420430dd597e517a6 --- dll/win32/shell32/dialogs/dialogs.cpp | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/dll/win32/shell32/dialogs/dialogs.cpp b/dll/win32/shell32/dialogs/dialogs.cpp index 47b6f04d5a5..fc23284a137 100644 --- a/dll/win32/shell32/dialogs/dialogs.cpp +++ b/dll/win32/shell32/dialogs/dialogs.cpp @@ -551,7 +551,8 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA LRESULT lRet; HWND htxt = GetDlgItem(hwnd, IDC_RUNDLG_EDITPATH); INT ic; - WCHAR *psz, *parent = NULL; + WCHAR *psz, *pszExpanded, *parent = NULL; + DWORD cchExpand; NMRUNFILEDLGW nmrfd; ic = GetWindowTextLengthW(htxt); @@ -575,6 +576,24 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA GetWindowTextW(htxt, psz, ic + 1); StrTrimW(psz, L" \t"); + if (wcschr(psz, L'%') != NULL) + { + cchExpand = ExpandEnvironmentStringsW(psz, NULL, 0); + pszExpanded = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, cchExpand * sizeof(WCHAR)); + if (!pszExpanded) + { + HeapFree(GetProcessHeap(), 0, psz); + EndDialog(hwnd, IDCANCEL); + return TRUE; + } + ExpandEnvironmentStringsW(psz, pszExpanded, cchExpand); + StrTrimW(pszExpanded, L" \t"); + } + else + { + pszExpanded = psz; + } + /* * The precedence is the following: first the user-given * current directory is used; if there is none, a current @@ -604,7 +623,7 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA nmrfd.hdr.code = RFN_VALIDATE; nmrfd.hdr.hwndFrom = hwnd; nmrfd.hdr.idFrom = 0; - nmrfd.lpFile = psz; + nmrfd.lpFile = pszExpanded; nmrfd.lpDirectory = pszStartDir; nmrfd.nShow = SW_SHOWNORMAL; @@ -617,12 +636,12 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA break; case RF_OK: - if (SUCCEEDED(ShellExecCmdLine(hwnd, psz, pszStartDir, SW_SHOWNORMAL, NULL, + if (SUCCEEDED(ShellExecCmdLine(hwnd, pszExpanded, pszStartDir, SW_SHOWNORMAL, NULL, SECL_ALLOW_NONEXE))) { /* Call again GetWindowText in case the contents of the edit box has changed? */ - GetWindowTextW(htxt, psz, ic + 1); - FillList(htxt, psz, ic + 2 + 1, FALSE); + GetWindowTextW(htxt, pszExpanded, ic + 1); + FillList(htxt, pszExpanded, ic + 2 + 1, FALSE); EndDialog(hwnd, IDOK); break; } @@ -638,6 +657,8 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA HeapFree(GetProcessHeap(), 0, parent); HeapFree(GetProcessHeap(), 0, psz); + if (psz != pszExpanded) + HeapFree(GetProcessHeap(), 0, pszExpanded); return TRUE; }