-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathuvirtuallayer_types.pas
200 lines (167 loc) · 5.17 KB
/
uvirtuallayer_types.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
unit uvirtuallayer_types;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
const VL_ERROR_DISK_FULL=-1;
const VL_INVALID_HANDLE=nil;
type
TvlHandleRecord=record
VirtualLayer: Pointer;
Handle: Pointer;
end;
PvlHandleRecord=^TvlHandleRecord;
TvlHandle=Pointer;
TVirtualMountPoint=record
MountPath: UTF8String;
MountedVirtual: Pointer;
end;
{ TVirtualLayer_CustomAttributes }
TVirtualLayer_CustomAttributes=Class(TObject)
private
protected
function GetReadOnly: Boolean; virtual; abstract;
function GetHidden: Boolean; virtual; abstract;
function GetSystem: Boolean; virtual; abstract;
function GetLastModification: TDateTime; virtual; abstract;
// procedure SetReadOnly(const AValue: Boolean); virtual; abstract;
// procedure SetHidden(const AValue: Boolean); virtual; abstract;
// procedure SetSystem(const AValue: Boolean); virtual; abstract;
// procedure SetLastModification(const AValue: TDateTime); virtual; abstract;
public
property IsReadOnly: Boolean read GetReadOnly; //write SetReadOnly;
property IsHidden: Boolean read GetHidden; //write SetHidden;
property IsSystem: Boolean read GetSystem; //write SetSystem;
property LastModification: TDateTime read GetLastModification; //write SetLastModification;
end;
{ TVirtualLayer_Item }
TVirtualLayer_Item=class(TObject)
private
protected
function GetAttributesHumanReadable: UTF8String; virtual;
function GetAttributes: TVirtualLayer_CustomAttributes; virtual;
public
Name: UTF8String;
Size: int64;
IsFolder: Boolean;
IsMountPoint: Boolean;
property Attributes: TVirtualLayer_CustomAttributes read GetAttributes;
property AttributesHumanReadable: UTF8String read GetAttributesHumanReadable;
destructor Destroy; override;
end;
{ TVirtualLayer_FolderList }
TVirtualLayer_FolderList=class(TList)
private
FPath: UTF8String;
function GetAttributes: TVirtualLayer_CustomAttributes; virtual;
function GetItems(index: integer): TVirtualLayer_Item;
procedure SetItems(index: integer; const AValue: TVirtualLayer_Item);
protected
public
procedure AddInheritedPath(const APath: UTF8String);
function Extract(index: integer): TVirtualLayer_Item;
procedure Sort(const {%H-}Ascending: Boolean=true;const {%H-}FoldersFirst: Boolean=true);
procedure Delete(const Index: integer);
property Path: UTF8String read FPath;
property Items[index: integer]:TVirtualLayer_Item read GetItems write SetItems; default;
property Attributes: TVirtualLayer_CustomAttributes read GetAttributes;
Constructor Create(const APath: UTF8String);
Destructor Destroy(); override;
end;
implementation
function fSortAscendingFoldersFirst(item1,item2: Pointer): integer; forward;
{ TVirtualLayer_FolderList }
function TVirtualLayer_FolderList.GetItems(index: integer): TVirtualLayer_Item;
begin
Result:=TVirtualLayer_Item(inherited items[Index]);
end;
function TVirtualLayer_FolderList.GetAttributes: TVirtualLayer_CustomAttributes;
begin
Result:=nil;
end;
procedure TVirtualLayer_FolderList.SetItems(index: integer;
const AValue: TVirtualLayer_Item);
begin
inherited items[index]:=AValue;
end;
procedure TVirtualLayer_FolderList.AddInheritedPath(const APath: UTF8String);
begin
FPath:=APath+RightStr(FPath,Length(FPath)-1);
end;
function TVirtualLayer_FolderList.Extract(index: integer): TVirtualLayer_Item;
begin
Result:=Items[index];
inherited Delete(index);
end;
procedure TVirtualLayer_FolderList.Sort(const Ascending: Boolean;
const FoldersFirst: Boolean);
begin
inherited Sort(@fSortAscendingFoldersFirst);
end;
procedure TVirtualLayer_FolderList.Delete(const Index: integer);
begin
TObject(Get(Index)).Free;
inherited Delete(Index);
end;
constructor TVirtualLayer_FolderList.Create(const APath: UTF8String);
begin
inherited Create;
FPath:=APath;
end;
destructor TVirtualLayer_FolderList.Destroy();
var
j: integer;
begin
for j := 0 to Count-1 do begin
TObject(Items[j]).Free;
end;
inherited Destroy();
end;
{FORWARDS}
function fSortAscendingFoldersFirst(item1, item2: Pointer): integer;
var
l1,l2: TVirtualLayer_Item;
begin
l1:=TVirtualLayer_Item(item1);
l2:=TVirtualLayer_Item(item2);
if L1.IsFolder and L2.IsFolder then begin
Result:=CompareText(L1.Name,L2.Name);
end else begin
if L1.IsFolder then begin
Result:=-1;
end else if L2.IsFolder then begin
Result:=1;
end else begin
Result:=CompareText(L1.Name,L2.Name);
end;
end;
end;
{ TVirtualLayer_Item }
function TVirtualLayer_Item.GetAttributesHumanReadable: UTF8String;
var
T: UTF8String = '';
A: TVirtualLayer_CustomAttributes;
fs: TFormatSettings;
begin
Result := '';
A := Attributes;
if A=nil then Exit;
fs := DefaultFormatSettings;
Result := Result+'Regular attributes: ';
if A.IsReadOnly then T:=T+'Read Only,';
if A.IsHidden then T:=T+'Hidden,';
if A.IsSystem then T:=T+'System file,';
T:=LeftStr(T,Length(T)-1);
Result:=Result+T+#13+#10;
Result:=Result+'Last modification: '+FormatDateTime(fs.LongDateFormat+' '+fs.LongTimeFormat,A.LastModification)+#13+#10;
end;
function TVirtualLayer_Item.GetAttributes: TVirtualLayer_CustomAttributes;
begin
Result:=nil;
end;
destructor TVirtualLayer_Item.Destroy;
begin
if Attributes<>nil Then Attributes.Free;
inherited Destroy;
end;
end.