Browse Source

Removing unused icon caching code

Source commit: 75888342ea946d49c1cdd91dc8577196535861a3
Martin Prikryl 2 years ago
parent
commit
d18e42efd7

+ 0 - 4
source/DriveDir.cbproj

@@ -143,10 +143,6 @@
 			<BuildOrder>38</BuildOrder>
 			<BuildOrder>22</BuildOrder>
 		</DelphiCompile>
-		<DelphiCompile Include="packages\filemng\ListExt.pas">
-			<BuildOrder>56</BuildOrder>
-			<BuildOrder>2</BuildOrder>
-		</DelphiCompile>
 		<DelphiCompile Include="packages\filemng\ShellDialogs.pas">
 			<BuildOrder>41</BuildOrder>
 			<BuildOrder>3</BuildOrder>

+ 19 - 82
source/packages/filemng/DirView.pas

@@ -38,7 +38,7 @@ interface
 {$WARN SYMBOL_PLATFORM OFF}
 
 uses
-  Windows, ShlObj, ComCtrls, CompThread, CustomDirView, ListExt,
+  Windows, ShlObj, ComCtrls, CompThread, CustomDirView,
   ExtCtrls, Graphics, FileOperator, DiscMon, Classes, DirViewColProperties,
   DragDrop, Messages, ListViewColProperties, CommCtrl, DragDropFilesEx,
   FileCtrl, SysUtils, BaseUtils, Controls, CustomDriveView, System.Generics.Collections, Winapi.ShellAPI;
@@ -84,14 +84,6 @@ type
     CalculatedSize: Int64;
   end;
 
-  {Record for fileinfo caching:}
-  PInfoCache = ^TInfoCache;
-  TInfoCache = record
-    FileExt: string;
-    TypeName: string;
-    ImageIndex: Integer;
-  end;
-
 {Additional events:}
 type
   TDirViewFileSizeChanged = procedure(Sender: TObject; Item: TListItem) of object;
@@ -134,8 +126,6 @@ type
   private
     FConfirmDelete: Boolean;
     FConfirmOverwrite: Boolean;
-    FUseIconCache: Boolean;
-    FInfoCacheList: TListExt;
     FDriveView: TCustomDriveView;
     FChangeTimer: TTimer;
     FChangeInterval: Cardinal;
@@ -282,9 +272,6 @@ type
     procedure StopIconUpdateThread;
     procedure TerminateThreads;
 
-    {Other additional functions: }
-    procedure ClearIconCache;
-
     {Create a new subdirectory:}
     procedure CreateDirectory(DirName: string); override;
     {Delete all selected files:}
@@ -363,12 +350,6 @@ type
     {Fetch shell icons by thread:}
     property UseIconUpdateThread: Boolean
       read FUseIconUpdateThread write FUseIconUpdateThread default False;
-    {Enables or disables icon caching for registered file extensions. Caching enabled
-     enhances the performance but does not take care about installed icon handlers, wich
-     may modify the display icon for registered files. Only the iconindex is cached not the
-     icon itself:}
-    property UseIconCache: Boolean
-      read FUseIconCache write FUseIconCache default False;
     {Watch current directory for filename changes (create, rename, delete files)}
     property WatchForChanges;
 
@@ -426,14 +407,6 @@ begin
   RegisterComponents('DriveDir', [TDirView]);
 end; {Register}
 
-function CompareInfoCacheItems(I1, I2: Pointer): Integer;
-begin
-  if PInfoCache(I1)^.FileExt < PInfoCache(I2)^.FileExt then Result := fLess
-    else
-  if PInfoCache(I1)^.FileExt > PInfoCache(I2)^.FileExt then Result := fGreater
-    else Result := fEqual;
-end; {CompareInfoCacheItems}
-
 function MatchesFileExt(Ext: string; const FileExtList: string): Boolean;
 begin
   Result := (Length(Ext) = 3) and (Pos(Ext, FileExtList) <> 0);
@@ -825,9 +798,7 @@ constructor TDirView.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
 
