ADD: CopyOut operation for WfxFileSource

This commit is contained in:
Alexander Koblov 2009-10-10 16:22:04 +00:00
commit b9d1a56eb9
3 changed files with 142 additions and 214 deletions

View file

@ -0,0 +1,124 @@
unit uWfxPluginCopyOutOperation;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
uFileSourceCopyOperation,
uFileSource,
uFileSourceOperation,
uFileSourceOperationOptions,
uFile,
uFileSystemFile,
uWfxPluginFile,
uWfxPluginFileSource,
uWfxPluginUtil;
type
TWfxPluginCopyOutOperation = class(TFileSourceCopyOutOperation)
private
FWfxPluginFileSource: TWfxPluginFileSource;
FOperationHelper: TWfxPluginOperationHelper;
FFullFilesTreeToCopy: TFileSystemFiles; // source files including all files/dirs in subdirectories
FStatistics: TFileSourceCopyOperationStatistics; // local copy of statistics
FCurrentFileSize: Int64;
// Options
FInternal: Boolean;
FFileExistsOption: TFileSourceOperationOptionFileExists;
protected
// ProcessFileNoQuestions (when we're sure the targets don't exist)
public
constructor Create(var aSourceFileSource: TFileSource;
var aTargetFileSource: TFileSource;
var theSourceFiles: TFiles;
aTargetPath: String); override;
destructor Destroy; override;
procedure Initialize; override;
procedure MainExecute; override;
procedure Finalize; override;
property FileExistsOption: TFileSourceOperationOptionFileExists read FFileExistsOption write FFileExistsOption;
end;
implementation
uses
uOSUtils, FileUtil, LCLProc, uGlobs, ufsplugin, uFileSystemUtil;
// -- TWfxPluginCopyOutOperation ---------------------------------------------
constructor TWfxPluginCopyOutOperation.Create(var aSourceFileSource: TFileSource;
var aTargetFileSource: TFileSource;
var theSourceFiles: TFiles;
aTargetPath: String);
begin
FWfxPluginFileSource:= aSourceFileSource as TWfxPluginFileSource;
FInternal:= aTargetFileSource is TWfxPluginFileSource;
inherited Create(aSourceFileSource, aTargetFileSource, theSourceFiles, aTargetPath);
end;
destructor TWfxPluginCopyOutOperation.Destroy;
begin
inherited Destroy;
end;
procedure TWfxPluginCopyOutOperation.Initialize;
begin
with FWfxPluginFileSource do
begin
WfxStatusInfo(CurrentPath, FS_STATUS_START, FS_STATUS_OP_PUT_MULTI);
WfxOperationList[PluginNumber]:= Self;
// Get initialized statistics; then we change only what is needed.
FStatistics := RetrieveStatistics;
FillAndCount(SourceFiles,
FFullFilesTreeToCopy,
FStatistics.TotalFiles,
FStatistics.TotalBytes); // gets full list of files (recursive)
end;
if Assigned(FOperationHelper) then
FreeAndNil(FOperationHelper);
FOperationHelper := TWfxPluginOperationHelper.Create(
FWfxPluginFileSource,
@AskQuestion,
@RaiseAbortOperation,
@CheckOperationState,
@UpdateStatistics,
Thread,
wpohmCopyMoveOut,
TargetPath,
FStatistics);
FOperationHelper.RenameMask := RenameMask;
FOperationHelper.FileExistsOption := FileExistsOption;
FOperationHelper.Initialize(FInternal);
end;
procedure TWfxPluginCopyOutOperation.MainExecute;
begin
FOperationHelper.ProcessFiles(FFullFilesTreeToCopy);
end;
procedure TWfxPluginCopyOutOperation.Finalize;
begin
with FWfxPluginFileSource do
begin
WfxStatusInfo(CurrentPath, FS_STATUS_END, FS_STATUS_OP_PUT_MULTI);
WfxOperationList[PluginNumber]:= nil;
end;
end;
end.

View file

