2
0
Эх сурвалжийг харах

FIX: Bug [0002525] Feed to listbox does not show archive search results

Alexander Koblov 4 жил өмнө
parent
commit
3553c11ffc

+ 21 - 12
src/fFindDlg.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    Find dialog, with searching in thread
 
-   Copyright (C) 2006-2020 Alexander Koblov ([email protected])
+   Copyright (C) 2006-2021 Alexander Koblov ([email protected])
    Copyright (C) 2003-2004 Radek Cervinka ([email protected])
 
    This program is free software; you can redistribute it and/or modify
@@ -32,7 +32,7 @@ uses
   fAttributesEdit, uDsxModule, DsxPlugin, uFindThread, uFindFiles,
   uSearchTemplate, fSearchPlugin, uFileView, types, DCStrUtils,
   ActnList, uOSForms, uShellContextMenu, uExceptions, uFileSystemFileSource,
-  uFormCommands, uHotkeyManager, LCLVersion, uWcxModule;
+  uFormCommands, uHotkeyManager, LCLVersion, uWcxModule, uFileSource;
 
 {$IF DEFINED(LCLGTK2) or DEFINED(LCLQT) or DEFINED(LCLQT5)}
   {$DEFINE FIX_DEFAULT}
@@ -290,6 +290,7 @@ type
     FSearchWithWDXPluginInProgress: boolean;
     FFreeOnClose: boolean;
     FAtLeastOneSearchWasDone: boolean;
+    FFileSource: IFileSource;
     FWcxModule: TWcxModule;
 
     property Commands: TFormCommands read FCommands implements IFormCommands;
@@ -390,7 +391,7 @@ implementation
 
 uses
   LCLProc, LCLType, LConvEncoding, StrUtils, HelpIntfs, fViewer, fMain,
-  uLng, uGlobs, uShowForm, uDCUtils, uFileSource, uFileSourceUtil,
+  uLng, uGlobs, uShowForm, uDCUtils, uFileSourceUtil,
   uSearchResultFileSource, uFile, uFileProperty, uColumnsFileView,
   uFileViewNotebook, uKeyboard, uOSUtils, uArchiveFileSourceUtil,
   DCOSUtils, RegExpr, uDebug, uShowMsg, uConvEncoding, uColumns,
@@ -641,6 +642,7 @@ begin
   DsxPlugins := TDSXModuleList.Create;
   DsxPlugins.Assign(gDSXPlugins);
   FoundedStringCopy := TStringListTemp.Create;
+  FoundedStringCopy.OwnsObjects := True;
   FFreeOnClose := False;
   FAtLeastOneSearchWasDone := False;
   FSearchWithDSXPluginInProgress := False;
@@ -1334,7 +1336,8 @@ var
   AEnabled: Boolean;
   AFileSource: IWcxArchiveFileSource;
 begin
-  AEnabled:= aFileView.FileSource.IsClass(TWcxArchiveFileSource);
+  FFileSource:= aFileView.FileSource;
+  AEnabled:= FFileSource.IsClass(TWcxArchiveFileSource);
 
   cbOpenedTabs.Visible:= not AEnabled;
   cbSelectedFiles.Visible:= not AEnabled;
@@ -1351,7 +1354,7 @@ begin
   if not AEnabled then
     FWcxModule:= nil
   else begin
-    AFileSource:= (aFileView.FileSource as IWcxArchiveFileSource);
+    AFileSource:= (FFileSource as IWcxArchiveFileSource);
     FWcxModule:= AFileSource.WcxModule;
   end;
 
@@ -1822,19 +1825,26 @@ var
   AProperty: TFileVariantProperty;
   ANewSet: TPanelColumnsClass;
   NewSorting: TFileSortings;
+  AHeader: TWCXHeader;
 begin
   StopSearch;
 
   FileList := TFileTree.Create;
   for i := 0 to lsFoundedFiles.Items.Count - 1 do
   begin
