[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
This commit is contained in:
Amine Khaldi 2014-02-02 23:41:29 +00:00
parent f7c21a892e
commit 7eb7ed4823

View file

@ -1955,8 +1955,20 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM
/* target path */ /* target path */
if (pThis->sPath) 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 */ /* working dir */
if (pThis->sWorkDir) if (pThis->sWorkDir)
SetDlgItemTextW(hwndDlg, 14011, 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) if (lppsn->hdr.code == PSN_APPLY)
{ {
WCHAR wszBuf[MAX_PATH]; WCHAR wszBuf[MAX_PATH];
/* set working directory */ /* set working directory */
GetDlgItemTextW(hwndDlg, 14011, wszBuf, MAX_PATH); GetDlgItemTextW(hwndDlg, 14011, wszBuf, MAX_PATH);
pThis->SetWorkingDirectory(wszBuf); pThis->SetWorkingDirectory(wszBuf);
/* set link destination */ /* set link destination */
GetDlgItemTextW(hwndDlg, 14009, wszBuf, MAX_PATH); 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 lpszArgs = PathGetArgsW(unquoted);
MessageBoxW(hwndDlg, L"file not existing", wszBuf, MB_OK); PathRemoveArgsW(unquoted);
SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); StrTrimW(lpszArgs, L" ");
return TRUE;
} }
if (unquoted[0] == '"' && unquoted[wcslen(unquoted)-1] == '"')
PathUnquoteSpacesW(unquoted);
WCHAR *pwszExt = PathFindExtensionW(wszBuf);
WCHAR *pwszExt = PathFindExtensionW(unquoted);
if (!wcsicmp(pwszExt, L".lnk")) if (!wcsicmp(pwszExt, L".lnk"))
{ {
// FIXME load localized error msg // FIXME load localized error msg
@ -1996,12 +2012,25 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM
return TRUE; 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); TRACE("This %p sLinkPath %S\n", pThis, pThis->sLinkPath);
pThis->Save(pThis->sLinkPath, TRUE); pThis->Save(pThis->sLinkPath, TRUE);
SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); return TRUE;
return TRUE;
} }
break; break;
} }