-
Notifications
You must be signed in to change notification settings - Fork 2
/
WinDu.DirectoryEntry.pas
197 lines (190 loc) · 6.6 KB
/
WinDu.DirectoryEntry.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
//WinDu.DirectoryEntry
//
//MIT License
//
//Copyright (c) 2020 ottigeda
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
unit WinDu.DirectoryEntry;
interface
uses
Generics.Collections,
FMX.Controls,
FMX.Objects,
FMX.Types,
System.SysUtils;
type
////////////////////////////////////////////////////////////////////////////////
TDirectoryEntry = class(TObject)
private
FTotalFileSize: Int64;
FPath: string;
FSubDirs: TObjectList<TDirectoryEntry>;
FParentDir : TDirectoryEntry;
FLevel: Integer;
FNumberOfFiles: Int64;
FPie: TPie;
FOtherControls: TObjectList<TControl>;
FLineControls: TObjectList<TControl>;
function GetTotalSize: Int64;
function GetTotalFiles: Int64;
function GetTotalSizeText: string;
function GetIsLeft: Boolean;
function GetIsRight: Boolean;
function GetDirectory: string;
function GetTotalFolders: Int64;
function GetAngle: Extended;
public
constructor Create(ADirectory : string);
destructor Destroy; override;
property Path : string read FPath write FPath;
property Directory : string read GetDirectory;
property TotalFileSize : Int64 read FTotalFileSize write FTotalFileSize;
property NumberOfFiles : Int64 read FNumberOfFiles write FNumberOfFiles;
property ParentDir : TDirectoryEntry read FParentDir write FParentDir;
property SubDirs : TObjectList<TDirectoryEntry> read FSubDirs;
property TotalSize : Int64 read GetTotalSize;
property TotalSizeText : string read GetTotalSizeText;
property TotalFiles : Int64 read GetTotalFiles;
property TotalFolders : Int64 read GetTotalFolders;
property Level : Integer read FLevel write FLevel;
property Angle : Extended read GetAngle;
property Pie : TPie read FPie write FPie;
property OtherControls : TObjectList<TControl> read FOtherControls;
property LineControls : TObjectList<TControl> read FLineControls;
property IsLeft : Boolean read GetIsLeft;
property IsRight : Boolean read GetIsRight;
end;
////////////////////////////////////////////////////////////////////////////////
implementation
{ TDirectoryEntry }
////////////////////////////////////////////////////////////////////////////////
constructor TDirectoryEntry.Create(ADirectory: string);
begin
FSubDirs := TObjectList<TDirectoryEntry>.Create;
FOtherControls := TObjectList<TControl>.Create;
FLineControls := TObjectList<TControl>.Create;
FPath := ADirectory;
FTotalFileSize := 0;
FNumberOfFiles := 0;
FLevel := 0;
FPie := nil;
end;
////////////////////////////////////////////////////////////////////////////////
destructor TDirectoryEntry.Destroy;
begin
FreeAndNil(FSubDirs);
FreeAndNil(FOtherControls);
FreeAndNil(FLineControls);
FreeAndNil(FPie);
inherited;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetTotalSize: Int64;
var
entry : TDirectoryEntry;
begin
Result := 0;
for entry in FSubDirs do begin
Result := Result + entry.TotalSize;
end;
Result := Result + TotalFileSize;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetTotalSizeText: string;
const
SIZE_CLASS : array[0..6] of string = ('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
var
size : Extended;
i : Integer;
begin
size := TotalSize;
i := 0;
while (i < Length(SIZE_CLASS)-1) and (size > 1024) do begin
size := size / 1024;
i := i + 1;
end;
Result := Format('%.2f %s' ,[size, SIZE_CLASS[i]]);
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetTotalFiles: Int64;
var
entry : TDirectoryEntry;
begin
Result := 0;
for entry in FSubDirs do begin
Result := Result + entry.TotalFiles;
end;
Result := Result + NumberOfFiles;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetTotalFolders: Int64;
var
entry : TDirectoryEntry;
begin
Result := 0;
for entry in FSubDirs do begin
Result := Result + entry.TotalFolders;
end;
Result := Result + 1;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetAngle: Extended;
begin
Result := 0;
if Assigned(FPie) then begin
Result := FPie.EndAngle - FPie.StartAngle;
end;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetDirectory: string;
var
p : Integer;
begin
Result := ExcludeTrailingPathDelimiter(FPath);
p := Pos(PathDelim, Result);
while p > 0 do begin
Result := Copy(Result, p+1, Length(Result));
p := Pos(PathDelim, Result);
end;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetIsLeft: Boolean;
var
angle : Extended;
begin
Result := False;
if Assigned(FPie) then begin
angle := FPie.StartAngle + (FPie.EndAngle - FPie.StartAngle) / 2;
Result := Cos(angle/180*Pi) <= 0;
end;
end;
////////////////////////////////////////////////////////////////////////////////
function TDirectoryEntry.GetIsRight: Boolean;
var
angle : Extended;
begin
Result := False;
if Assigned(FPie) then begin
angle := (FPie.EndAngle - FPie.StartAngle) / 2;
Result := Cos(angle/180*Pi) >= 0;
end;
end;
////////////////////////////////////////////////////////////////////////////////
end.