-    sFileName := lsFoundedFiles.Items[I];
-    try
+    if Assigned(FWcxModule) then
+    begin
+      AHeader:= TWCXHeader(lsFoundedFiles.Items.Objects[I]);
+      aFile := TWcxArchiveFileSource.CreateFile(ExtractFilePath(AHeader.FileName), AHeader);
+      FileList.AddSubNode(aFile);
+    end
+    else try
+      sFileName := lsFoundedFiles.Items[I];
       aFile := TFileSystemFileSource.CreateFileFromFile(sFileName);
       if FLastSearchTemplate.SearchRecord.Duplicates then
       begin
         AProperty:= TFileVariantProperty.Create(PluginDuplicate);
-        AProperty.Value:= IntPtr(lsFoundedFiles.Items.Objects[I]);
+        AProperty.Value:= TDuplicate(lsFoundedFiles.Items.Objects[I]).Index;
         aFile.Properties[fpVariant]:= AProperty;
       end;
       FileList.AddSubNode(aFile);
@@ -1846,7 +1856,7 @@ begin
   // Create search result file source.
   // Currently only searching FileSystem is supported.
   SearchResultFS := TSearchResultFileSource.Create;
-  SearchResultFS.AddList(FileList, TFileSystemFileSource.GetFileSource);
+  SearchResultFS.AddList(FileList, FFileSource);
 
   // Add new tab for search results.
   Notebook := frmMain.ActiveNotebook;
@@ -2060,12 +2070,11 @@ end;
 function TfrmFindDlg.ObjectType(Index: Integer): TCheckBoxState;
 var
   ATemp: TObject;
-  AValue: PtrInt absolute ATemp;
 begin
   ATemp:= lsFoundedFiles.Items.Objects[Index];
-  if (ATemp) = nil then
+  if (ATemp = nil) then
     Result:= cbUnchecked
-  else if (AValue = High(PtrInt)) then
+  else if (ATemp is TWcxHeader) then
     Result:= cbChecked
   else
     Result:= cbGrayed;

+ 2 - 1
src/filesources/searchresult/usearchresultfilesource.pas

@@ -49,7 +49,8 @@ end;
 
 function TSearchResultFileSource.GetProperties: TFileSourceProperties;
 begin
-  Result := inherited GetProperties + [fspLinksToLocalFiles] - [fspNoneParent, fspListFlatView];
+  Result := inherited GetProperties - [fspNoneParent, fspListFlatView];
+  if (fspDirectAccess in Result) then Result+= [fspLinksToLocalFiles];
 end;
 
 function TSearchResultFileSource.SetCurrentWorkingDirectory(NewDir: String): Boolean;

+ 27 - 16
src/ufindthread.pas

@@ -33,10 +33,13 @@ uses
 
 type
 
+  { TDuplicate }
+
   TDuplicate = class
     Name: String;
     Index: IntPtr;
     Count: Integer;
+    function Clone: TDuplicate;
   end;
 
   { TFindThread }
@@ -62,6 +65,7 @@ type
     FExcludeFilesRegExp: TRegExprW;
     FRegExpr: TRegExpr;
     FArchive: TWcxModule;
+    FHeader: TWcxHeader;
 
     FTimeSearchStart:TTime;
     FTimeSearchEnd:TTime;
@@ -126,6 +130,14 @@ begin
     Result:= 1;
 end;
 
+{ TDuplicate }
+
+function TDuplicate.Clone: TDuplicate;
+begin
+  Result:= TDuplicate.Create;
+  Result.Index:= Self.Index;
+end;
+
 { TFindThread }
 
 constructor TFindThread.Create(const AFindOptions: TSearchTemplateRec; SelectedFiles: TStringList);
@@ -283,7 +295,7 @@ end;
 
 procedure TFindThread.AddArchiveFile;
 begin
-  FItems.AddObject(FFoundFile, TObject(High(IntPtr)));
+  FItems.AddObject(FFoundFile, FHeader.Clone);
 end;
 
 procedure TFindThread.AddDuplicateFile;
@@ -294,10 +306,10 @@ begin
   if AData.Count = 1 then
   begin
     Inc(FFilesFound);
