Re: [ros-diffs] 01/01: improve SHGetFileInfo (#118)

Pierre Schweitzer <[email protected]>
Newsgroups gmane.os.reactos.kernel
Message-ID <[email protected]>
For the record, the commit doesn't match our contributing rules and
should be avoided in the future.
Reference: https://github.com/reactos/reactos/blob/master/.gitmessage

Le 16/02/2018 à 12:00, Katayama Hirofumi MZ a écrit :
> https://git.reactos.org/?p=reactos.git;a=commitdiff;h=338799bf8bf98698f3e4c1c2b885d724a9a929da
> 
> commit 338799bf8bf98698f3e4c1c2b885d724a9a929da
> Author:     Katayama Hirofumi MZ <[email protected]>
> AuthorDate: Fri Feb 16 20:00:08 2018 +0900
> Commit:     Ged Murphy <[email protected]>
> CommitDate: Fri Feb 16 11:00:08 2018 +0000
> 
>     improve SHGetFileInfo (#118)
>     
>     This patch reduces failures of SHGetFileInfo function. CORE-7159
>     * improve WideByteToWideChar calls
>     * fix bugs related to file attributes and SHGFI_EXETYPE
>     * SHGFI_USEFILEATTRIBUTES and SHGFI_ICON fix
>     * s/sizeof(temppsfi)/0/
> ---
>  dll/win32/shell32/wine/shell32_main.c | 81 +++++++++++++++++++++--------------
>  1 file changed, 49 insertions(+), 32 deletions(-)
> 
> diff --git a/dll/win32/shell32/wine/shell32_main.c b/dll/win32/shell32/wine/shell32_main.c
> index b5638f0582..e64ef7f6fb 100644
> --- a/dll/win32/shell32/wine/shell32_main.c
> +++ b/dll/win32/shell32/wine/shell32_main.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright 1998 Marcus Meissner
>   * Copyright 1998 Juergen Schmied (jsch)  *  <[email protected]>
> + * Copyright 2017 Katayama Hirofumi MZ <[email protected]>
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -433,7 +434,7 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>      {
>          psfi->szDisplayName[0] = '\0';
>          psfi->szTypeName[0] = '\0';
> -        psfi->iIcon = 0;
> +        psfi->hIcon = NULL;
>      }
>  
>      if (!(flags & SHGFI_PIDL))
> @@ -449,12 +450,24 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>              lstrcpynW(szFullPath, path, MAX_PATH);
>          }
>      }
> +    else
> +    {
> +        SHGetPathFromIDListW((LPITEMIDLIST)path, szFullPath);
> +    }
>  
>      if (flags & SHGFI_EXETYPE)
>      {
> -        if (flags != SHGFI_EXETYPE)
> -            return 0;
> -        return shgfi_get_exe_type(szFullPath);
> +        if (!(flags & SHGFI_SYSICONINDEX))
> +        {
> +            if (flags & SHGFI_USEFILEATTRIBUTES)
> +            {
> +                return TRUE;
> +            }
> +            else if (GetFileAttributesW(szFullPath) != INVALID_FILE_ATTRIBUTES)
> +            {
> +                return shgfi_get_exe_type(szFullPath);
> +            }
> +        }
>      }
>  
>      /*
> @@ -488,6 +501,8 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>                                  (LPCITEMIDLIST*)&pidlLast );
>              if (SUCCEEDED(hr))
>                  pidlLast = ILClone(pidlLast);
> +            else
> +                hr = S_OK;
>              ILFree(pidl);
>          }
>          else
> @@ -505,8 +520,18 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>              psfi->dwAttributes = 0xffffffff;
>          }
>          if (psfParent)
> -            IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
> -                                      &(psfi->dwAttributes) );
> +        {
> +            IShellFolder_GetAttributesOf(psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
> +                                         &(psfi->dwAttributes));
> +        }
> +    }
> +
> +    if (flags & SHGFI_USEFILEATTRIBUTES)
> +    {
> +        if (flags & SHGFI_ICON)
> +        {
> +            psfi->dwAttributes = 0;
> +        }
>      }
>  
>      /* get the displayname */
> @@ -516,7 +541,7 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>          {
>              lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
>          }
> -        else
> +        else if (psfParent)
>          {
>              STRRET str;
>              hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
> @@ -618,7 +643,7 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>                      ret = FALSE;
>              }
>          }
> -        else
> +        else if (psfParent)
>          {
>              hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
>                  (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
> @@ -694,7 +719,7 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
>                  }
>              }
>          }
> -        else
> +        else if (psfParent)
>          {
>              if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
>                  uGilFlags, &(psfi->iIcon))))
> @@ -769,33 +794,25 @@ DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
>          pathW = temppath;
>      }
>  
> -    if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
> -        temppsfi.dwAttributes=psfi->dwAttributes;
> +    if (psfi)
> +    {
> +        temppsfi.hIcon = psfi->hIcon;
> +        temppsfi.iIcon = psfi->iIcon;
> +        temppsfi.dwAttributes = psfi->dwAttributes;
>  
> -    if (psfi == NULL)
> -        ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, 0, flags);
> -    else
>          ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
> +        psfi->hIcon = temppsfi.hIcon;
> +        psfi->iIcon = temppsfi.iIcon;
> +        psfi->dwAttributes = temppsfi.dwAttributes;
>  
> -    if (psfi)
> -    {
> -        if(flags & SHGFI_ICON)
> -            psfi->hIcon=temppsfi.hIcon;
> -        if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
> -            psfi->iIcon=temppsfi.iIcon;
> -        if(flags & SHGFI_ATTRIBUTES)
> -            psfi->dwAttributes=temppsfi.dwAttributes;
> -        if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
> -        {
> -            WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
> -                  psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
> -        }
> -        if(flags & SHGFI_TYPENAME)
> -        {
> -            WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
> -                  psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
> -        }
> +        WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
> +              psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
> +
> +        WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
> +              psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
>      }
> +    else
> +        ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, 0, flags);
>  
>      HeapFree(GetProcessHeap(), 0, temppath);
>  
> 


