https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9078e34f3cb3718b481de…
commit 9078e34f3cb3718b481de0e15d05b1f633efc9e9
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Oct 11 13:33:43 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Oct 11 13:33:43 2021 +0900
[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
---
dll/win32/shell32/CDefView.cpp | 23 +++++++++++++------
dll/win32/shell32/folders/CFSFolder.cpp | 40 +++++++++++++++++++++------------
dll/win32/shell32/shfldr.h | 2 +-
3 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/dll/win32/shell32/CDefView.cpp b/dll/win32/shell32/CDefView.cpp
index 03a639a9026..00e310397f4 100644
--- a/dll/win32/shell32/CDefView.cpp
+++ b/dll/win32/shell32/CDefView.cpp
@@ -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;
diff --git a/dll/win32/shell32/folders/CFSFolder.cpp
b/dll/win32/shell32/folders/CFSFolder.cpp
index f44a71f6b33..09c7574fd9c 100644
--- a/dll/win32/shell32/folders/CFSFolder.cpp
+++ b/dll/win32/shell32/folders/CFSFolder.cpp
@@ -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;
}
diff --git a/dll/win32/shell32/shfldr.h b/dll/win32/shell32/shfldr.h
index 8b60f6e32a8..7fd635f7385 100644
--- a/dll/win32/shell32/shfldr.h
+++ b/dll/win32/shell32/shfldr.h
@@ -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);