[CPL][APPWIZ] Use display name for shortcut label (#2284)

CORE-16534
This commit is contained in:
Katayama Hirofumi MZ 2020-01-28 23:31:09 +09:00 committed by GitHub
parent f7972f0e6a
commit 7249b8b74f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 109 additions and 4 deletions

View file

@ -11,6 +11,7 @@
*/
#include "appwiz.h"
#include <shellapi.h>
#include <strsafe.h>
BOOL
@ -176,6 +177,50 @@ BOOL IsInternetLocation(LPCWSTR pszLocation)
return (PathIsURLW(pszLocation) || wcsstr(pszLocation, L"www.") == pszLocation);
}
/* Remove all invalid characters from the name */
void
DoConvertNameForFileSystem(LPWSTR szName)
{
LPWSTR pch1, pch2;
for (pch1 = pch2 = szName; *pch1; ++pch1)
{
if (wcschr(L"\\/:*?\"<>|", *pch1) != NULL)
{
/* *pch1 is an invalid character */
continue;
}
*pch2 = *pch1;
++pch2;
}
*pch2 = 0;
}
BOOL
DoValidateShortcutName(PCREATE_LINK_CONTEXT pContext)
{
SIZE_T cch;
LPCWSTR pch, pszName = pContext->szDescription;
if (!pszName || !pszName[0])
return FALSE;
cch = wcslen(pContext->szOrigin) + wcslen(pszName) + 1;
if (cch >= MAX_PATH)
return FALSE;
pch = pszName;
for (pch = pszName; *pch; ++pch)
{
if (wcschr(L"\\/:*?\"<>|", *pch) != NULL)
{
/* *pch is an invalid character */
return FALSE;
}
}
return TRUE;
}
INT_PTR
CALLBACK
WelcomeDlgProc(HWND hwndDlg,
@ -191,6 +236,7 @@ WelcomeDlgProc(HWND hwndDlg,
BROWSEINFOW brws;
LPITEMIDLIST pidllist;
LPWSTR pch;
SHFILEINFOW FileInfo;
switch(uMsg)
{
@ -259,6 +305,11 @@ WelcomeDlgProc(HWND hwndDlg,
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);
@ -272,10 +323,17 @@ WelcomeDlgProc(HWND hwndDlg,
{
/* not found */
WCHAR szError[MAX_PATH + 100];
SendDlgItemMessageW(hwndDlg, IDC_SHORTCUT_LOCATION, EM_SETSEL, 0, -1);
LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, _countof(szDesc));
LoadStringW(hApplet, IDS_ERROR_NOT_FOUND, szPath, _countof(szPath));
StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget);
MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR);
/* prevent the wizard to go next */
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
return TRUE;
}
}
else if (lppsn->hdr.code == PSN_RESET)
@ -300,6 +358,8 @@ FinishDlgProc(HWND hwndDlg,
PCREATE_LINK_CONTEXT pContext;
LPPSHNOTIFY lppsn;
LPWSTR pch;
WCHAR szText[MAX_PATH];
WCHAR szMessage[128];
switch(uMsg)
{
@ -307,7 +367,11 @@ FinishDlgProc(HWND hwndDlg,
ppsp = (LPPROPSHEETPAGEW)lParam;
pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
/* TODO: Use shell32!PathCleanupSpec instead of DoConvertNameForFileSystem */
DoConvertNameForFileSystem(pContext->szDescription);
SetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, pContext->szDescription);
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
break;
case WM_COMMAND:
@ -316,7 +380,12 @@ FinishDlgProc(HWND hwndDlg,
case EN_CHANGE:
if (SendDlgItemMessage(hwndDlg, IDC_SHORTCUT_NAME, WM_GETTEXTLENGTH, 0, 0))
{
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, szText, _countof(szText));
StrTrimW(szText, L" \t");
if (szText[0])
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
else
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
}
else
{
@ -330,9 +399,21 @@ FinishDlgProc(HWND hwndDlg,
pContext = (PCREATE_LINK_CONTEXT) GetWindowLongPtr(hwndDlg, DWLP_USER);
if (lppsn->hdr.code == PSN_WIZFINISH)
{
GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, pContext->szDescription, MAX_PATH);
GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, pContext->szDescription, _countof(pContext->szDescription));
StrTrimW(pContext->szDescription, L" \t");
if (!DoValidateShortcutName(pContext))
{
SendDlgItemMessageW(hwndDlg, IDC_SHORTCUT_NAME, EM_SETSEL, 0, -1);
LoadStringW(hApplet, IDS_INVALID_NAME, szMessage, _countof(szMessage));
MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
/* prevent the wizard to go next */
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
return TRUE;
}
/* if old shortcut file exists, then delete it now */
DeleteFileW(pContext->szOldFile);
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, pContext->szOldFile, NULL);
@ -352,7 +433,6 @@ FinishDlgProc(HWND hwndDlg,
if (!CreateInternetShortcut(pContext))
{
WCHAR szMessage[128];
LoadStringW(hApplet, IDS_CANTMAKEINETSHORTCUT, szMessage, _countof(szMessage));
MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
}
@ -522,7 +602,7 @@ NewLinkHereA(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{
WCHAR szFile[MAX_PATH];
if (MultiByteToWideChar(CP_ACP, 0, (LPSTR) lParam1, -1, szFile, MAX_PATH))
if (MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam1, -1, szFile, _countof(szFile)))
{
return ShowCreateShortcutWizard(hwndCPl, szFile);
}

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -90,4 +90,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -94,4 +94,5 @@ BEGIN
IDS_NO_MEMORY "No se pudo asignar memoria"
IDS_NO_DIRECTORY "No se ha especificado directorio alguno"
IDS_INVALID_PATH "La ruta proporcionada es inválida"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -92,4 +92,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -86,4 +86,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "Tidak ada memori yang bisa dialokasikan!"
IDS_NO_DIRECTORY "Direktori belum diberi!"
IDS_INVALID_PATH "Jalur yang diberikan tidak sah!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -95,4 +95,5 @@ BEGIN
IDS_NO_MEMORY "Nie można przydzielić pamięci!"
IDS_NO_DIRECTORY "Nie podano ścieżki!"
IDS_INVALID_PATH "Podana ścieżka jest niepoprawna!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -87,4 +87,5 @@ BEGIN
IDS_NO_MEMORY "A memória não pode ser alocada!"
IDS_NO_DIRECTORY "Sem diretoria!"
IDS_INVALID_PATH "O caminho é invalido!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -87,4 +87,5 @@ BEGIN
IDS_NO_MEMORY "A memória não pode ser alocada!"
IDS_NO_DIRECTORY "Sem directoria!"
IDS_INVALID_PATH "O caminho é invalido!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -91,4 +91,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -85,4 +85,5 @@ BEGIN
IDS_NO_MEMORY "Невозможно выделить память."
IDS_NO_DIRECTORY "Не указано ни одного каталога!"
IDS_INVALID_PATH "Указанный путь неверен!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -89,4 +89,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -89,4 +89,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -87,4 +87,5 @@ BEGIN
IDS_NO_MEMORY "No memory could be allocated!"
IDS_NO_DIRECTORY "No directory given!"
IDS_INVALID_PATH "The given path is invalid!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -93,4 +93,5 @@ BEGIN
IDS_NO_MEMORY "Неможливо виділити пам'ять."
IDS_NO_DIRECTORY "Не вказано жодного каталогу!"
IDS_INVALID_PATH "Вказаний шлях недійсний!"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -94,4 +94,5 @@ BEGIN
IDS_NO_MEMORY "没有可以分配的内存空间。"
IDS_NO_DIRECTORY "没有指定路径。"
IDS_INVALID_PATH "指定的路径无效。"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -94,4 +94,5 @@ BEGIN
IDS_NO_MEMORY "沒有可以分配的記憶體空間。"
IDS_NO_DIRECTORY "沒有指定路徑。"
IDS_INVALID_PATH "指定的路徑無效。"
IDS_INVALID_NAME "The shortcut name you entered either contained characters that are invalid for file names or was too long."
END

View file

@ -28,6 +28,7 @@
#define IDS_NO_MEMORY 2026
#define IDS_NO_DIRECTORY 2027
#define IDS_INVALID_PATH 2028
#define IDS_INVALID_NAME 2029
#define IDS_DOWNLOADING 14
#define IDS_INSTALLING 15