-- 
Pierre Schweitzer <pierre at reactos.org>
System & Network Administrator
Senior Kernel Developer
ReactOS Deutschland e.V.

_______________________________________________
Ros-dev mailing list
[email protected]
http://www.reactos.org/mailman/listinfo/ros-dev
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJahszTAAoJEHVFVWw9WFsLzMQQAIF8/tdJLWuepWOWyoxFKj5A
y6hwvmWfEm+t+9MJ4kKhwcjjBi/cLzLWI02iA0W56lg+CY/cLCeHWs0ajhWD0jU2
0WW34DmfA0YyV1twAr+Sa7g28c/BmGL1QOSXF8/qcReu/hfBoK8wXwNJalNWwjoq
LqLMqr+y1E/oLaj+NHEW0+qqKHXU0ZPDL3tbJ96vrS+lh/0D1PC1a+PD0ffJomOT
UgS0CoU9dvFT7o7okvaFlP2NksEdXCUzMIQ90oOf+cjqE8P349HWrusYgVu8JySj
Wevma1CLqQRKRWAXriIpOMMSTidUKKLX482p8wXLPFEPEVdjXymsfzRVT0ic4Bwz
pEoBcN3CLnbFcsFpXnlak74xy8qoNSgBypFvzLPiGDjKIEIZe79XP5mbeSjruwQ4
rBxasMlUIWWZs+PdoKkq9hPoyHgGPOf+gTvb/O0on6SNJnbyyJ6w4p38jwr32ray
X9O9oxPk/W19q8eEgBZ9LtjaoWrR+oaRotpthtS6eqqJcOtxgkINHK3Ek/Ftwm2W
jhrZFKZwN/NFvVeDQkh4bkZFKlMGtSf2mLMCzY6yjQ5+qB1L4bOARvXqISMZ3EWl
jJFX+K7+c3ah5B9NnZwkoXe5OcNwWLAMh1NODU4TxJGYZYx3vxoVY9kL+NbYpmy+
K6uPDxmJM2AReD5o/bf5
=hByX
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.