mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Set date/time operation for WfxPluginFileSource
This commit is contained in:
parent
abdaa8284b
commit
037dddcdee
4 changed files with 186 additions and 1 deletions
|
|
@ -134,6 +134,7 @@ begin
|
|||
|
||||
repeat
|
||||
bRetry := False;
|
||||
|
||||
Result:= mbFileSetTime(FileName, fdLastWriteTime, fdCreationTime, fdLastAccessTime) <> 0;
|
||||
|
||||
if not Result then
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ uses
|
|||
LCLProc, FileUtil,{} Forms, Dialogs, LCLType,{} uGlobs, uDCUtils, uLog, uLng, uCryptProc,
|
||||
uWfxPluginCopyInOperation, uWfxPluginCopyOutOperation, uWfxPluginExecuteOperation,
|
||||
uWfxPluginListOperation, uWfxPluginCreateDirectoryOperation, uWfxPluginDeleteOperation,
|
||||
uWfxPluginSetAttributeOperation, uWfxPluginFile, uWfxPluginUtil;
|
||||
uWfxPluginSetAttributeOperation, uWfxPluginSetDateTimeOperation, uWfxPluginFile, uWfxPluginUtil;
|
||||
|
||||
{ CallBack functions }
|
||||
|
||||
|
|
|
|||
173
src/newdesign/uwfxpluginsetdatetimeoperation.pas
Normal file
173
src/newdesign/uwfxpluginsetdatetimeoperation.pas
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
unit uWfxPluginSetDateTimeOperation;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
uFileSourceSetDateTimeOperation,
|
||||
uFileSource,
|
||||
uFileSourceOperationOptions,
|
||||
uFileSourceOperationUI,
|
||||
uFile,
|
||||
uWfxPluginFileSource,
|
||||
uWfxPluginFile,
|
||||
uGlobs, uLog;
|
||||
|
||||
type
|
||||
|
||||
TWfxPluginSetDateTimeOperation = class(TFileSourceSetDateTimeOperation)
|
||||
|
||||
private
|
||||
FWfxPluginFileSource: IWfxPluginFileSource;
|
||||
FFullFilesTreeToSetDateTime: TFiles; // source files including all files/dirs in subdirectories
|
||||
FStatistics: TFileSourceSetDateTimeOperationStatistics; // local copy of statistics
|
||||
|
||||
// Options.
|
||||
FSymLinkOption: TFileSourceOperationOptionSymLink;
|
||||
FSkipErrors: Boolean;
|
||||
|
||||
protected
|
||||
function ProcessFile(aFile: TWfxPluginFile): Boolean;
|
||||
|
||||
public
|
||||
constructor Create(aTargetFileSource: IFileSource;
|
||||
var theFilesToSetDateTime: TFiles; aLastWriteTime: TDateTime); override;
|
||||
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure Initialize; override;
|
||||
procedure MainExecute; override;
|
||||
procedure Finalize; override;
|
||||
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
uFileProperty, uLng, uDCUtils, WfxPlugin, uOSUtils;
|
||||
|
||||
constructor TWfxPluginSetDateTimeOperation.Create(aTargetFileSource: IFileSource;
|
||||
var theFilesToSetDateTime: TFiles; aLastWriteTime: TDateTime);
|
||||
begin
|
||||
FSymLinkOption := fsooslNone;
|
||||
FSkipErrors := False;
|
||||
FFullFilesTreeToSetDateTime := nil;
|
||||
FWfxPluginFileSource:= aTargetFileSource as IWfxPluginFileSource;
|
||||
|
||||
inherited Create(aTargetFileSource, theFilesToSetDateTime, aLastWriteTime);
|
||||
end;
|
||||
|
||||
destructor TWfxPluginSetDateTimeOperation.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
|
||||
if Recursive then
|
||||
begin
|
||||
if Assigned(FFullFilesTreeToSetDateTime) then
|
||||
FreeAndNil(FFullFilesTreeToSetDateTime);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWfxPluginSetDateTimeOperation.Initialize;
|
||||
begin
|
||||
with FWfxPluginFileSource do
|
||||
WfxModule.WfxStatusInfo(FilesToSetDateTime.Path, FS_STATUS_START, FS_STATUS_OP_ATTRIB);
|
||||
// Get initialized statistics; then we change only what is needed.
|
||||
FStatistics := RetrieveStatistics;
|
||||
|
||||
if not Recursive then
|
||||
begin
|
||||
FFullFilesTreeToSetDateTime:= FilesToSetDateTime;
|
||||
FStatistics.TotalFiles:= FFullFilesTreeToSetDateTime.Count;
|
||||
end
|
||||
else
|
||||
begin
|
||||
FWfxPluginFileSource.FillAndCount(FilesToSetDateTime,
|
||||
FFullFilesTreeToSetDateTime,
|
||||
FStatistics.TotalFiles,
|
||||
FStatistics.TotalBytes); // gets full list of files (recursive)
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWfxPluginSetDateTimeOperation.MainExecute;
|
||||
var
|
||||
aFile: TWfxPluginFile;
|
||||
CurrentFileIndex: Integer;
|
||||
begin
|
||||
for CurrentFileIndex := FFullFilesTreeToSetDateTime.Count - 1 downto 0 do
|
||||
begin
|
||||
aFile := FFullFilesTreeToSetDateTime[CurrentFileIndex] as TWfxPluginFile;
|
||||
|
||||
FStatistics.CurrentFile := aFile.Path + aFile.Name;
|
||||
UpdateStatistics(FStatistics);
|
||||
|
||||
ProcessFile(aFile);
|
||||
|
||||
with FStatistics do
|
||||
begin
|
||||
DoneFiles := DoneFiles + 1;
|
||||
DoneBytes := DoneBytes + aFile.Size;
|
||||
|
||||
UpdateStatistics(FStatistics);
|
||||
end;
|
||||
|
||||
CheckOperationState;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWfxPluginSetDateTimeOperation.Finalize;
|
||||
begin
|
||||
with FWfxPluginFileSource do
|
||||
WfxModule.WfxStatusInfo(FilesToSetDateTime.Path, FS_STATUS_END, FS_STATUS_OP_ATTRIB);
|
||||
end;
|
||||
|
||||
function TWfxPluginSetDateTimeOperation.ProcessFile(aFile: TWfxPluginFile): Boolean;
|
||||
var
|
||||
FileName: String;
|
||||
bRetry: Boolean;
|
||||
sMessage, sQuestion: String;
|
||||
ftLastWriteTime,
|
||||
ftCreationTime,
|
||||
ftLastAccessTime: TFileTime;
|
||||
begin
|
||||
Result := False;
|
||||
FileName := aFile.Path + aFile.Name;
|
||||
|
||||
ftLastWriteTime:= DateTimeToFileTime(LastWriteTime);
|
||||
ftCreationTime:= DateTimeToFileTime(CreationTime);
|
||||
ftLastAccessTime:= DateTimeToFileTime(LastAccessTime);
|
||||
|
||||
repeat
|
||||
bRetry := False;
|
||||
|
||||
with FWfxPluginFileSource.WfxModule do
|
||||
Result:= WfxSetTime(FileName, ftCreationTime, ftLastAccessTime, ftLastWriteTime);
|
||||
|
||||
if not Result then
|
||||
begin
|
||||
sMessage := Format(rsMsgLogError + rsMsgErrSetDateTime, [FileName]);
|
||||
sQuestion := Format(rsMsgErrSetDateTime, [FileName]);
|
||||
|
||||
if gSkipFileOpError or (FSkipErrors = True) then
|
||||
logWrite(Thread, sMessage, lmtError)
|
||||
else
|
||||
begin
|
||||
case AskQuestion(sQuestion, '',
|
||||
[fsourRetry, fsourSkip, fsourSkipAll, fsourAbort],
|
||||
fsourRetry, fsourSkip) of
|
||||
fsourRetry:
|
||||
bRetry := True;
|
||||
fsourSkipAll:
|
||||
FSkipErrors := True;
|
||||
fsourAbort:
|
||||
RaiseAbortOperation;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
until bRetry = False;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
@ -131,6 +131,7 @@ type
|
|||
procedure WfxStatusInfo(RemoteDir: UTF8String; InfoStartEnd, InfoOperation: Integer);
|
||||
function WfxExecuteFile(MainWin: HWND; var RemoteName: UTF8String; Verb: UTF8String): Integer;
|
||||
function WfxSetAttr(RemoteName: UTF8String; NewAttr: LongInt): Boolean;
|
||||
function WfxSetTime(RemoteName: UTF8String; CreationTime, LastAccessTime, LastWriteTime: TFileTime): Boolean;
|
||||
function WfxMkDir(const sBasePath, sDirName: UTF8String): LongInt;
|
||||
function WfxRemoveDir(const sDirName: UTF8String): Boolean;
|
||||
function WfxDeleteFile(const sFileName: UTF8String): Boolean;
|
||||
|
|
@ -318,6 +319,16 @@ begin
|
|||
Result:= FsSetAttr(PAnsiChar(UTF8ToSys(RemoteName)), NewAttr);
|
||||
end;
|
||||
|
||||
function TWFXModule.WfxSetTime(RemoteName: UTF8String; CreationTime,
|
||||
LastAccessTime, LastWriteTime: TFileTime): Boolean;
|
||||
begin
|
||||
Result:= False;
|
||||
if Assigned(FsSetTimeW) then
|
||||
Result:= FsSetTimeW(PWideChar(UTF8Decode(RemoteName)), @CreationTime, @LastAccessTime, @LastWriteTime)
|
||||
else if Assigned(FsSetTime) then
|
||||
Result:= FsSetTime(PAnsiChar(UTF8ToSys(RemoteName)), @CreationTime, @LastAccessTime, @LastWriteTime);
|
||||
end;
|
||||
|
||||
function TWFXModule.WfxMkDir(const sBasePath, sDirName: UTF8String): LongInt;
|
||||
begin
|
||||
Result:= WFX_NOTSUPPORTED;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue