ADD/StashFS: step-7: support reload when files changed

This commit is contained in:
rich2014 2026-06-04 22:51:43 +08:00
commit 3764ee267c
3 changed files with 44 additions and 3 deletions

View file

@ -28,9 +28,13 @@ type
TStashFileSource = class(TVirtualFileSource)
private
_fileSystemFS: IFileSystemFileSource;
protected
procedure onFileSystemEvent(var params: TFileSourceEventParams);
public
constructor Create; override; overload;
destructor Destroy; override;
function GetLocalName(var aFile: TFile): Boolean; override;
function needReload(const PathToReload: String; const PathToCheck: String): Boolean; override;
function GetProcessor: TFileSourceProcessor; override;
function GetRootDir(sPath : String): String; override;
@ -39,6 +43,7 @@ type
function GetRetrievableFileProperties: TFilePropertiesTypes; override;
function GetOperationsTypes: TFileSourceOperationTypes; override;
class function CreateFile(const APath: String): TFile; override;
procedure RetrieveProperties(AFile: TFile; PropertiesToSet: TFilePropertiesTypes; const AVariantProperties: array of String); override;
function CreateListOperation(TargetPath: String): TFileSourceOperation; override;
function CreateCopyInOperation(SourceFileSource: IFileSource; var SourceFiles: TFiles; TargetPath: String): TFileSourceOperation; override;
function CreateCopyOutOperation(TargetFileSource: IFileSource; var SourceFiles: TFiles; TargetPath: String): TFileSourceOperation; override;
@ -137,10 +142,22 @@ end;
{ TStashFileSource }
procedure TStashFileSource.onFileSystemEvent(var params: TFileSourceEventParams);
begin
self.Reload( params.paths );
end;
constructor TStashFileSource.Create;
begin
Inherited Create;
_fileSystemFS:= TFileSystemFileSource.Create;
_fileSystemFS:= IFileSystemFileSource(FileSourceManager.Find(TFileSystemFileSource,EmptyStr));
_fileSystemFS.AddEventListener( @self.onFileSystemEvent );
end;
destructor TStashFileSource.Destroy;
begin
_fileSystemFS.RemoveEventListener( @self.onFileSystemEvent );
inherited Destroy;
end;
function TStashFileSource.GetLocalName(var aFile: TFile): Boolean;
@ -148,6 +165,14 @@ begin
Result:= True;
end;
function TStashFileSource.needReload(
const PathToReload: String;
const PathToCheck: String): Boolean;
begin
// todo: it should check the path in StashFilesBackend
Result:= True;
end;
function TStashFileSource.GetProcessor: TFileSourceProcessor;
begin
Result:= stashFileSourceProcessor;
@ -181,7 +206,14 @@ end;
class function TStashFileSource.CreateFile(const APath: String): TFile;
begin
Result:= TFileSystemFileSource.CreateFileFromFile(APath);
Result:= TFileSystemFileSource.CreateFile(APath);
end;
procedure TStashFileSource.RetrieveProperties(AFile: TFile;
PropertiesToSet: TFilePropertiesTypes;
const AVariantProperties: array of String);
begin
_fileSystemFS.RetrieveProperties(AFile, PropertiesToSet, AVariantProperties);
end;
function TStashFileSource.CreateListOperation(TargetPath: String): TFileSourceOperation;

View file

@ -210,6 +210,7 @@ type
procedure eventNotify( var params: TFileSourceEventParams );
procedure Reload(const PathsToReload: TPathsArray);
procedure Reload(const PathToReload: String);
function needReload(const PathToReload: String; const PathToCheck: String): Boolean;
procedure AddEventListener(FunctionToCall: TFileSourceEventListener);
procedure RemoveEventListener(FunctionToCall: TFileSourceEventListener);
@ -432,6 +433,7 @@ type
procedure eventNotify( var params: TFileSourceEventParams );
procedure Reload(const PathsToReload: TPathsArray); virtual; overload;
procedure Reload(const PathToReload: String); overload;
function needReload(const PathToReload: String; const PathToCheck: String): Boolean; virtual;
procedure AddEventListener(FunctionToCall: TFileSourceEventListener);
procedure RemoveEventListener(FunctionToCall: TFileSourceEventListener);
@ -1123,6 +1125,13 @@ begin
Reload(PathsToReload);
end;
function TFileSource.needReload(
const PathToReload: String;
const PathToCheck: String): Boolean;
begin
Result := IsInPath(PathToReload, PathToCheck, True, True);
end;
procedure TFileSource.AddEventListener(FunctionToCall: TFileSourceEventListener);
begin
FEventListeners.Add(TMethod(FunctionToCall));

View file

@ -2463,7 +2463,7 @@ begin
begin
Result := False;
for i := Low(PathsToReload) to High(PathsToReload) do
if IsInPath(PathsToReload[i], CurrentPath, True, True) then
if FileSource.needReload(PathsToReload[i], CurrentPath) then
begin
Result := True;
Break;