diff options
Diffstat (limited to 'UCore.pas')
| -rw-r--r-- | UCore.pas | 78 |
1 files changed, 58 insertions, 20 deletions
@@ -28,7 +28,7 @@ function FillPanel(List: TList; ListView: TGTKListView; Engine: TPanelEngine; Le procedure FindNextSelected(ListView: TGTKListView; DataList: TList; var Item1, Item2: string); procedure UnselectAll(ListView: TGTKListView; DataList: TList); -procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStringList; DoNotRecurse: boolean); +procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStringList; DoNotRecurse, SortForStream: boolean); function GetFileInfoSL(Engine: TPanelEngine; const APath: string): PDataItemSL; procedure DebugWriteListSL(List: TList); @@ -348,16 +348,25 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) -procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStringList; DoNotRecurse: boolean); +procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStringList; DoNotRecurse, SortForStream: boolean); +var DirStage1List, FilesList, DirStage2List: TList; - function FillDirFiles_compare_func(Item1, Item2: PDataItem): integer; + function FillDirFiles_compare_func(Item1, Item2: Pointer): integer; + var DataItem1, DataItem2: PDataItem; begin + if not SortForStream then begin + DataItem1 := Item1; + DataItem2 := Item2; + end else begin + DataItem1 := PDataItemSL(Item1)^.DataItem; + DataItem2 := PDataItemSL(Item2)^.DataItem; + end; // sort by inode number // also, we want to have directories at the bottom of the list - if Item1^.IsDir and (not Item2^.IsDir) then Result := 1 else - if (not Item1^.IsDir) and Item2^.IsDir then Result := -1 else - if Item1^.inode_no > Item2^.inode_no then Result := 1 else - if Item1^.inode_no < Item2^.inode_no then Result := -1 else + if DataItem1^.IsDir and (not DataItem2^.IsDir) then Result := 1 else + if (not DataItem1^.IsDir) and DataItem2^.IsDir then Result := -1 else + if DataItem1^.inode_no > DataItem2^.inode_no then Result := 1 else + if DataItem1^.inode_no < DataItem2^.inode_no then Result := -1 else Result := 0; end; @@ -389,9 +398,16 @@ procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStrin end; procedure FillDirFiles_sort(FList: TList); + var i: integer; begin if FList.Count < 2 then Exit; + writeln('before sorting:'); + for i := 0 to FList.Count - 1 do + writeln(' ', i, ' [', PDataItemSL(FList[i])^.DataItem^.inode_no, '] ', PDataItemSL(FList[i])^.DataItem^.FName); QuickSort(Flist, 0, FList.Count - 1); + writeln('after sorting:'); + for i := 0 to FList.Count - 1 do + writeln(' ', i, ' [', PDataItemSL(FList[i])^.DataItem^.inode_no, '] ', PDataItemSL(FList[i])^.DataItem^.FName); end; procedure FillDirFiles_Recurse(const LocalPath: string; ALevel: integer); @@ -403,14 +419,7 @@ procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStrin begin LocalList := TList.Create; if Engine.GetListing(LocalList, LocalPath, True, False, True) = 0 then begin - writeln('before sorting:'); - for i := 0 to LocalList.Count - 1 do - writeln(' ', i, ' [', PDataItem(LocalList[i])^.inode_no, '] ', PDataItem(LocalList[i])^.FName); - FillDirFiles_sort(LocalList); - writeln('after sorting:'); - for i := 0 to LocalList.Count - 1 do - writeln(' ', i, ' [', PDataItem(LocalList[i])^.inode_no, '] ', PDataItem(LocalList[i])^.FName); - + if not SortForStream then FillDirFiles_sort(LocalList); for i := 0 to LocalList.Count - 1 do begin Item := LocalList[i]; ItemSL := malloc(sizeof(TDataItemSL)); @@ -419,7 +428,10 @@ procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStrin ItemSL^.Stage1 := True; ItemSL^.IsOnRO := Engine.IsOnROMedium(string(Item^.FName)); ItemSL^.Level := ALevel; - DestList.Add(ItemSL); + if not SortForStream then DestList.Add(ItemSL) else begin + if Item^.IsDir then DirStage1List.Add(ItemSL) + else FilesList.Add(ItemSL); + end; if Item^.IsDir then begin // Recurse to parent @@ -429,7 +441,8 @@ procedure FillDirFiles(Engine: TPanelEngine; DestList: TList; InputFiles: TStrin // Add end stage ItemSL := DuplicateDataItem(ItemSL); ItemSL^.Stage1 := False; - DestList.Add(ItemSL); + if SortForStream then DirStage2List.Add(ItemSL) + else DestList.Add(ItemSL); end; end; end else begin @@ -444,6 +457,11 @@ var root: PDataItemSL; i: integer; begin if InputFiles.Count = 0 then Exit; + if SortForStream then begin + DirStage1List := TList.Create; + FilesList := TList.Create; + DirStage2List := TList.Create; + end; for i := 0 to InputFiles.Count - 1 do begin root := GetFileInfoSL(Engine, InputFiles[i]); @@ -451,21 +469,41 @@ begin DebugMsg(['FillDirFiles: cannot stat ', InputFiles[i]]); Exit; end; + root^.Stage1 := True; root^.Level := 1; - DestList.Add(root); + if not SortForStream then DestList.Add(root) else + if not root^.DataItem^.IsDir then FilesList.Add(root); if root^.DataItem^.IsDir then begin // It's a directory, mark as starting item - root^.Stage1 := True; + if SortForStream then DirStage1List.Add(root); // Recurse to child FillDirFiles_Recurse(InputFiles[i], 2); // Add ending item root := GetFileInfoSL(Engine, InputFiles[i]); root^.Stage1 := False; root^.Level := 1; - DestList.Add(root); + if SortForStream then DirStage2List.Add(root) + else DestList.Add(root); end; end; + + // Merge lists + if SortForStream then begin + FillDirFiles_sort(FilesList); + if DirStage1List.Count > 0 then + for i := 0 to DirStage1List.Count - 1 do + DestList.Add(DirStage1List[i]); + if FilesList.Count > 0 then + for i := 0 to FilesList.Count - 1 do + DestList.Add(FilesList[i]); + if DirStage2List.Count > 0 then + for i := 0 to DirStage2List.Count - 1 do + DestList.Add(DirStage2List[i]); + DirStage1List.Free; + FilesList.Free; + DirStage2List.Free; + end; end; function GetFileInfoSL(Engine: TPanelEngine; const APath: string): PDataItemSL; |
