Browse Source

Bug 1556: Skip loading of files icons when it takes too long

https://winscp.net/tracker/1556

Source commit: 69b91195389c51bcf68e9b546a53fc7f76c2e08d
Martin Prikryl 8 năm trước cách đây
mục cha
commit
e909b850ab

+ 5 - 4
source/packages/filemng/DirView.pas

@@ -1717,8 +1717,8 @@ begin
             begin
               // Files with PIDL are typically .exe files.
               // It may take long to retrieve an icon from exe file.
-              if SHGetFileInfoForPidlWithTimeout(
-                   PIDL, FILE_ATTRIBUTE_NORMAL, FileInfo, SizeOf(FileInfo),
+              if SHGetFileInfoWithTimeout(
+                   PChar(PIDL), FILE_ATTRIBUTE_NORMAL, FileInfo, SizeOf(FileInfo),
                    SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES or SHGFI_SYSICONINDEX or SHGFI_PIDL,
                    MSecsPerSec div 4) = 0 then
               begin
@@ -1728,8 +1728,9 @@ begin
             end
               else
             begin
-              SHGetFileInfo(PChar(FileIconForName), FILE_ATTRIBUTE_NORMAL, FileInfo, SizeOf(FileInfo),
-                SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES or SHGFI_SYSICONINDEX);
+              SHGetFileInfoWithTimeout(PChar(FileIconForName), FILE_ATTRIBUTE_NORMAL, FileInfo, SizeOf(FileInfo),
+                SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES or SHGFI_SYSICONINDEX,
+                MSecsPerSec div 4);
             end;
 
             TypeName := FileInfo.szTypeName;

+ 27 - 8
source/packages/my/OperationWithTimeout.pas

@@ -8,8 +8,8 @@ uses
 function ShellFolderGetAttributesOfWithTimeout(
   ShellFolder: IShellFolder; cidl: UINT; var apidl: PItemIDList; var rgfInOut: UINT; Timeout: Integer): HResult;
 
-function SHGetFileInfoForPidlWithTimeout(
-  PIDL: PItemIDList; dwFileAttributes: DWORD; var psfi: TSHFileInfoW;
+function SHGetFileInfoWithTimeout(
+  pszPath: LPCWSTR; dwFileAttributes: DWORD; var psfi: TSHFileInfoW;
   cbFileInfo, uFlags: UINT; Timeout: Integer): DWORD_PTR;
 
 function ShellFolderParseDisplayNameWithTimeout(
@@ -40,6 +40,7 @@ type
 
     // SHGetFileInfoWithTimeout
     PIDL: PItemIDList;
+    Path: string;
     dwFileAttributes: DWORD;
     psfi: TSHFileInfoW;
     cbFileInfo, uFlags: UINT;
@@ -229,21 +230,39 @@ begin
   end;
 end;
 
-procedure SHGetFileInfoForPidlOperation(Operation: TOperation);
+procedure SHGetFileInfoOperation(Operation: TOperation);
+var
+  pszPath: LPCWSTR;
 begin
+  if Operation.uFlags and SHGFI_PIDL <> 0 then
+  begin
+    pszPath := LPCWSTR(Operation.PIDL);
+  end
+    else
+  begin
+    pszPath := LPCWSTR(Operation.Path);
+  end;
+
   Operation.ResultDWordPtr :=
-    SHGetFileInfo(PChar(Operation.PIDL), Operation.dwFileAttributes, Operation.psfi, Operation.cbFileInfo, Operation.uFlags);
+    SHGetFileInfo(pszPath, Operation.dwFileAttributes, Operation.psfi, Operation.cbFileInfo, Operation.uFlags);
 end;
 
-function SHGetFileInfoForPidlWithTimeout(
-  PIDL: PItemIDList; dwFileAttributes: DWORD; var psfi: TSHFileInfoW;
+function SHGetFileInfoWithTimeout(
+  pszPath: LPCWSTR; dwFileAttributes: DWORD; var psfi: TSHFileInfoW;
   cbFileInfo, uFlags: UINT; Timeout: Integer): DWORD_PTR;
 var
   Operation: TOperation;
 begin
   NeedThread;
-  Operation := TOperation.Create(SHGetFileInfoForPidlOperation);
-  Operation.PIDL := PIDL;
+  Operation := TOperation.Create(SHGetFileInfoOperation);
+  if uFlags and SHGFI_PIDL <> 0 then
+  begin
+    Operation.PIDL := PItemIDList(pszPath);
+  end
+    else
+  begin
+    Operation.Path := pszPath;
+  end;
   Operation.dwFileAttributes := dwFileAttributes;
   Operation.psfi := psfi;
   Operation.cbFileInfo := cbFileInfo;