-    FItems.AddObject(AData.Name, TObject(AData.Index));
+    FItems.AddObject(AData.Name, AData.Clone);
   end;
   Inc(FFilesFound);
-  FItems.AddObject(FFoundFile, TObject(AData.Index));
+  FItems.AddObject(FFoundFile, AData.Clone);
 end;
 
 function TFindThread.CheckDirectory(const CurrentDir, FolderName : String): Boolean;
@@ -491,7 +503,6 @@ end;
 procedure TFindThread.FindInArchive(const FileName: String);
 var
   Index: Integer;
-  Header: TWcxHeader;
 
   function CheckHeader: Boolean;
   var
@@ -505,28 +516,28 @@ var
       if IsFindText then
       begin
         // Skip directories
-        if (Header.FileAttr and faFolder) <> 0 then Exit(False);
+        if (FHeader.FileAttr and faFolder) <> 0 then Exit(False);
         // Some plugins end directories with path delimiter.
         // And not set directory attribute. Process this case.
-        NameLength := Length(Header.FileName);
-        if (NameLength > 0) and (Header.FileName[NameLength] = PathDelim) then
+        NameLength := Length(FHeader.FileName);
+        if (NameLength > 0) and (FHeader.FileName[NameLength] = PathDelim) then
           Exit(False);
       end;
 
-      DirectoryName:= ExtractFileName(ExtractFileDir(Header.FileName));
+      DirectoryName:= ExtractFileName(ExtractFileDir(FHeader.FileName));
       if not CheckDirectoryName(DirectoryName) then Exit(False);
 
-      if not CheckFileName(ExtractFileName(Header.FileName)) then
+      if not CheckFileName(ExtractFileName(FHeader.FileName)) then
         Exit(False);
 
       if (IsDateFrom or IsDateTo or IsTimeFrom or IsTimeTo or IsNotOlderThan) then
-        Result := CheckFileDateTime(FFileChecks, WcxFileTimeToDateTime(Header.FileTime));
+        Result := CheckFileDateTime(FFileChecks, WcxFileTimeToDateTime(FHeader.FileTime));
 
       if (IsFileSizeFrom or IsFileSizeTo) and Result then
-        Result := CheckFileSize(FFileChecks, Header.UnpSize);
+        Result := CheckFileSize(FFileChecks, FHeader.UnpSize);
 
       if Result then
-        Result := CheckFileAttributes(FFileChecks, Header.FileAttr);
+        Result := CheckFileAttributes(FFileChecks, FHeader.FileAttr);
     end;
   end;
 
@@ -581,12 +592,12 @@ begin
       WcxModule.WcxSetChangeVolProc(ArcHandle);
       WcxModule.WcxSetProcessDataProc(ArcHandle, @ProcessDataProcAG, @ProcessDataProcWG);
 
-      while (WcxModule.ReadWCXHeader(ArcHandle, Header) = E_SUCCESS) do
+      while (WcxModule.ReadWCXHeader(ArcHandle, FHeader) = E_SUCCESS) do
       begin
         Result:= CheckHeader;
         if Terminated then Break;
         Flags:= IfThen(Result, Operation, PK_SKIP);
-        if Flags = PK_EXTRACT then TargetFileName:= TargetPath + PathDelim + ExtractFileName(Header.FileName);
+        if Flags = PK_EXTRACT then TargetFileName:= TargetPath + PathDelim + ExtractFileName(FHeader.FileName);
         if WcxModule.WcxProcessFile(ArcHandle, Flags, EmptyStr, TargetFileName) = E_SUCCESS then
         begin
           with FSearchTemplate do
@@ -601,11 +612,11 @@ begin
         end;
         if Result then
         begin
-          FFoundFile := FileName + ReversePathDelim + Header.FileName;
+          FFoundFile := FileName + ReversePathDelim + FHeader.FileName;
           Synchronize(@AddArchiveFile);
           Inc(FFilesFound);
         end;
-        FreeAndNil(Header);
+        FreeAndNil(FHeader);
       end;
       if Operation = PK_EXTRACT then mbRemoveDir(TargetPath);
     finally