forked from doublecmd/doublecmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuarchivefilesource.pas
106 lines (81 loc) · 2.65 KB
/
uarchivefilesource.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
unit uArchiveFileSource;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
DCOSUtils,
uLocalFileSource,
uFileSource,
uFile,
uFileProperty;
type
IArchiveFileSource = interface(ILocalFileSource)
['{13A8637C-FFDF-46B0-B5B4-E7C6851C157A}']
function Changed: Boolean;
function GetPacker: String;
property Packer: String read GetPacker;
{en
Full path to the archive on the ParentFileSource.
}
property ArchiveFileName: String read GetCurrentAddress;
end;
{ TArchiveFileSource }
TArchiveFileSource = class(TLocalFileSource, IArchiveFileSource)
private
FAttributeData: TFileAttributeData;
protected
function GetPacker: String; virtual; abstract;
function GetSupportedFileProperties: TFilePropertiesTypes; override;
public
{en
Creates an archive file source.
@param(anArchiveFileSource
File source that stores the archive.
Usually it will be direct-access file source, like filesystem.)
@param(anArchiveFileName
Full path to the archive on the ArchiveFileSource.)
}
constructor Create(anArchiveFileSource: IFileSource;
anArchiveFileName: String); virtual reintroduce overload;
class function CreateFile(const APath: String): TFile; override;
function Changed: Boolean;
property ArchiveFileName: String read GetCurrentAddress;
end;
implementation
constructor TArchiveFileSource.Create(anArchiveFileSource: IFileSource;
anArchiveFileName: String);
begin
FCurrentAddress := anArchiveFileName;
inherited Create;
ParentFileSource := anArchiveFileSource;
mbFileGetAttr(anArchiveFileName, FAttributeData);
end;
class function TArchiveFileSource.CreateFile(const APath: String): TFile;
begin
Result := TFile.Create(APath);
with Result do
begin
SizeProperty := TFileSizeProperty.Create;
CompressedSizeProperty := TFileCompressedSizeProperty.Create;
AttributesProperty := TFileAttributesProperty.CreateOSAttributes;
ModificationTimeProperty := TFileModificationDateTimeProperty.Create;
end;
end;
function TArchiveFileSource.Changed: Boolean;
var
Attr: TFileAttributeData;
begin
if not mbFileGetAttr(ArchiveFileName, Attr) then
Result:= False
else begin
Result:= (Attr.Size <> FAttributeData.Size) or
(Attr.LastWriteTime <> FAttributeData.LastWriteTime);
if Result then FAttributeData:= Attr;
end;
end;
function TArchiveFileSource.GetSupportedFileProperties: TFilePropertiesTypes;
begin
Result := inherited GetSupportedFileProperties
+ [fpSize, fpCompressedSize, fpAttributes, fpModificationTime];
end;
end.