diff --git a/dll/cpl/appwiz/createlink.c b/dll/cpl/appwiz/createlink.c index 7925f0b2ea3..27ac650e96e 100644 --- a/dll/cpl/appwiz/createlink.c +++ b/dll/cpl/appwiz/createlink.c @@ -11,6 +11,7 @@ */ #include "appwiz.h" +#include #include 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); } diff --git a/dll/cpl/appwiz/lang/bg-BG.rc b/dll/cpl/appwiz/lang/bg-BG.rc index 4198ecd3879..1771b697598 100644 --- a/dll/cpl/appwiz/lang/bg-BG.rc +++ b/dll/cpl/appwiz/lang/bg-BG.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/cs-CZ.rc b/dll/cpl/appwiz/lang/cs-CZ.rc index 4d0157bc21d..a03f07ba4b9 100644 --- a/dll/cpl/appwiz/lang/cs-CZ.rc +++ b/dll/cpl/appwiz/lang/cs-CZ.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/de-DE.rc b/dll/cpl/appwiz/lang/de-DE.rc index 29f55f9f696..f44b8e79fee 100644 --- a/dll/cpl/appwiz/lang/de-DE.rc +++ b/dll/cpl/appwiz/lang/de-DE.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/el-GR.rc b/dll/cpl/appwiz/lang/el-GR.rc index 4f996bd341e..53c815a9f37 100644 --- a/dll/cpl/appwiz/lang/el-GR.rc +++ b/dll/cpl/appwiz/lang/el-GR.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/en-US.rc b/dll/cpl/appwiz/lang/en-US.rc index b84f58d92e1..7f25e1b4a74 100644 --- a/dll/cpl/appwiz/lang/en-US.rc +++ b/dll/cpl/appwiz/lang/en-US.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/es-ES.rc b/dll/cpl/appwiz/lang/es-ES.rc index 52f809c83b7..9758843998e 100644 --- a/dll/cpl/appwiz/lang/es-ES.rc +++ b/dll/cpl/appwiz/lang/es-ES.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/et-EE.rc b/dll/cpl/appwiz/lang/et-EE.rc index 9a28610184e..1536a64b7ef 100644 --- a/dll/cpl/appwiz/lang/et-EE.rc +++ b/dll/cpl/appwiz/lang/et-EE.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/fr-FR.rc b/dll/cpl/appwiz/lang/fr-FR.rc index 3a3b8419808..e03f2ef5d7c 100644 --- a/dll/cpl/appwiz/lang/fr-FR.rc +++ b/dll/cpl/appwiz/lang/fr-FR.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/he-IL.rc b/dll/cpl/appwiz/lang/he-IL.rc index e4ab1dd5d2f..ade66f0999d 100644 --- a/dll/cpl/appwiz/lang/he-IL.rc +++ b/dll/cpl/appwiz/lang/he-IL.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/id-ID.rc b/dll/cpl/appwiz/lang/id-ID.rc index 08924fa71a4..32e0a8ea171 100644 --- a/dll/cpl/appwiz/lang/id-ID.rc +++ b/dll/cpl/appwiz/lang/id-ID.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/it-IT.rc b/dll/cpl/appwiz/lang/it-IT.rc index 248a279785d..7cde7d4e4e2 100644 --- a/dll/cpl/appwiz/lang/it-IT.rc +++ b/dll/cpl/appwiz/lang/it-IT.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/ja-JP.rc b/dll/cpl/appwiz/lang/ja-JP.rc index 01ad4976552..045e9ac89de 100644 --- a/dll/cpl/appwiz/lang/ja-JP.rc +++ b/dll/cpl/appwiz/lang/ja-JP.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/no-NO.rc b/dll/cpl/appwiz/lang/no-NO.rc index 77ac73142bb..f1a85e72e07 100644 --- a/dll/cpl/appwiz/lang/no-NO.rc +++ b/dll/cpl/appwiz/lang/no-NO.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/pl-PL.rc b/dll/cpl/appwiz/lang/pl-PL.rc index 5af34f868d2..caf66710be7 100644 --- a/dll/cpl/appwiz/lang/pl-PL.rc +++ b/dll/cpl/appwiz/lang/pl-PL.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/pt-BR.rc b/dll/cpl/appwiz/lang/pt-BR.rc index a76c1bcd118..35404e74dc2 100644 --- a/dll/cpl/appwiz/lang/pt-BR.rc +++ b/dll/cpl/appwiz/lang/pt-BR.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/pt-PT.rc b/dll/cpl/appwiz/lang/pt-PT.rc index 0c6e6801ee3..715daa40991 100644 --- a/dll/cpl/appwiz/lang/pt-PT.rc +++ b/dll/cpl/appwiz/lang/pt-PT.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/ro-RO.rc b/dll/cpl/appwiz/lang/ro-RO.rc index 185243b789b..45eb1112d49 100644 --- a/dll/cpl/appwiz/lang/ro-RO.rc +++ b/dll/cpl/appwiz/lang/ro-RO.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/ru-RU.rc b/dll/cpl/appwiz/lang/ru-RU.rc index 94a9bc76c30..42d1c80017e 100644 --- a/dll/cpl/appwiz/lang/ru-RU.rc +++ b/dll/cpl/appwiz/lang/ru-RU.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/sk-SK.rc b/dll/cpl/appwiz/lang/sk-SK.rc index ab136de8f32..5a52da02bdc 100644 --- a/dll/cpl/appwiz/lang/sk-SK.rc +++ b/dll/cpl/appwiz/lang/sk-SK.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/sq-AL.rc b/dll/cpl/appwiz/lang/sq-AL.rc index 161f72f7e75..bf247b9a099 100644 --- a/dll/cpl/appwiz/lang/sq-AL.rc +++ b/dll/cpl/appwiz/lang/sq-AL.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/tr-TR.rc b/dll/cpl/appwiz/lang/tr-TR.rc index 34f4f76f9ed..a45bf5a6d7e 100644 --- a/dll/cpl/appwiz/lang/tr-TR.rc +++ b/dll/cpl/appwiz/lang/tr-TR.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/uk-UA.rc b/dll/cpl/appwiz/lang/uk-UA.rc index c3ec10ceea9..965dc6233f2 100644 --- a/dll/cpl/appwiz/lang/uk-UA.rc +++ b/dll/cpl/appwiz/lang/uk-UA.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/zh-CN.rc b/dll/cpl/appwiz/lang/zh-CN.rc index cd43aaeaf0e..42d017c2dd1 100644 --- a/dll/cpl/appwiz/lang/zh-CN.rc +++ b/dll/cpl/appwiz/lang/zh-CN.rc @@ -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 diff --git a/dll/cpl/appwiz/lang/zh-TW.rc b/dll/cpl/appwiz/lang/zh-TW.rc index 7f499e1c37f..f2de51b4e78 100644 --- a/dll/cpl/appwiz/lang/zh-TW.rc +++ b/dll/cpl/appwiz/lang/zh-TW.rc @@ -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 diff --git a/dll/cpl/appwiz/resource.h b/dll/cpl/appwiz/resource.h index d91a360e172..28ddc864cf7 100644 --- a/dll/cpl/appwiz/resource.h +++ b/dll/cpl/appwiz/resource.h @@ -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