@ -52,6 +52,9 @@ type
function CreateCopyInOperation(var SourceFileSource: TFileSource;
var SourceFiles: TFiles;
TargetPath: String): TFileSourceOperation; override;
function CreateCopyOutOperation(var TargetFileSource: TFileSource;
var SourceFiles: TFiles;
TargetPath: String): TFileSourceOperation; override;
function CreateDeleteOperation(var FilesToDelete: TFiles): TFileSourceOperation; override;
function CreateCreateDirectoryOperation(DirectoryPath: String): TFileSourceOperation; override;
@ -70,7 +73,7 @@ implementation
uses
LCLProc, FileUtil, uGlobs, uDCUtils, uLog, uLng,
uWfxPluginCopyInOperation,
uWfxPluginCopyInOperation, uWfxPluginCopyOutOperation,
uWfxPluginListOperation, uWfxPluginCreateDirectoryOperation, uWfxPluginDeleteOperation,
uWfxPluginFile;
@ -265,7 +268,7 @@ end;
class function TWfxPluginFileSource.GetOperationsTypes: TFileSourceOperationTypes;
begin
Result := [fsoList, fsoCopyIn, fsoDelete, fsoCreateDirectory];
Result := [fsoList, fsoCopyIn, fsoCopyOut, fsoDelete, fsoCreateDirectory];
end;
class function TWfxPluginFileSource.GetFilePropertiesDescriptions: TFilePropertiesDescriptions;
@ -447,6 +450,19 @@ begin
SourceFiles, TargetPath);
end;
function TWfxPluginFileSource.CreateCopyOutOperation(
var TargetFileSource: TFileSource;
var SourceFiles: TFiles;
TargetPath: String): TFileSourceOperation;
var
SourceFileSource: TFileSource;
begin
SourceFileSource := Self.Clone;
Result := TWfxPluginCopyOutOperation.Create(SourceFileSource,
TargetFileSource,
SourceFiles, TargetPath);
end;
function TWfxPluginFileSource.CreateDeleteOperation(var FilesToDelete: TFiles): TFileSourceOperation;
var
TargetFileSource: TFileSource;

View file