-  FInfoCacheList := TListExt.Create(SizeOf(TInfoCache));
   FDriveType := DRIVE_UNKNOWN;
-  FUseIconCache := False;
   FConfirmDelete := True;
   FParentFolder := nil;
   FDesktopFolder := nil;
@@ -871,7 +842,6 @@ begin
   if Assigned(PIDLRecycle) then FreePIDL(PIDLRecycle);
 
   FLastPath.Free;
-  FInfoCacheList.Free;
   FFileOperator.Free;
   FChangeTimer.Free;
 
@@ -1461,7 +1431,6 @@ begin
 
   finally
     //if Assigned(Animate) then Animate.Free;
-    FInfoCacheList.Sort(CompareInfoCacheItems);
   end; {Finally}
 end;
 
@@ -1759,12 +1728,6 @@ begin
     else inherited;
 end; {ReLoad}
 
-procedure TDirView.ClearIconCache;
-begin
-  if Assigned(FInfoCacheList) then
-    FInfoCacheList.Clear;
-end; {ClearIconCache}
-
 function TDirView.FormatFileTime(FileTime: TFileTime): string;
 begin
   Result := FormatDateTime(DateTimeFormatStr,
@@ -1811,9 +1774,6 @@ end;
 procedure TDirView.GetDisplayData(Item: TListItem; FetchIcon: Boolean);
 var
   FileInfo: TShFileInfo;
-  Index: Integer;
-  PExtItem: PInfoCache;
-  CacheItem: TInfoCache;
   IsSpecialExt: Boolean;
   ForceByName: Boolean;
   Eaten: ULONG;
@@ -1824,18 +1784,6 @@ begin
   with PFileRec(Item.Data)^ do
   begin
     IsSpecialExt := MatchesFileExt(FileExt, SpecialExtensions);
-    if FUseIconCache and not IsSpecialExt and not IsDirectory then
-    begin
-      CacheItem.FileExt := FileExt;
-      Index := FInfoCacheList.FindSequential(Addr(CacheItem), CompareInfoCacheItems);
-      if Index >= 0 then
-      begin
-        TypeName := PInfoCache(FInfoCacheList[Index])^.TypeName;
-        ImageIndex  := PInfoCache(FInfoCacheList[Index])^.ImageIndex;
-        Empty := False;
-        IconEmpty := False;
-      end;
-    end;
 
     FetchIcon := IconEmpty and (FetchIcon or not IsSpecialExt);
 
@@ -1939,19 +1887,8 @@ begin
           end; {Except}
         end;
 
-        if (Length(TypeName) > 0) then
-        begin
-          {Fill FileInfoCache:}
-          if FUseIconCache and not IsSpecialExt and not IconEmpty and not IsDirectory then
-          begin
-            GetMem(PExtItem, SizeOf(TInfoCache));
-            PExtItem.FileExt := FileExt;
-            PExtItem.TypeName := TypeName;
-            PExtItem.ImageIndex := ImageIndex;
-            FInfoCacheList.Add(PExtItem);
-          end;
-        end
-          else TypeName := Format(STextFileExt, [FileExt]);
+        if Length(TypeName) = 0 then
+          TypeName := Format(STextFileExt, [FileExt]);
       end {If FetchIcon}
         else
       begin
@@ -2044,10 +1981,10 @@ var
 begin
   Time1 := Int64(P1.FileTime.dwHighDateTime) shl 32 + P1.FileTime.dwLowDateTime;
   Time2 := Int64(P2.FileTime.dwHighDateTime) shl 32 + P2.FileTime.dwLowDateTime;
-  if Time1 < Time2 then Result := fLess
+  if Time1 < Time2 then Result := -1
     else
-  if Time1 > Time2 then Result := fGreater
-    else Result := fEqual; // fallback
+  if Time1 > Time2 then Result := 1
+    else Result := 0; // fallback
 end;
 
 function GetItemFileSize(P: PFileRec): Int64; inline;
@@ -2064,24 +2001,24 @@ var
   P1, P2: PFileRec;
 begin
   ConsiderDirection := True;
-  if I1 = I2 then Result := fEqual
+  if I1 = I2 then Result := 0
     else
-  if I1 = nil then Result := fLess
+  if I1 = nil then Result := -1
     else
-  if I2 = nil then Result := fGreater
+  if I2 = nil then Result := 1
     else
   begin
     P1 := PFileRec(I1.Data);
     P2 := PFileRec(I2.Data);
     if P1.isParentDir then
     begin
-      Result := fLess;
+      Result := -1;
       ConsiderDirection := False;
     end
       else
     if P2.isParentDir then
     begin
-      Result := fGreater;
+      Result := 1;
       ConsiderDirection := False;
     end
       else
@@ -2090,18 +2027,18 @@ begin
     begin
       if P1.isDirectory then
       begin
-        Result := fLess;
+        Result := -1;
         ConsiderDirection := False;
       end
         else
       begin
-        Result := fGreater;
+        Result := 1;
         ConsiderDirection := False;
       end;
     end
       else
     begin
-      Result := fEqual;
+      Result := 0;
 
       if P1.isDirectory and AOwner.AlwaysSortDirectoriesByName then
       begin
@@ -2114,9 +2051,9 @@ begin
             ; // fallback
 
           dvSize:
-            if GetItemFileSize(P1) < GetItemFileSize(P2) then Result := fLess
+            if GetItemFileSize(P1) < GetItemFileSize(P2) then Result := -1
               else
-            if GetItemFileSize(P1) > GetItemFileSize(P2) then Result := fGreater
+            if GetItemFileSize(P1) > GetItemFileSize(P2) then Result := 1
               else ; // fallback
 
           dvType:
@@ -2126,9 +2063,9 @@ begin
             Result := CompareFileTime(P1, P2);
 
           dvAttr:
-            if P1.Attr < P2.Attr then Result := fLess
+            if P1.Attr < P2.Attr then Result := -1
               else
-            if P1.Attr > P2.Attr then Result := fGreater
+            if P1.Attr > P2.Attr then Result := 1
               else ; // fallback
 
           dvExt:
@@ -2145,7 +2082,7 @@ begin
         end;
       end;
 
-      if Result = fEqual then
+      if Result = 0 then
       begin
         Result := CompareLogicalTextPas(P1.DisplayName, P2.DisplayName, AOwner.NaturalOrderNumericalSorting)
       end;

+ 1 - 1
source/packages/filemng/DriveView.pas

@@ -44,7 +44,7 @@ uses
   Windows, Messages, SysUtils, Classes,  Graphics, Controls, Forms, ComObj,
   Dialogs, ComCtrls, ShellApi, CommCtrl, ExtCtrls, ActiveX,  ShlObj,
   DirView, ShellDialogs, DragDrop, DragDropFilesEx, FileChanges, FileOperator,
-  DiscMon, IEDriveInfo, IEListView, PIDL, BaseUtils, ListExt, CustomDirView,
+  DiscMon, IEDriveInfo, IEListView, PIDL, BaseUtils, CustomDirView,
   CustomDriveView, System.Generics.Collections;
 
 const

+ 0 - 316
source/packages/filemng/ListExt.pas

@@ -1,316 +0,0 @@
-unit ListExt;
-{==================================================================
-
- Component TListExt  /  Version 1.0  / 03.1999
- =============================================
-
-    Description:
-    ============
-    My own version of managing sorted lists.
-
-    Author:
-    =======
-    (c) Ingo Eckel
-    Sodener Weg 38
-    65812 Bad Soden
-    Germany
-
- ==================================================================}
-
-
-{==================================================================}
-interface
-{==================================================================}
-
-Uses Classes,
-     SysUtils;
-
-Const InitSize   = 500;
-      ExtendSize = 500;
-      FLess      = -1;
-      FEqual     = 0;
-      FGreater   = 1;
-
-Type IntType     = Integer;
-
-     TLxDeleteEvent = Procedure(Sender : TObject; Var P : Pointer; Size : Integer) Of Object;
-
-{==================================================================}
-     TListExt = Class(TInterfacedobject)
-{==================================================================}
-     Private
-{==================================================================}
-       FCount   : IntType;
-       FData    : Array of Pointer;
-       FSorted  : Boolean;
-       fOnDelete: TLxDeleteEvent;
-       FItemSize: IntType;
-       MaxCount : IntType;
-
-       Function  GetItem  ( I : IntType) : Pointer;
-       Procedure FreeItem ( I : IntType);
-
-
-{==================================================================}
-     Public
-{==================================================================}
-       property data[i : IntType] : Pointer Read GetItem; default;
-       Property Sorted : Boolean            Read fSorted;
-       Property Count : IntType Read FCount;
-       Property ItemSize : IntType Read FItemSize;
-       Constructor Create(ItemSize : IntType);
-       Procedure Free;
-       Procedure Clear;
-       Procedure Add(P : Pointer);
-       Function  IndexOf(P : Pointer) : IntType;
-       Procedure Sort(Compare : TListSortCompare);
-       Function  Find(P : Pointer; Compare : TListSortCompare) : Integer;
-       Function  FindSequential(P : Pointer; Compare : TListSortCompare) : Integer;
-       Function  First : Pointer;
-       Function  Last  : Pointer;
-       procedure Delete(I: IntType);
-
-{==================================================================}
-     Published
-{==================================================================}
-       Property OnDelete: TLxDeleteEvent Read  fOnDelete
-                                         Write fOnDelete;
-     End;
-
-{==================================================================}
-implementation
-{==================================================================}
-
-uses
-  Math;
-
-Constructor TListExt.Create(ItemSize : IntType);
-Var i : IntType;
-Begin
-  IF ItemSize < 0 Then
-  Raise ERangeError.CreateFmt('TListExt: negative itemsize: %u',[ItemSize]);
-  Inherited Create;
-  FCount := 0;
-  MaxCount := InitSize;
-  FSorted  := TRUE;
-  FItemSize := ItemSize;
-  SetLength(FData, MaxCount+1);
-  For i := 0 To MaxCount Do
-  FData[i] := NIL;
-End; {Create}
-
-
-Procedure TListExt.Free;
-Begin
-  Clear;
-  FData := NIL;
-  Inherited Free;
-End;
-
-
-Procedure TListExt.Add(P : Pointer);
-
-Begin
-  IF Fcount = MaxCount Then
-  Begin
-    INC(MaxCount, ExtendSize);
-    SetLength(FData, MaxCount + 1);
-  End;
-
-
-  IF FCount >= MaxCount Then
-  Raise ERangeError.CreateFmt('TListExt: buffer overflow: %u',[Fcount]);
-
-  INC (FCount);
-  FData[Pred(FCount)] := P;
-  FSorted := FALSE;
-End; {Add}
-
-
-Function TListExt.IndexOf(P : Pointer) : IntType;
-Var i : IntType;
-Begin
-  Result := 0;
-  IF Not Assigned(P) Then Exit;
-  For i := 0 To FCount Do
-  IF P = FData[i] Then
-  Begin
-    Result := i;
-    Exit;
-  End;
-End; {IndexOf}
-
-
-Procedure TListExt.FreeItem(I : IntType);
-Begin
-  Begin
-    IF Assigned(FData[i]) Then
-    Begin
-      IF Assigned(fOnDelete) Then
-      Begin
-        fOnDelete(Self, FData[i], FItemSize);
-        IF Assigned(FData[i]) Then
-        FreeMem(FData[i], FItemSize);
-      End
-      Else
-      FreeMem(FData[i], FItemSize);
-      FData[i] := NIL;
-    End;
-  End;
-End; {FreeItem}
-
-
-Procedure TListExt.Clear;
-Var i : IntType;
-Begin
-  For i := 0 To Pred(FCount) Do
-  Begin
-    IF Assigned(FData[i]) Then
-      FreeItem(i)
-    Else
-      Break;
-  End;
-  FCount := 0;
-  FSorted  := TRUE;
-  MaxCount := InitSize;
-  SetLength(FData, MaxCount + 1);
-End; {Clear}
-
-
-Function TListExt.GetItem(I : IntType) : Pointer;
-Begin
-  IF (i >= FCount) Then
-  Begin
-    Raise ERangeError.CreateFmt('TListExt: index out of range: %u',[i]);
-    Result := NIL;
-    Exit;
-  End;
-  Result := FData[i];
-End; {GetItem}
-
-
-Function TListExt.First : Pointer;
-Begin
-  Result := NIL;
-  IF Count > 0 Then
-  Result := FData[0];
-End; {First}
-
-
-Function TListExt.Last  : Pointer;
-Begin
-  Result := NIL;
-  IF Count > 0 Then
-  Result := FData[Pred(FCount)];
-End; {Last}
-
-
-
-Procedure TListExt.Delete(i : IntType);
-Begin
-  IF (FCount = 0) Or (i > Pred(FCount)) Then Exit;
-  FreeItem(i);
-
-  IF FCount - Succ(i) > 0 Then
-    Move(FData[Succ(i)], FData[i], ( FCount - Succ(i) ) * SizeOf(Pointer));
-
-  Dec(FCount);
-  FData[FCount] := NIL;
-End; {Delete}
-
-
-Function TListExt.Find(P : Pointer; Compare : TListSortCompare) : Integer;
-var nResult   : integer;
-    nLow      : integer;
-    nHigh     : integer;
-    nCompare  : integer;
-    nCheckPos : integer;
-
-Begin
-  Result := -1;
-  IF Not Assigned(P) Or (FCount < 1) Then
-  Exit;
-  IF not Sorted Then
-  Sort(Compare);
-
-  nLow    := 0;
-  nHigh   := Count - 1;
-  nResult := - 1;
-  { Perform a binary search:}
-  while (nResult = -1) and (nLow <= nHigh) do
-  begin
-      nCheckPos := (nLow + nHigh) div 2;
-      nCompare := Compare(P, FData[nCheckPos]);
-      if (nCompare = fLess) Then nHigh := nCheckPos - 1 { less than }
-      else if (nCompare = fGreater) then nLow := nCheckPos + 1 { greater than }
-           else nResult := nCheckPos; { equal to }
-  end;
-  Result := nResult;
-End; {Find}
-
-
-Function TListExt.FindSequential(P : Pointer; Compare : TListSortCompare) : Integer;
-Var i : Integer;
-
-Begin
-  Result := -1;
-  IF Not Assigned(P) Then
-  Exit;
-
-  IF Sorted Then
-  Result := Find(P, Compare)
-  Else
-  Begin
-    For i := 0 To Pred(FCount) Do
-    Begin
-      IF Compare(P, FData[i]) = 0 Then
-      Begin
-        Result := i;
-        Exit;
-      End;
-    End;
-  End;
-End; {FindSequential}
-
-
-Procedure TListExt.Sort(Compare : TListSortCompare);
-
-PROCEDURE quicksort(VAR a: Array of Pointer; LO,HI: IntType);
-
-PROCEDURE sort(L,R: IntType);
-VAR i,j : IntType;
-    x,y : Pointer;
-
-BEGIN
-  i := L;
-  j := R;
-  x := a[(L+R) DIV 2];
-  REPEAT
-    WHILE Compare(a[i], x) = fLess DO
-    i := i + 1;
-    WHILE Compare(x, a[j]) = FLess DO
-      j := j - 1;
-    IF i <= j THEN
-    BEGIN
-      y:=a[i];
-      a[i]:=a[j];
-      a[j]:=y;
-      i:=i+1;
-      j:=j-1;
-    END;
-  UNTIL i>j;
-  IF L<j THEN sort(L,j);
-  IF i<R THEN sort(i,R);
-END; (* Sort *)
-
-BEGIN
-  sort(LO,HI);
-END; (* QuickSort *)
-
-Begin
-  IF (Self.FCount > 1) And Not Sorted Then
-    QuickSort(Self.FData, 0,  Pred(Self.FCount));
-  FSorted := TRUE;
-End; {Sort}
-
-end.