|
@@ -30,141 +30,179 @@ library DSXLocate;
|
|
uses
|
|
uses
|
|
Classes, SysUtils, DsxPlugin, un_process;
|
|
Classes, SysUtils, DsxPlugin, un_process;
|
|
|
|
|
|
-var List:TStringList;
|
|
|
|
- LocatePath:String;
|
|
|
|
|
|
+var
|
|
|
|
+ List: TStringList;
|
|
|
|
+ LocatePath: String;
|
|
|
|
|
|
type
|
|
type
|
|
|
|
|
|
- { TPlugInfo }
|
|
|
|
-
|
|
|
|
- TPlugInfo = class
|
|
|
|
- private
|
|
|
|
- FProcess:TExProcess;
|
|
|
|
- FAddProc:TSAddFileProc;
|
|
|
|
- FUpdateProc:TSUpdateStatusProc;
|
|
|
|
- FSearchAttr:TSearchAttrRecord;
|
|
|
|
- FStartPath:String;
|
|
|
|
- FilesScaned:integer;
|
|
|
|
- public
|
|
|
|
- PluginNr:integer;
|
|
|
|
- //---------------------
|
|
|
|
- constructor Create(Nr:integer);
|
|
|
|
- procedure SetProcs(AddProc:TSAddFileProc; UpdateProc:TSUpdateStatusProc);
|
|
|
|
- procedure SetDefs(SearchAttr:TSearchAttrRecord; StartPath:String);
|
|
|
|
- destructor Destroy; override;
|
|
|
|
- //---------------------
|
|
|
|
- procedure Start;
|
|
|
|
- procedure Stop;
|
|
|
|
- procedure OnReadLn(str: string);
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-constructor TPlugInfo.Create(Nr:integer);
|
|
|
|
|
|
+ { TPlugInfo }
|
|
|
|
+
|
|
|
|
+ TPlugInfo = class
|
|
|
|
+ private
|
|
|
|
+ FProcess: TExProcess;
|
|
|
|
+ FAddProc: TSAddFileProc;
|
|
|
|
+ FUpdateProc: TSUpdateStatusProc;
|
|
|
|
+ FSearchRec: TDsxSearchRecord;
|
|
|
|
+ FilesScanned: Integer;
|
|
|
|
+ public
|
|
|
|
+ PluginNr: Integer;
|
|
|
|
+ //---------------------
|
|
|
|
+ constructor Create(Nr: Integer);
|
|
|
|
+ procedure SetProcs(AddProc: TSAddFileProc; UpdateProc: TSUpdateStatusProc);
|
|
|
|
+ procedure SetDefs(pSearchRec: PDsxSearchRecord);
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
+ //---------------------
|
|
|
|
+ procedure Start;
|
|
|
|
+ procedure Stop;
|
|
|
|
+ procedure OnReadLn(str: String);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+constructor TPlugInfo.Create(Nr: Integer);
|
|
begin
|
|
begin
|
|
- PluginNr:=Nr;
|
|
|
|
|
|
+ PluginNr := Nr;
|
|
|
|
+ FProcess := nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TPlugInfo.SetProcs(AddProc: TSAddFileProc; UpdateProc: TSUpdateStatusProc);
|
|
procedure TPlugInfo.SetProcs(AddProc: TSAddFileProc; UpdateProc: TSUpdateStatusProc);
|
|
begin
|
|
begin
|
|
-FAddProc:=AddProc;
|
|
|
|
-FUpdateProc:=UpdateProc;
|
|
|
|
|
|
+ FAddProc := AddProc;
|
|
|
|
+ FUpdateProc := UpdateProc;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TPlugInfo.SetDefs(SearchAttr: TSearchAttrRecord; StartPath: String);
|
|
|
|
|
|
+procedure TPlugInfo.SetDefs(pSearchRec: PDsxSearchRecord);
|
|
begin
|
|
begin
|
|
-FSearchAttr:=SearchAttr;
|
|
|
|
-FStartPath:=StartPath;
|
|
|
|
|
|
+ FSearchRec := pSearchRec^;
|
|
end;
|
|
end;
|
|
|
|
|
|
-
|
|
|
|
destructor TPlugInfo.Destroy;
|
|
destructor TPlugInfo.Destroy;
|
|
begin
|
|
begin
|
|
-if Assigned(FProcess) then FreeAndNil(FProcess);
|
|
|
|
|
|
+ if Assigned(FProcess) then
|
|
|
|
+ FreeAndNil(FProcess);
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TPlugInfo.Start;
|
|
procedure TPlugInfo.Start;
|
|
|
|
+var
|
|
|
|
+ sSearch: String;
|
|
begin
|
|
begin
|
|
- FilesScaned:=0;
|
|
|
|
- FProcess:=TExProcess.Create();
|
|
|
|
- FProcess.OnReadLn:=@OnReadLn;
|
|
|
|
- FProcess.SetCmdLine(LocatePath+' '+string(FSearchAttr.rFileMask));
|
|
|
|
|
|
+ FilesScanned := 0;
|
|
|
|
+ if Assigned(FProcess) then
|
|
|
|
+ FreeAndNil(FProcess);
|
|
|
|
+ FProcess := TExProcess.Create;
|
|
|
|
+ FProcess.OnReadLn := @OnReadLn;
|
|
|
|
+
|
|
|
|
+ with FSearchRec do
|
|
|
|
+ begin
|
|
|
|
+ // TProcess doesn't support passing parameters other than quoted in "".
|
|
|
|
+ // Adapt this code when this changes.
|
|
|
|
+ sSearch := String(StartPath);
|
|
|
|
+ if sSearch <> '' then
|
|
|
|
+ begin
|
|
|
|
+ // Search in given start path and in subdirectories.
|
|
|
|
+ sSearch := '"' + IncludeTrailingPathDelimiter(sSearch) + String(FileMask) + '" ' +
|
|
|
|
+ '"' + IncludeTrailingPathDelimiter(sSearch) + '*' + PathDelim + String(FileMask) + '"';
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ sSearch := '"' + String(FileMask) + '"';
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ if LocatePath <> '' then
|
|
|
|
+ FProcess.SetCmdLine(LocatePath + ' ' + sSearch);
|
|
FProcess.Execute;
|
|
FProcess.Execute;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TPlugInfo.Stop;
|
|
procedure TPlugInfo.Stop;
|
|
begin
|
|
begin
|
|
- FProcess.Stop;
|
|
|
|
- FreeAndNil(FProcess);
|
|
|
|
|
|
+ if Assigned(FProcess) then
|
|
|
|
+ begin
|
|
|
|
+ FProcess.Stop;
|
|
|
|
+ FreeAndNil(FProcess);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TPlugInfo.OnReadLn(str: string);
|
|
|
|
|
|
+procedure TPlugInfo.OnReadLn(str: String);
|
|
begin
|
|
begin
|
|
- FilesScaned:=FilesScaned+1;
|
|
|
|
- FAddProc(PluginNr,PChar(str));
|
|
|
|
- FUpdateProc(PluginNr,PChar(str),FilesScaned);
|
|
|
|
|
|
+ if str <> '' then
|
|
|
|
+ Inc(FilesScanned);
|
|
|
|
+ FAddProc(PluginNr, PChar(str));
|
|
|
|
+ FUpdateProc(PluginNr, PChar(str), FilesScanned);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
{Main --------------------------------------------------------------------------------}
|
|
{Main --------------------------------------------------------------------------------}
|
|
|
|
|
|
-function Init(dps:pDSXDefaultParamStruct; pAddFileProc:TSAddFileProc; pUpdateStatus:TSUpdateStatusProc):integer; stdcall;
|
|
|
|
-var i:integer;
|
|
|
|
|
|
+function Init(dps: PDsxDefaultParamStruct; pAddFileProc: TSAddFileProc;
|
|
|
|
+ pUpdateStatus: TSUpdateStatusProc): Integer; stdcall;
|
|
|
|
+var
|
|
|
|
+ i: Integer;
|
|
begin
|
|
begin
|
|
- if not assigned(List) then List:=TStringList.Create;
|
|
|
|
- I:=List.Count;
|
|
|
|
- List.AddObject(IntToStr(I),TPlugInfo.Create(I));
|
|
|
|
- TPlugInfo(List.Objects[I]).SetProcs(pAddFileProc,pUpdateStatus);
|
|
|
|
|
|
+ if not assigned(List) then
|
|
|
|
+ List := TStringList.Create;
|
|
|
|
+ I := List.Count;
|
|
|
|
+ List.AddObject(IntToStr(I), TPlugInfo.Create(I));
|
|
|
|
+ TPlugInfo(List.Objects[I]).SetProcs(pAddFileProc, pUpdateStatus);
|
|
|
|
+ Result := I;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure StartSearch(FPluginNr:integer; StartPath:pchar; SearchAttrRec:TSearchAttrRecord); stdcall;
|
|
|
|
|
|
+procedure StartSearch(FPluginNr: Integer; pSearchRecRec: PDsxSearchRecord); stdcall;
|
|
begin
|
|
begin
|
|
- TPlugInfo(List.Objects[FPluginNr]).SetDefs(SearchAttrRec,string(StartPath));
|
|
|
|
|
|
+ TPlugInfo(List.Objects[FPluginNr]).SetDefs(pSearchRecRec);
|
|
TPlugInfo(List.Objects[FPluginNr]).Start;
|
|
TPlugInfo(List.Objects[FPluginNr]).Start;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure StopSearch(FPluginNr:integer); stdcall;
|
|
|
|
|
|
+procedure StopSearch(FPluginNr: Integer); stdcall;
|
|
begin
|
|
begin
|
|
-TPlugInfo(List.Objects[FPluginNr]).Stop;
|
|
|
|
|
|
+ TPlugInfo(List.Objects[FPluginNr]).Stop;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure Finalize(FPluginNr:integer); stdcall;
|
|
|
|
|
|
+procedure Finalize(FPluginNr: Integer); stdcall;
|
|
begin
|
|
begin
|
|
-if not Assigned(List) then exit;
|
|
|
|
-if (FPluginNr>List.Count) or (FPluginNr<0) or (List.Count=0) then exit;
|
|
|
|
|
|
+ if not Assigned(List) then
|
|
|
|
+ exit;
|
|
|
|
+ if (FPluginNr > List.Count) or (FPluginNr < 0) or (List.Count = 0) then
|
|
|
|
+ exit;
|
|
|
|
|
|
-//Destroy PlugInfo Item №
|
|
|
|
|
|
+ //Destroy PlugInfo Item №
|
|
TPlugInfo(List.Objects[FPluginNr]).Free;
|
|
TPlugInfo(List.Objects[FPluginNr]).Free;
|
|
List.Delete(FPluginNr);
|
|
List.Delete(FPluginNr);
|
|
- if List.Count=0 then
|
|
|
|
|
|
+ if List.Count = 0 then
|
|
FreeAndNil(List);
|
|
FreeAndNil(List);
|
|
end;
|
|
end;
|
|
|
|
|
|
-
|
|
|
|
exports
|
|
exports
|
|
- Init,
|
|
|
|
- StartSearch,
|
|
|
|
- StopSearch,
|
|
|
|
- Finalize;
|
|
|
|
-
|
|
|
|
-type Tx=class
|
|
|
|
- procedure OnReadLnWhich(str: string);
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-procedure Tx.OnReadLnWhich(str: string);
|
|
|
|
|
|
+ Init,
|
|
|
|
+ StartSearch,
|
|
|
|
+ StopSearch,
|
|
|
|
+ Finalize;
|
|
|
|
+
|
|
|
|
+type
|
|
|
|
+ Tx = class
|
|
|
|
+ procedure OnReadLnWhich(str: String);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+procedure Tx.OnReadLnWhich(str: String);
|
|
begin
|
|
begin
|
|
- if str<>'' then
|
|
|
|
- begin
|
|
|
|
- LocatePath:=str;
|
|
|
|
- //WriteLn('PLUGIN: locate found in '+str);
|
|
|
|
- end;
|
|
|
|
|
|
+ if str <> '' then
|
|
|
|
+ begin
|
|
|
|
+ LocatePath := str;
|
|
|
|
+ //WriteLn('PLUGIN: locate found in '+str);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-var Pr:TExProcess; x:TX;
|
|
|
|
|
|
+var
|
|
|
|
+ Pr: TExProcess;
|
|
|
|
+ x: TX;
|
|
begin
|
|
begin
|
|
-pr:=TExProcess.Create('which locate');
|
|
|
|
-x:=Tx.Create;
|
|
|
|
-pr.OnReadLn:=@(x.OnReadLnWhich);
|
|
|
|
-pr.Execute;
|
|
|
|
-x.free;
|
|
|
|
|
|
+ pr := TExProcess.Create('which locate');
|
|
|
|
+ x := Tx.Create;
|
|
|
|
+ pr.OnReadLn := @x.OnReadLnWhich;
|
|
|
|
+ pr.Execute;
|
|
|
|
+ pr.Free;
|
|
|
|
+ x.Free;
|
|
|
|
+ {$IFDEF UNIX}
|
|
|
|
+ if LocatePath = '' then
|
|
|
|
+ Writeln('DSXLocate: Locate utility not found.');
|
|
|
|
+ {$ENDIF}
|
|
end.
|
|
end.
|
|
|
|
|