[APPWIZ] 'Create Shortcut' wizard: Accept arguments (#5456)

Allow command line as Create Shortcut wizard's target. CORE-5866
This commit is contained in:
Katayama Hirofumi MZ 2023-07-22 12:39:51 +09:00 committed by GitHub
parent 252026352d
commit 059427e31d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 36 deletions

View file

@ -27,9 +27,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(appwiz);
typedef struct typedef struct
{ {
WCHAR szTarget[MAX_PATH]; WCHAR szTarget[2 * MAX_PATH];
WCHAR szWorkingDirectory[MAX_PATH]; WCHAR szWorkingDirectory[MAX_PATH];
WCHAR szDescription[MAX_PATH]; WCHAR szDescription[MAX_PATH];
WCHAR szArguments[2 * MAX_PATH];
WCHAR szOrigin[MAX_PATH]; WCHAR szOrigin[MAX_PATH];
WCHAR szOldFile[MAX_PATH]; WCHAR szOldFile[MAX_PATH];
WCHAR szLinkName[MAX_PATH]; WCHAR szLinkName[MAX_PATH];

View file

@ -14,6 +14,7 @@
#include <commctrl.h> #include <commctrl.h>
#include <shellapi.h> #include <shellapi.h>
#include <strsafe.h> #include <strsafe.h>
#include <shlwapi_undoc.h> // for PathFindOnPathExW
BOOL BOOL
IsShortcut(HKEY hKey) IsShortcut(HKEY hKey)
@ -126,6 +127,8 @@ CreateShortcut(PCREATE_LINK_CONTEXT pContext)
return FALSE; return FALSE;
pShellLink->lpVtbl->SetPath(pShellLink, Path); pShellLink->lpVtbl->SetPath(pShellLink, Path);
if (pContext->szArguments[0])
pShellLink->lpVtbl->SetArguments(pShellLink, pContext->szArguments);
pShellLink->lpVtbl->SetDescription(pShellLink, pContext->szDescription); pShellLink->lpVtbl->SetDescription(pShellLink, pContext->szDescription);
pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pContext->szWorkingDirectory); pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pContext->szWorkingDirectory);
@ -237,7 +240,6 @@ WelcomeDlgProc(HWND hwndDlg,
WCHAR szTitle[100]; WCHAR szTitle[100];
BROWSEINFOW brws; BROWSEINFOW brws;
LPITEMIDLIST pidllist; LPITEMIDLIST pidllist;
LPWSTR pch;
SHFILEINFOW FileInfo; SHFILEINFOW FileInfo;
switch(uMsg) switch(uMsg)
@ -250,6 +252,7 @@ WelcomeDlgProc(HWND hwndDlg,
SHAutoComplete(GetDlgItem(hwndDlg, IDC_SHORTCUT_LOCATION), SHACF_DEFAULT); SHAutoComplete(GetDlgItem(hwndDlg, IDC_SHORTCUT_LOCATION), SHACF_DEFAULT);
break; break;
case WM_COMMAND: case WM_COMMAND:
{
switch(HIWORD(wParam)) switch(HIWORD(wParam))
{ {
case EN_CHANGE: case EN_CHANGE:
@ -306,56 +309,66 @@ WelcomeDlgProc(HWND hwndDlg,
{ {
GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_LOCATION, pContext->szTarget, _countof(pContext->szTarget)); GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_LOCATION, pContext->szTarget, _countof(pContext->szTarget));
StrTrimW(pContext->szTarget, L" \t"); StrTrimW(pContext->szTarget, L" \t");
ExpandEnvironmentStringsW(pContext->szTarget, szPath, _countof(szPath)); ExpandEnvironmentStringsW(pContext->szTarget, szPath, _countof(szPath));
StringCchCopyW(pContext->szTarget, _countof(pContext->szTarget), szPath);
if (IsInternetLocation(pContext->szTarget)) if (IsInternetLocation(szPath)) /* The internet location */
{ {
/* internet */
WCHAR szName[128]; WCHAR szName[128];
LoadStringW(hApplet, IDS_NEW_INTERNET_SHORTCUT, szName, _countof(szName)); LoadStringW(hApplet, IDS_NEW_INTERNET_SHORTCUT, szName, _countof(szName));
StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), szName); StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), szName);
pContext->szWorkingDirectory[0] = 0; pContext->szWorkingDirectory[0] = 0;
pContext->szArguments[0] = 0;
return FALSE;
} }
else if (GetFileAttributesW(pContext->szTarget) != INVALID_FILE_ATTRIBUTES)
/* Split and build args */
LPWSTR pszArgs = PathGetArgsW(szPath);
if (pszArgs && pszArgs > szPath)
{ {
/* file */ PathRemoveArgsW(szPath);
SendDlgItemMessage(hwndDlg, IDC_SHORTCUT_LOCATION, EM_SETSEL, 0, -1); StringCchCopyW(pContext->szArguments, _countof(pContext->szArguments), pszArgs);
SetFocus(GetDlgItem(hwndDlg, IDC_SHORTCUT_LOCATION));
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
/* get display name */
FileInfo.szDisplayName[0] = 0;
if (SHGetFileInfoW(pContext->szTarget, 0, &FileInfo, sizeof(FileInfo), SHGFI_DISPLAYNAME))
StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), FileInfo.szDisplayName);
/* set working directory */
StringCchCopyW(pContext->szWorkingDirectory, _countof(pContext->szWorkingDirectory),
pContext->szTarget);
PathRemoveBackslashW(pContext->szWorkingDirectory);
pch = PathFindFileNameW(pContext->szWorkingDirectory);
if (pch && *pch)
*pch = 0;
PathRemoveBackslashW(pContext->szWorkingDirectory);
} }
else else
{ {
/* not found */ pContext->szArguments[0] = 0;
WCHAR szError[MAX_PATH + 100]; }
/* Find the file */
WCHAR szFound[MAX_PATH];
StringCchCopyW(szFound, _countof(szFound), szPath);
if (!PathFindOnPathExW(szFound, NULL, WHICH_DEFAULT) &&
FindExecutableW(szPath, NULL, szFound) <= (HINSTANCE)(INT_PTR)32)
{
/* Not found */
SendDlgItemMessageW(hwndDlg, IDC_SHORTCUT_LOCATION, EM_SETSEL, 0, -1); SendDlgItemMessageW(hwndDlg, IDC_SHORTCUT_LOCATION, EM_SETSEL, 0, -1);
LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, _countof(szDesc)); LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, _countof(szDesc));
LoadStringW(hApplet, IDS_ERROR_NOT_FOUND, szPath, _countof(szPath)); LoadStringW(hApplet, IDS_ERROR_NOT_FOUND, szPath, _countof(szPath));
WCHAR szError[MAX_PATH + 100];
StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget); StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget);
MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR); MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR);
/* prevent the wizard to go next */ /* Prevent the wizard to go next */
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
return TRUE; return TRUE;
} }
/* Rebuild target */
StringCchCopyW(pContext->szTarget, _countof(pContext->szTarget), szFound);
/* Get display name */
FileInfo.szDisplayName[0] = 0;
if (SHGetFileInfoW(szFound, 0, &FileInfo, sizeof(FileInfo), SHGFI_DISPLAYNAME))
StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), FileInfo.szDisplayName);
/* Set working directory */
StringCchCopyW(pContext->szWorkingDirectory, _countof(pContext->szWorkingDirectory), szFound);
PathRemoveBackslashW(pContext->szWorkingDirectory);
PathRemoveFileSpecW(pContext->szWorkingDirectory);
PathRemoveBackslashW(pContext->szWorkingDirectory);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
} }
else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam) else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
{ {
@ -364,6 +377,7 @@ WelcomeDlgProc(HWND hwndDlg,
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, pContext->szOldFile, NULL); SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, pContext->szOldFile, NULL);
} }
break; break;
}
} }
return FALSE; return FALSE;
} }
@ -378,7 +392,6 @@ FinishDlgProc(HWND hwndDlg,
LPPROPSHEETPAGEW ppsp; LPPROPSHEETPAGEW ppsp;
PCREATE_LINK_CONTEXT pContext; PCREATE_LINK_CONTEXT pContext;
LPPSHNOTIFY lppsn; LPPSHNOTIFY lppsn;
LPWSTR pch;
WCHAR szText[MAX_PATH]; WCHAR szText[MAX_PATH];
WCHAR szMessage[128]; WCHAR szMessage[128];
@ -450,9 +463,7 @@ FinishDlgProc(HWND hwndDlg,
PathAppendW(pContext->szLinkName, pContext->szDescription); PathAppendW(pContext->szLinkName, pContext->szDescription);
/* change extension if any */ /* change extension if any */
pch = PathFindExtensionW(pContext->szLinkName); PathRemoveExtensionW(pContext->szLinkName);
if (pch && *pch)
*pch = 0;
StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".url"); StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".url");
if (!CreateInternetShortcut(pContext)) if (!CreateInternetShortcut(pContext))
@ -469,9 +480,7 @@ FinishDlgProc(HWND hwndDlg,
PathAppendW(pContext->szLinkName, pContext->szDescription); PathAppendW(pContext->szLinkName, pContext->szDescription);
/* change extension if any */ /* change extension if any */
pch = PathFindExtensionW(pContext->szLinkName); PathRemoveExtensionW(pContext->szLinkName);
if (pch && *pch)
*pch = 0;
StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".lnk"); StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".lnk");
if (!CreateShortcut(pContext)) if (!CreateShortcut(pContext))