Reactos

[SHELL32] Allow .Lnk properties dialog to change icon for non-FS targets (#7911)

CORE-19971

authored by

Whindmar Saksit and committed by
GitHub
efbdd483 7eb8535e

+66 -42
+66 -41
dll/win32/shell32/CShellLink.cpp
··· 294 294 m_pDBList = NULL; 295 295 m_bInInit = FALSE; 296 296 m_hIcon = NULL; 297 - m_idCmdFirst = 0; 298 297 299 298 m_sLinkPath = NULL; 300 299 ··· 2543 2542 { 2544 2543 INT id = 0; 2545 2544 2546 - m_idCmdFirst = idCmdFirst; 2547 - 2548 2545 TRACE("%p %p %u %u %u %u\n", this, 2549 2546 hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags); 2550 2547 ··· 2934 2931 2935 2932 case IDC_SHORTCUT_CHANGE_ICON: 2936 2933 { 2937 - WCHAR wszPath[MAX_PATH] = L""; 2934 + SHFILEINFOW fi; 2935 + INT IconIndex = m_Header.nIconIndex; 2936 + WCHAR wszPath[MAX_PATH]; 2937 + *wszPath = UNICODE_NULL; 2938 + 2939 + if (!StrIsNullOrEmpty(m_sIcoPath)) 2940 + { 2941 + PWSTR pszPath = m_sIcoPath; 2942 + if (*m_sIcoPath == '.') // Extension-only icon location, we need a fake path 2943 + { 2944 + if (SUCCEEDED(StringCchPrintfW(wszPath, _countof(wszPath), L"x:\\x%s", m_sIcoPath)) && 2945 + SHGetFileInfoW(wszPath, 0, &fi, sizeof(fi), SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES)) 2946 + { 2947 + pszPath = fi.szDisplayName; // The path is now a generic icon based 2948 + IconIndex = fi.iIcon; // on the registry info of the file extension. 2949 + } 2950 + } 2938 2951 2939 - if (m_sIcoPath) 2940 - wcscpy(wszPath, m_sIcoPath); 2941 - else 2952 + if (FAILED(StringCchCopyW(wszPath, _countof(wszPath), pszPath))) 2953 + *wszPath = UNICODE_NULL; 2954 + } 2955 + else if (!StrIsNullOrEmpty(m_sPath)) 2956 + { 2942 2957 FindExecutableW(m_sPath, NULL, wszPath); 2958 + } 2943 2959 2944 - INT IconIndex = m_Header.nIconIndex; 2960 + if (!*wszPath && m_pPidl) 2961 + { 2962 + if (SHGetFileInfoW((PWSTR)m_pPidl, 0, &fi, sizeof(fi), SHGFI_ICONLOCATION | SHGFI_PIDL) && 2963 + SUCCEEDED(StringCchCopyW(wszPath, _countof(wszPath), fi.szDisplayName))) 2964 + { 2965 + IconIndex = fi.iIcon; 2966 + } 2967 + } 2968 + 2945 2969 if (PickIconDlg(hwndDlg, wszPath, _countof(wszPath), &IconIndex)) 2946 2970 { 2947 2971 SetIconLocation(wszPath, IconIndex); ··· 2993 3017 SetWorkingDirectory(wszBuf); 2994 3018 2995 3019 /* set link destination */ 2996 - GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_TARGET_TEXT, wszBuf, _countof(wszBuf)); 2997 - LPWSTR lpszArgs = NULL; 2998 - LPWSTR unquoted = strdupW(wszBuf); 2999 - StrTrimW(unquoted, L" "); 3000 - 3001 - if (!PathFileExistsW(unquoted)) 3020 + HWND hWndTarget = GetDlgItem(hwndDlg, IDC_SHORTCUT_TARGET_TEXT); 3021 + GetWindowTextW(hWndTarget, wszBuf, _countof(wszBuf)); 3022 + // Only set the path and arguments for filesystem targets (we can't verify other targets) 3023 + if (IsWindowEnabled(hWndTarget)) 3002 3024 { 3003 - lpszArgs = PathGetArgsW(unquoted); 3004 - PathRemoveArgsW(unquoted); 3005 - StrTrimW(lpszArgs, L" "); 3006 - } 3007 - if (unquoted[0] == '"' && unquoted[wcslen(unquoted) - 1] == '"') 3008 - PathUnquoteSpacesW(unquoted); 3025 + LPWSTR lpszArgs = NULL; 3026 + LPWSTR unquoted = wszBuf; 3027 + StrTrimW(unquoted, L" "); 3009 3028 3010 - WCHAR *pwszExt = PathFindExtensionW(unquoted); 3011 - if (!_wcsicmp(pwszExt, L".lnk")) 3012 - { 3013 - // FIXME load localized error msg 3014 - MessageBoxW(hwndDlg, L"You cannot create a link to a shortcut", L"Error", MB_ICONERROR); 3015 - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); 3016 - return TRUE; 3017 - } 3029 + if (!PathFileExistsW(unquoted)) 3030 + { 3031 + lpszArgs = PathGetArgsW(unquoted); 3032 + PathRemoveArgsW(unquoted); 3033 + StrTrimW(lpszArgs, L" "); 3034 + } 3035 + if (unquoted[0] == '"' && unquoted[wcslen(unquoted) - 1] == '"') 3036 + PathUnquoteSpacesW(unquoted); 3018 3037 3019 - if (!PathFileExistsW(unquoted)) 3020 - { 3021 - // FIXME load localized error msg 3022 - MessageBoxW(hwndDlg, L"The specified file name in the target box is invalid", L"Error", MB_ICONERROR); 3023 - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); 3024 - return TRUE; 3025 - } 3038 + WCHAR *pwszExt = PathFindExtensionW(unquoted); 3039 + if (!_wcsicmp(pwszExt, L".lnk")) 3040 + { 3041 + // TODO: SLDF_ALLOW_LINK_TO_LINK (Win7+) 3042 + // FIXME load localized error msg 3043 + MessageBoxW(hwndDlg, L"You cannot create a link to a shortcut", NULL, MB_ICONERROR); 3044 + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); 3045 + return TRUE; 3046 + } 3026 3047 3027 - SetPath(unquoted); 3028 - if (lpszArgs) 3029 - SetArguments(lpszArgs); 3030 - else 3031 - SetArguments(L"\0"); 3048 + if (!PathFileExistsW(unquoted)) 3049 + { 3050 + // FIXME load localized error msg 3051 + MessageBoxW(hwndDlg, L"The specified file name in the target box is invalid", NULL, MB_ICONERROR); 3052 + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); 3053 + return TRUE; 3054 + } 3032 3055 3033 - HeapFree(GetProcessHeap(), 0, unquoted); 3056 + SetPath(unquoted); 3057 + SetArguments(lpszArgs ? lpszArgs : L"\0"); 3058 + } 3034 3059 3035 3060 m_Header.wHotKey = (WORD)SendDlgItemMessageW(hwndDlg, IDC_SHORTCUT_KEY_HOTKEY, HKM_GETHOTKEY, 0, 0); 3036 3061
-1
dll/win32/shell32/CShellLink.h
··· 87 87 LPDBLIST m_pDBList; /* Optional data block list (in the extra data section) */ 88 88 BOOL m_bInInit; // in initialization or not 89 89 HICON m_hIcon; 90 - UINT m_idCmdFirst; 91 90 92 91 /* Pointers to strings inside Logo3/Darwin info blocks, cached for debug info purposes only */ 93 92 LPWSTR sProduct;