When we're hiding file extensions then SetNameOf should append the
authorHuw Davies <huw@codeweavers.com>
Fri, 15 Apr 2005 16:11:45 +0000 (16:11 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 15 Apr 2005 16:11:45 +0000 (16:11 +0000)
original extension if SHGDN_FORPARSING isn't set.
The flags passed to SetNameOf refer to the dst string not the src
pidl.

dlls/shell32/shfldr_fs.c

index 34f637c5c2b1bcbfe8286e1cf52d2c505bd7e321..4d0a9b449ae923b02f77cd5e94aad806869cd081 100644 (file)
@@ -686,45 +686,46 @@ static const WCHAR HideFileExtW[] = { 'H','i','d','e','F','i','l','e','E','x',
 static const WCHAR NeverShowExtW[] = { 'N','e','v','e','r','S','h','o','w','E',
  'x','t',0 };
 
-void SHELL_FS_ProcessDisplayFilename(LPSTR szPath, DWORD dwFlags)
+static BOOL hide_extension(LPWSTR szPath)
 {
-    /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
-    if (!(dwFlags & SHGDN_FORPARSING) &&
-        ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
-        HKEY hKey;
-        DWORD dwData;
-        DWORD dwDataSize = sizeof (DWORD);
-        BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
-
-        if (!RegCreateKeyExW (HKEY_CURRENT_USER, AdvancedW,
-         0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
-            if (!RegQueryValueExW (hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData,
-             &dwDataSize))
-                doHide = dwData;
-
-            RegCloseKey (hKey);
-        }
-
-        if (!doHide) {
-            LPSTR ext = PathFindExtensionA(szPath);
+    HKEY hKey;
+    DWORD dwData;
+    DWORD dwDataSize = sizeof (DWORD);
+    BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
+    
+    if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
+        if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
+            doHide = dwData;
+        RegCloseKey (hKey);
+    }
 
-            if (ext) {
-                char classname[MAX_PATH];
-                LONG classlen = MAX_PATH;
+    if (!doHide) {
+        LPWSTR ext = PathFindExtensionW(szPath);
 
-                if (!RegQueryValueA(HKEY_CLASSES_ROOT, ext, classname,
-                 &classlen))
-                    if (!RegOpenKeyA(HKEY_CLASSES_ROOT, classname, &hKey)) {
-                        if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL,
-                         NULL, NULL))
-                            doHide = TRUE;
+        if (*ext != '\0') {
+            WCHAR classname[MAX_PATH];
+            LONG classlen = sizeof(classname);
 
-                        RegCloseKey(hKey);
-                    }
-            }
+            if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
+                if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
+                    if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
+                        doHide = TRUE;
+                    RegCloseKey(hKey);
+                }
         }
+    }
+    return doHide;
+}
+    
+void SHELL_FS_ProcessDisplayFilename(LPSTR szPath, DWORD dwFlags)
+{
+    WCHAR pathW[MAX_PATH];
 
-        if (doHide && szPath[0] != '.')
+    /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
+    if (!(dwFlags & SHGDN_FORPARSING) &&
+        ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
+        MultiByteToWideChar(CP_ACP, 0, szPath, -1, pathW, MAX_PATH);
+        if (hide_extension(pathW) && szPath[0] != '.')
             PathRemoveExtensionA (szPath);
     }
 }
@@ -828,22 +829,30 @@ static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
      debugstr_w (lpName), dwFlags, pPidlOut);
 
     /* build source path */
-    if (dwFlags & SHGDN_INFOLDER) {
-        MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szSrc, MAX_PATH);
-        ptr = PathAddBackslashW (szSrc);
-        if (ptr)
-            _ILSimpleGetTextW (pidl, ptr, MAX_PATH - (ptr - szSrc));
-    } else {
-        /* FIXME: Can this work with a simple PIDL? */
-        SHGetPathFromIDListW (pidl, szSrc);
-    }
+    MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szSrc, MAX_PATH);
+    ptr = PathAddBackslashW (szSrc);
+    if (ptr)
+        _ILSimpleGetTextW (pidl, ptr, MAX_PATH - (ptr - szSrc));
 
     /* build destination path */
-    MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szDest, MAX_PATH);
-    ptr = PathAddBackslashW (szDest);
-    if (ptr)
-        lstrcpynW(ptr, lpName, MAX_PATH - (ptr - szDest));
+    if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) {
+        MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szDest, MAX_PATH);
+        ptr = PathAddBackslashW (szDest);
+        if (ptr)
+            lstrcpynW(ptr, lpName, MAX_PATH - (ptr - szDest));
+    } else
+        lstrcpynW(szDest, lpName, MAX_PATH);
+
+    if(!(dwFlags & SHGDN_FORPARSING) && hide_extension(szSrc)) {
+        WCHAR *ext = PathFindExtensionW(szSrc);
+        if(*ext != '\0') {
+            INT len = strlenW(szDest);
+            lstrcpynW(szDest + len, ext, MAX_PATH - len);
+        }
+    }
+    
     TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest));
+
     if (MoveFileW (szSrc, szDest)) {
         HRESULT hr = S_OK;