From 7eb7ed4823983a1f0066dffd82cbb57f246234d7 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Sun, 2 Feb 2014 23:41:29 +0000 Subject: [PATCH] [SHELL32] * Fix how the shortcut targets are edited to allow for program arguments. * Brought to you by Huw Campbell. CORE-7763 #resolve #comment Committed in r61934. Thanks ! svn path=/trunk/; revision=61934 --- reactos/dll/win32/shell32/shelllink.cpp | 53 +++++++++++++++++++------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/reactos/dll/win32/shell32/shelllink.cpp b/reactos/dll/win32/shell32/shelllink.cpp index 156e4073426..d8e5580dedb 100644 --- a/reactos/dll/win32/shell32/shelllink.cpp +++ b/reactos/dll/win32/shell32/shelllink.cpp @@ -1955,8 +1955,20 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM /* target path */ if (pThis->sPath) - SetDlgItemTextW(hwndDlg, 14009, pThis->sPath); - + { + WCHAR newpath[2*MAX_PATH] = L"\0"; + if (wcschr(pThis->sPath, ' ')) + StringCchPrintfExW(newpath, 2*MAX_PATH, NULL, NULL, 0, L"\"%ls\"", pThis->sPath); + else + StringCchCopyExW(newpath, 2*MAX_PATH, pThis->sPath, NULL, NULL, 0); + + if (pThis->sArgs && pThis->sArgs[0]) + { + StringCchCatW(newpath, 2*MAX_PATH, L" "); + StringCchCatW(newpath, 2*MAX_PATH, pThis->sArgs); + } + SetDlgItemTextW(hwndDlg, 14009, newpath); + } /* working dir */ if (pThis->sWorkDir) SetDlgItemTextW(hwndDlg, 14011, pThis->sWorkDir); @@ -1973,21 +1985,25 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM if (lppsn->hdr.code == PSN_APPLY) { WCHAR wszBuf[MAX_PATH]; - /* set working directory */ GetDlgItemTextW(hwndDlg, 14011, wszBuf, MAX_PATH); pThis->SetWorkingDirectory(wszBuf); /* set link destination */ GetDlgItemTextW(hwndDlg, 14009, wszBuf, MAX_PATH); - if (!PathFileExistsW(wszBuf)) + LPWSTR lpszArgs = NULL; + LPWSTR unquoted = strdupW(wszBuf); + StrTrimW(unquoted, L" "); + if (!PathFileExistsW(unquoted)) { - //FIXME load localized error msg - MessageBoxW(hwndDlg, L"file not existing", wszBuf, MB_OK); - SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); - return TRUE; + lpszArgs = PathGetArgsW(unquoted); + PathRemoveArgsW(unquoted); + StrTrimW(lpszArgs, L" "); } + if (unquoted[0] == '"' && unquoted[wcslen(unquoted)-1] == '"') + PathUnquoteSpacesW(unquoted); - WCHAR *pwszExt = PathFindExtensionW(wszBuf); + + WCHAR *pwszExt = PathFindExtensionW(unquoted); if (!wcsicmp(pwszExt, L".lnk")) { // FIXME load localized error msg @@ -1996,12 +2012,25 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM return TRUE; } - pThis->SetPath(wszBuf); + if (!PathFileExistsW(unquoted)) + { + //FIXME load localized error msg + MessageBoxW(hwndDlg, L"The specified file name in the target box is invalid", L"Error", MB_ICONERROR); + SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); + return TRUE; + } + + pThis->SetPath(unquoted); + if (lpszArgs) + pThis->SetArguments(lpszArgs); + else + pThis->SetArguments(L"\0"); + + HeapFree(GetProcessHeap(), 0, unquoted); TRACE("This %p sLinkPath %S\n", pThis, pThis->sLinkPath); pThis->Save(pThis->sLinkPath, TRUE); - SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); - return TRUE; + SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); return TRUE; } break; }