mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
UPD: add fsoCopy logic to TDefaultFileSourceProcessor/TFileSystemFileSourceProcessor/TMountedFileSourceProcessor
This commit is contained in:
parent
d578945573
commit
b8a101a71c
5 changed files with 129 additions and 8 deletions
|
|
@ -11,6 +11,7 @@ uses
|
|||
uLocalFileSource,
|
||||
uFileSource, uFileSourceManager,
|
||||
uFileSourceProperty,
|
||||
uFileSourceUtil,
|
||||
uFileProperty,
|
||||
uFile,
|
||||
uDescr,
|
||||
|
|
@ -45,6 +46,8 @@ type
|
|||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
|
||||
function GetProcessor: TFileSourceProcessor; override;
|
||||
|
||||
class function CreateFile(const APath: String): TFile; override;
|
||||
class function CreateFile(const APath: String; pSearchRecord: PSearchRecEx): TFile; overload;
|
||||
{en
|
||||
|
|
@ -116,6 +119,15 @@ type
|
|||
property Description: TDescription read FDescr;
|
||||
end;
|
||||
|
||||
{ TFileSystemFileSourceProcessor }
|
||||
|
||||
TFileSystemFileSourceProcessor = class( TDefaultFileSourceProcessor )
|
||||
private
|
||||
procedure consultCopyOperation( var params: TFileSourceConsultParams );
|
||||
public
|
||||
procedure consultBeforeOperate( var params: TFileSourceConsultParams ); override;
|
||||
end;
|
||||
|
||||
{ TFileSystemFileSourceConnection }
|
||||
|
||||
TFileSystemFileSourceConnection = class(TFileSourceConnection)
|
||||
|
|
@ -153,6 +165,9 @@ uses
|
|||
uFileSystemCalcStatisticsOperation,
|
||||
uFileSystemSetFilePropertyOperation;
|
||||
|
||||
var
|
||||
fileSystemFileSourceProcessor: TFileSystemFileSourceProcessor;
|
||||
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
|
||||
procedure SetOwner(AFile: TFile);
|
||||
|
|
@ -317,6 +332,11 @@ begin
|
|||
FDescr.Free;
|
||||
end;
|
||||
|
||||
function TFileSystemFileSource.GetProcessor: TFileSourceProcessor;
|
||||
begin
|
||||
Result:= fileSystemFileSourceProcessor;
|
||||
end;
|
||||
|
||||
class function TFileSystemFileSource.CreateFile(const APath: String): TFile;
|
||||
begin
|
||||
Result := TFile.Create(APath);
|
||||
|
|
@ -1030,6 +1050,62 @@ begin
|
|||
theNewProperties);
|
||||
end;
|
||||
|
||||
{ TFileSystemFileSourceProcessor }
|
||||
|
||||
procedure TFileSystemFileSourceProcessor.consultCopyOperation( var params: TFileSourceConsultParams );
|
||||
var
|
||||
sourceFS: IFileSource;
|
||||
targetFS: IFileSource;
|
||||
|
||||
procedure doSource;
|
||||
begin
|
||||
// If same file source and address
|
||||
if isCompatibleFileSourceForCopyOperation( sourceFS, targetFS ) then begin
|
||||
params.resultFS:= sourceFS;
|
||||
end else if fsoCopyIn in targetFS.GetOperationsTypes then begin
|
||||
params.operationType := fsoCopyIn;
|
||||
params.resultFS:= targetFS;
|
||||
end else if (fsoCopyOut in sourceFS.GetOperationsTypes) and (fsoCopyIn in targetFS.GetOperationsTypes) then begin
|
||||
params.operationType:= fsoCopyOut;
|
||||
params.resultFS:= params.sourceFS;
|
||||
params.operationTemp:= True;
|
||||
end else begin
|
||||
params.consultResult:= fscrNotSupported;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure doTarget;
|
||||
begin
|
||||
if params.resultFS <> nil then
|
||||
Exit;
|
||||
|
||||
if fsoCopyOut in sourceFS.GetOperationsTypes then begin
|
||||
params.operationType:= fsoCopyOut;
|
||||
params.resultFS:= sourceFS;
|
||||
params.consultResult:= fscrSuccess;
|
||||
end
|
||||
end;
|
||||
|
||||
begin
|
||||
sourceFS:= params.sourceFS;
|
||||
targetFS:= params.targetFS;
|
||||
|
||||
if params.currentFS = params.sourceFS then
|
||||
doSource
|
||||
else
|
||||
doTarget;
|
||||
end;
|
||||
|
||||
procedure TFileSystemFileSourceProcessor.consultBeforeOperate( var params: TFileSourceConsultParams );
|
||||
begin
|
||||
case params.operationType of
|
||||
fsoCopy:
|
||||
self.consultCopyOperation( params );
|
||||
else
|
||||
Inherited;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TFileSystemFileSourceConnection }
|
||||
|
||||
procedure TFileSystemFileSourceConnection.SetCurrentPath(NewPath: String);
|
||||
|
|
@ -1042,5 +1118,11 @@ begin
|
|||
inherited SetCurrentPath(NewPath);
|
||||
end;
|
||||
|
||||
initialization
|
||||
fileSystemFileSourceProcessor:= TFileSystemFileSourceProcessor.Create;
|
||||
|
||||
finalization
|
||||
FreeAndNil( fileSystemFileSourceProcessor );
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ type
|
|||
|
||||
{ TMountedFileSourceProcessor }
|
||||
|
||||
TMountedFileSourceProcessor = class( TDefaultFileSourceProcessor )
|
||||
TMountedFileSourceProcessor = class( TFileSystemFileSourceProcessor )
|
||||
private
|
||||
procedure consultMoveOperation( var params: TFileSourceConsultParams );
|
||||
procedure resolveRealPath( var params: TFileSourceConsultParams );
|
||||
public
|
||||
procedure consultBeforeOperate( var params: TFileSourceConsultParams ); override;
|
||||
end;
|
||||
|
|
@ -264,7 +264,7 @@ end;
|
|||
|
||||
{ TMountedFileSourceProcessor }
|
||||
|
||||
procedure TMountedFileSourceProcessor.consultMoveOperation( var params: TFileSourceConsultParams);
|
||||
procedure TMountedFileSourceProcessor.resolveRealPath( var params: TFileSourceConsultParams);
|
||||
var
|
||||
mountedFS: TMountedFileSource;
|
||||
begin
|
||||
|
|
@ -278,8 +278,8 @@ end;
|
|||
procedure TMountedFileSourceProcessor.consultBeforeOperate( var params: TFileSourceConsultParams );
|
||||
begin
|
||||
case params.operationType of
|
||||
fsoMove:
|
||||
self.consultMoveOperation( params );
|
||||
fsoCopy, fsoMove:
|
||||
self.resolveRealPath( params );
|
||||
end;
|
||||
Inherited;
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ type
|
|||
handled: Boolean;
|
||||
|
||||
operationType: TFileSourceOperationType;
|
||||
operationTemp: Boolean;
|
||||
files: TFiles;
|
||||
targetPath: String;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ interface
|
|||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
uFileSource, uFileSourceOperationTypes,
|
||||
uFileSource, uFileSourceOperationTypes, uFileSourceUtil,
|
||||
uDebug;
|
||||
|
||||
type
|
||||
|
|
@ -31,6 +31,7 @@ type
|
|||
|
||||
TDefaultFileSourceProcessor = class( TFileSourceProcessor )
|
||||
private
|
||||
procedure consultCopyOperation( var params: TFileSourceConsultParams );
|
||||
procedure consultMoveOperation( var params: TFileSourceConsultParams );
|
||||
public
|
||||
procedure consultBeforeOperate( var params: TFileSourceConsultParams ); override;
|
||||
|
|
@ -124,7 +125,7 @@ begin
|
|||
if processor <> nil then
|
||||
processor.consultBeforeOperate( params );
|
||||
|
||||
if (params.consultResult<>fscrSuccess) or params.handled then
|
||||
if params.handled then
|
||||
Exit;
|
||||
|
||||
if params.targetFS = nil then
|
||||
|
|
@ -140,6 +141,29 @@ end;
|
|||
|
||||
{ TDefaultFileSourceProcessor }
|
||||
|
||||
procedure TDefaultFileSourceProcessor.consultCopyOperation( var params: TFileSourceConsultParams );
|
||||
var
|
||||
sourceFS: IFileSource;
|
||||
targetFS: IFileSource;
|
||||
begin
|
||||
if params.currentFS <> params.sourceFS then
|
||||
Exit;
|
||||
|
||||
sourceFS:= params.sourceFS;
|
||||
targetFS:= params.targetFS;
|
||||
|
||||
// If same file source and address
|
||||
if isCompatibleFileSourceForCopyOperation( sourceFS, targetFS ) then begin
|
||||
params.resultFS:= params.sourceFS;
|
||||
end else if (fsoCopyOut in sourceFS.GetOperationsTypes) and (fsoCopyIn in targetFS.GetOperationsTypes) then begin
|
||||
params.operationType:= fsoCopyOut;
|
||||
params.operationTemp:= True;
|
||||
params.resultFS:= params.sourceFS;
|
||||
end else begin
|
||||
params.consultResult:= fscrNotSupported;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDefaultFileSourceProcessor.consultMoveOperation( var params: TFileSourceConsultParams);
|
||||
var
|
||||
sourceFS: IFileSource;
|
||||
|
|
@ -173,6 +197,8 @@ end;
|
|||
procedure TDefaultFileSourceProcessor.consultBeforeOperate( var params: TFileSourceConsultParams );
|
||||
begin
|
||||
case params.operationType of
|
||||
fsoCopy:
|
||||
self.consultCopyOperation( params );
|
||||
fsoMove:
|
||||
self.consultMoveOperation( params );
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ interface
|
|||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
uFileSource, uFileSourceManager, uFileView, uFile, uFileSourceOperationTypes,
|
||||
uFileSource, uFileView, uFile, uFileSourceOperationTypes,
|
||||
uFileSourceSetFilePropertyOperation;
|
||||
|
||||
{en
|
||||
|
|
@ -37,6 +37,9 @@ procedure SetFileSystemPath(aFileView: TFileView; aPath: String);
|
|||
function RenameFile(aFileSource: IFileSource; const aFile: TFile;
|
||||
const NewFileName: String; Interactive: Boolean; Reload: Boolean): TSetFilePropertyResult;
|
||||
|
||||
|
||||
function isCompatibleFileSourceForCopyOperation( fs1: IFileSource; fs2: IFileSource ): Boolean;
|
||||
|
||||
function GetCopyOperationType(SourceFileSource, TargetFileSource: IFileSource;
|
||||
out OperationType: TFileSourceOperationType): Boolean;
|
||||
|
||||
|
|
@ -45,6 +48,7 @@ implementation
|
|||
uses
|
||||
LCLProc, fFileExecuteYourSelf, uGlobs, uShellExecute, uFindEx, uDebug,
|
||||
uOSUtils, uShowMsg, uLng, uVfsModule, DCOSUtils, DCStrUtils,
|
||||
uFileSourceManager,
|
||||
uFileSourceOperation,
|
||||
uFileSourceExecuteOperation,
|
||||
uVfsFileSource,
|
||||
|
|
@ -404,6 +408,14 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function isCompatibleFileSourceForCopyOperation(fs1: IFileSource; fs2: IFileSource): Boolean;
|
||||
begin
|
||||
Result:= (fsoCopy in fs1.GetOperationsTypes) and
|
||||
(fsoCopy in fs2.GetOperationsTypes) and
|
||||
fs1.Equals(fs1) and
|
||||
SameText(fs1.GetCurrentAddress, fs2.GetCurrentAddress);
|
||||
end;
|
||||
|
||||
function GetCopyOperationType(SourceFileSource, TargetFileSource: IFileSource;
|
||||
out OperationType: TFileSourceOperationType): Boolean;
|
||||
begin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue