[SHELL32] Don't smartass-renaming on LNK files (#4020)

Renaming .LNK files had a bug that the selection won't include the extension-like filename part.
CORE-17807
This commit is contained in:
Katayama Hirofumi MZ 2021-10-11 13:33:43 +09:00 committed by GitHub
parent 3c36cde874
commit 9078e34f3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 22 deletions

View file

@ -2093,14 +2093,23 @@ LRESULT CDefView::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandl
HWND hEdit = reinterpret_cast<HWND>(m_ListView.SendMessage(LVM_GETEDITCONTROL));
SHLimitInputEdit(hEdit, m_pSFParent);
LPWSTR pszText = lpdi->item.pszText;
if (!(dwAttr & (SFGAO_LINK | SFGAO_FOLDER)) && (dwAttr & SFGAO_FILESYSTEM) &&
(lpdi->item.mask & LVIF_TEXT) &&
!SelectExtOnRename() && !SHELL_FS_HideExtension(pszText))
/* smartass-renaming: See CORE-15242 */
if (!(dwAttr & SFGAO_FOLDER) && (dwAttr & SFGAO_FILESYSTEM) &&
(lpdi->item.mask & LVIF_TEXT) && !SelectExtOnRename())
{
LPWSTR pchDotExt = PathFindExtensionW(pszText);
::PostMessageW(hEdit, EM_SETSEL, 0, pchDotExt - pszText);
::PostMessageW(hEdit, EM_SCROLLCARET, 0, 0);
WCHAR szFullPath[MAX_PATH];
PIDLIST_ABSOLUTE pidlFull = ILCombine(m_pidlParent, pidl);
SHGetPathFromIDListW(pidlFull, szFullPath);
if (!SHELL_FS_HideExtension(szFullPath))
{
LPWSTR pszText = lpdi->item.pszText;
LPWSTR pchDotExt = PathFindExtensionW(pszText);
::PostMessageW(hEdit, EM_SETSEL, 0, pchDotExt - pszText);
::PostMessageW(hEdit, EM_SCROLLCARET, 0, 0);
}
ILFree(pidlFull);
}
m_isEditing = TRUE;

View file

@ -1279,34 +1279,46 @@ static const WCHAR NeverShowExtW[] = L"NeverShowExt";
* TRUE, if the filename's extension should be hidden
* FALSE, otherwise.
*/
BOOL SHELL_FS_HideExtension(LPWSTR szPath)
BOOL SHELL_FS_HideExtension(LPCWSTR szPath)
{
HKEY hKey;
DWORD dwData;
DWORD dwDataSize = sizeof (DWORD);
DWORD dwData, dwDataSize = sizeof(DWORD);
BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
LONG lError;
if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
lError = RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
&hKey, NULL);
if (lError == ERROR_SUCCESS)
{
lError = RegQueryValueExW(hKey, HideFileExtW, NULL, NULL, (LPBYTE)&dwData, &dwDataSize);
if (lError == ERROR_SUCCESS)
doHide = dwData;
RegCloseKey (hKey);
RegCloseKey(hKey);
}
if (!doHide) {
LPWSTR ext = PathFindExtensionW(szPath);
if (*ext != '\0') {
if (!doHide)
{
LPCWSTR DotExt = PathFindExtensionW(szPath);
if (*DotExt != 0)
{
WCHAR classname[MAX_PATH];
LONG classlen = sizeof(classname);
if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
lError = RegQueryValueW(HKEY_CLASSES_ROOT, DotExt, classname, &classlen);
if (lError == ERROR_SUCCESS)
{
lError = RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey);
if (lError == ERROR_SUCCESS)
{
lError = RegQueryValueExW(hKey, NeverShowExtW, NULL, NULL, NULL, NULL);
if (lError == ERROR_SUCCESS)
doHide = TRUE;
RegCloseKey(hKey);
}
}
}
}
return doHide;
}

View file

@ -92,7 +92,7 @@ static __inline int SHELL32_GUIDToStringW (REFGUID guid, LPWSTR str)
}
void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath, DWORD dwFlags);
BOOL SHELL_FS_HideExtension(LPWSTR pwszPath);
BOOL SHELL_FS_HideExtension(LPCWSTR pwszPath);
void AddClassKeyToArray(const WCHAR * szClass, HKEY* array, UINT* cKeys);