@ -40,19 +40,6 @@ const
WFX_ERROR = -2;
type
TWFXModule = class;
{ CopyIn/CopyOut thread }
{ TWFXCopyThread }
TWFXCopyThread = class(TThread)
protected
procedure Execute; override;
public
Operation : Integer;
WFXModule : TWFXModule;
end;
{ TWFXModule }
@ -66,10 +53,7 @@ type
FLastFileSize,
FFilesSize: Int64;
FPercent : Double;
CT : TWFXCopyThread; // CopyIn/CopyOut thread
FFileOpDlg: TfrmFileOp; // progress window
function WFXCopyOut : Boolean; {Copy files from VFS}
function WFXCopyIn : Boolean; {Copy files in VFS}
public
{Mandatory}
FsInit : TFsInit;
@ -121,8 +105,6 @@ type
function VFSConfigure(Parent: THandle):Boolean;override;
function VFSCopyOut(var flSrcList : TFileList; sDstPath:String; Flags: Integer):Boolean;override;
function VFSCopyOutEx(var flSrcList : TFileList; sDstPath:String; Flags: Integer):Boolean;override;
function VFSRun(const sName:String):Boolean;override;
function VFSMisc: PtrUInt; override;
@ -403,173 +385,6 @@ begin
end;
end;
function TWFXModule.WFXCopyOut: Boolean;
var
Count, I : Integer;
ri : TRemoteInfo;
iInt64Rec : TInt64Rec;
RemoteName,
LocalName : String;
iResult : Integer;
begin
FsFillAndCount(FFileList, FFilesSize);
Count := FFileList.Count - 1;
for I := 0 to Count do
begin
RemoteName := FFileList.CurrentDirectory + FFileList.GetFileName(I);
LocalName := ExtractFilePath(FDstPath) + FFileList.GetFileName(I);
DebugLN('Remote name == ' + RemoteName);
DebugLN('Local name == ' + LocalName);
if FPS_ISDIR(FFileList.GetItem(I)^.iMode) then
begin
mbForceDirectory(LocalName);
Continue;
end;
with ri, FFileList.GetItem(I)^ do
begin
iInt64Rec.Value := iSize;
SizeLow := iInt64Rec.Low;
SizeHigh := iInt64Rec.High;
LastWriteTime := DateTimeToFileTime(fTimeI);
Attr := iMode;
end;
FLastFileSize := FFileList.GetItem(I)^.iSize;
iResult := FsGetFile(PChar(UTF8ToSys(RemoteName)), PChar(UTF8ToSys(LocalName)), FFlags, @ri);
if iResult = FS_FILE_USERABORT then
begin
FreeAndNil(FFileList);
Exit; //Copying was aborted by the user (through ProgressProc)
end;
Result := (iResult = FS_FILE_OK);
{ Log messages }
if Result then
// write log success
if (log_vfs_op in gLogOptions) and (log_success in gLogOptions) then
logWrite(CT, Format(rsMsgLogSuccess+rsMsgLogCopy, [RemoteName+' -> '+LocalName]), lmtSuccess)
else
// write log error
if (log_vfs_op in gLogOptions) and (log_errors in gLogOptions) then
logWrite(CT, Format(rsMsgLogError+rsMsgLogCopy, [RemoteName+' -> '+LocalName]), lmtError);
{/ Log messages }
end;
FreeAndNil(FFileList);
end;
function TWFXModule.WFXCopyIn: Boolean;
var
Count, I : Integer;
LocalName,
RemoteName : String;
iResult : Integer;
begin
FillAndCount(FFileList, FFilesSize);
Count := FFileList.Count - 1;
for I := 0 to Count do
begin
LocalName := FFileList.CurrentDirectory + FFileList.GetFileName(I);
RemoteName := ExtractFilePath(FDstPath) + FFileList.GetFileName(I);
DebugLN('Local name == ' + LocalName);
DebugLN('Remote name == ' + RemoteName);
if FPS_ISDIR(FFileList.GetItem(I)^.iMode) then
begin
FsMkDir(PChar(UTF8ToSys(RemoteName)));
Continue;
end;
FLastFileSize := FFileList.GetItem(I)^.iSize;
iResult := FsPutFile(PChar(UTF8ToSys(LocalName)), PChar(UTF8ToSys(RemoteName)), FFlags);
if iResult = FS_FILE_USERABORT then
begin
FreeAndNil(FFileList);
Exit; //Copying was aborted by the user (through ProgressProc)
end;
Result := (iResult = FS_FILE_OK);
{ Log messages }
if Result then
// write log success
if (log_vfs_op in gLogOptions) and (log_success in gLogOptions) then
logWrite(CT, Format(rsMsgLogSuccess+rsMsgLogCopy, [LocalName+' -> '+RemoteName]), lmtSuccess)
else
// write log error
if (log_vfs_op in gLogOptions) and (log_errors in gLogOptions) then
logWrite(CT, Format(rsMsgLogError+rsMsgLogCopy, [LocalName+' -> '+RemoteName]), lmtError);
{/ Log messages }
end;
FreeAndNil(FFileList);
end;
function TWFXModule.VFSCopyOut(var flSrcList: TFileList; sDstPath: String;
Flags: Integer): Boolean;
begin
Result := True;
try
FFileOpDlg:= TfrmFileOp.Create(nil);
FFileOpDlg.Show;
{
FFileOpDlg.iProgress1Max:=100;
FFileOpDlg.iProgress2Max:=100;
}
FFileOpDlg.Caption := rsDlgCp;
FFileList := flSrcList;
FDstPath := sDstPath;
FFlags := Flags;
CT := nil;
WFXCopyOut;
FFileOpDlg.Close;
except
Result := False;
end;
FFileOpDlg := nil;
end;
function TWFXModule.VFSCopyOutEx(var flSrcList: TFileList; sDstPath: String;
Flags: Integer): Boolean;
begin
{
//VFSCopyOut(flSrcList, sDstPath, Flags);
Result := True;
try
FFileOpDlg:= TfrmFileOp.Create(nil);
FFileOpDlg.Show;
FFileOpDlg.iProgress1Max:=100;
FFileOpDlg.iProgress2Max:=100;
FFileOpDlg.Caption := rsDlgCp;
FFileList := flSrcList;
FDstPath := sDstPath;
FFlags := Flags;
CT := TWFXCopyThread.Create(True);
CT.FreeOnTerminate := True;
CT.Operation := OP_COPYOUT;
CT.WFXModule := Self;
FFileOpDlg.Thread := TThread(CT);
CT.Resume;
except
Result := False;
end;
}
end;
function TWFXModule.VFSRun(const sName: String): Boolean;
var
pcRemoteName: PChar;
@ -597,33 +412,6 @@ begin
Result:=0;
end;
{ TWFXCopyThread }
procedure TWFXCopyThread.Execute;
begin
// main archive thread code started here
{ try
with WFXModule do
begin
case Operation of
OP_COPYOUT:
begin
WFXCopyOut;
end;
OP_COPYIN:
begin
WFXCopyIn;
end;
end; //case
end; //with
except
DebugLN('Error in "WFXCopyThread.Execute"');
end;
}
Synchronize(WFXModule.FFileOpDlg.Close);
WFXModule.FFileOpDlg := nil;
end;
{ TWFXModuleList }
function TWFXModuleList.GetAEnabled(Index: Integer): Boolean;