-
Notifications
You must be signed in to change notification settings - Fork 2
/
FILELIST.PAS
289 lines (267 loc) · 9.62 KB
/
FILELIST.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Version 1.51 Copyright (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
unit FileList;
interface
uses Drives, Drivers, Views, Objects, FilesCol, DOS, Advance, RStrings;
const DIZFilter: String = 'files.bbs;*.diz';
type
PDesc = ^TDesc;
TDesc = record
Name: String[12];
DIZ: PString;
end;
PDIZCol = ^TDIZCol;
TDIZCol = object(TSortedCollection)
procedure FreeItem(P: Pointer); virtual;
function Compare(P1, P2: Pointer): Integer; virtual;
end;
PListDrive = ^TListDrive;
TListDrive = object(TDrive)
Descriptions: PSortedCollection;
function GetDirectory(SortMode, PanelFlags: Integer; const FileMask: String;
var FreeSpace, TotalInfo: String ): PCollection; virtual;
destructor Done; virtual;
procedure GetFull(var B; P: PFileRec; C, Flags: Word); virtual;
procedure GetEmpty(var B; C, Flags: Word); virtual;
function CalcLength(Flags: Word): Integer; virtual;
procedure MakeTop(var S: String; Flags: Word); virtual;
end;
implementation
uses FLPanel, Memory, Tree, DNApp;
procedure TDIZCol.FreeItem;
begin
if P <> nil then
begin
DisposeStr(PDesc(P)^.DIZ);
Dispose(PDesc(P));
end;
end;
function TDIZCol.Compare;
begin
if PDesc(P1)^.Name < PDesc(P2)^.Name then Compare := -1 else
if PDesc(P1)^.Name = PDesc(P2)^.Name then Compare := 0 else
Compare := 1;
end;
destructor TListDrive.Done;
begin
if Descriptions <> nil then Dispose(Descriptions, Done);
inherited Done;
end;
function TListDrive.GetDirectory;
var Files: PFilesCollection;
SR: SearchRec;
P: PFileRec;
D: DateTime;
I,J: Integer;
DrNm: PathStr;
AllFiles: Boolean;
FreeSpc, TotalLen: LongInt;
S: String;
Hilite: Boolean;
PD: PDesc;
procedure ReadList;
var T: Text;
S: String;
S1: String[12];
I: Integer;
begin
ClrIO;
Assign(T, MakeNormName(CurDir, SR.Name));
Reset(T);
if (IOResult <> 0) or Abort then Exit;
While not SeekEOF(T) do
begin
ReadLn(T,S);
DelLeft(S);
S1 := '';
if S <> '' then
begin
While (S1[0] < #12) and (S[1] <> ' ') do
begin S1 := S1 + S[1]; DelFC(S) end;
DelLeft(S);
New(PD);
PD^.Name := LowStrg(Norm12(S1));
PD^.Name[9] := ' ';
PD^.DIZ := NewStr(S);
if not Descriptions^.Search(PD, I) then Descriptions^.AtInsert(I, PD)
else Descriptions^.FreeItem(PD);
end;
end;
Close(T);
end;
begin
DriveType := drListDrive;
if Descriptions <> nil then Dispose(Descriptions, Done);
Descriptions := nil;
Hilite := PFilePanel(Owner)^.PanelFlags and pfHiliteFiles <> 0;
DOSError := 0;
Abort := Off; AllFiles := FileMask = x_x; ClrIO; FreeSpc := 0;
FreeSpace := ''; TotalInfo := ''; TotalLen := 0;
Files := New(PFilesCollection, Init(10, 20));
PFilesCollection(Files)^.Owner := Owner;
if PanelFlags and pfFreeSpace <> 0 then FreeSpc := DiskFree(Byte(CurDir[1])-64);
PFilesCollection(Files)^.SortMode := SortMode;
DosError := 0; ClrIO; Abort := Off;
DrNm := MakeNormName(CurDir,x_x);
FindFirst(DrNm, $3F xor VolumeID, SR);
While (DosError = 0) and not Abort and (IOResult = 0) and (MemAvail > LowMemSize) do
begin
if (SR.Attr and VolumeID = 0) and (SR.Name <> '.') then
if (SR.Name[1] = '.') or (not Security or (Security and (SR.Attr and Hidden=0))) then
if AllFiles or (SR.Attr and Directory <> 0) or (InFilter(SR.Name, FileMask)) then
begin
New(P);
if SR.Name[1] <> '.' then
begin
I := Pos('.', SR.Name);
if I = 0 then P^.Name := SR.Name + Strg(32,12)
else P^.Name := Copy(Copy(SR.Name, 1, I - 1) + ' ', 1, 9) + Copy(SR.Name, I + 1, 3) + ' ';
end else P^.Name := '.. ';
UnpackTime(SR.Time, D);
P^.TType := Byte(Hilite);
P^.Year := D.Year mod 100;
P^.Month := D.Month;
P^.Day := D.Day;
P^.Hour := D.Hour;
P^.Min := D.Min;
P^.Attr := SR.Attr;
P^.Size := SR.Size;
P^.DIZ := nil;
P^.Selected := Off;
if SR.Attr and Directory = 0 then
begin
if (Descriptions = nil) and InFilter(SR.Name, DIZFilter) then
begin
Descriptions := New(PDIZCol, Init(10,10));
ReadList;
end;
LowStr(P^.Name);
if SR.Attr and SysFile <> 0 then P^.Name[1] := UpCase(P^.Name[1]);
end else
begin
P^.Size := 0;
if PanelFlags and pfShowLength <> 0 then
begin
if SR.Name[1] = '.' then P^.Size := GetDirLen(CurDir)
else P^.Size := GetDirLen(CurDir+'\'+SR.Name);
if Abort then begin PanelFlags := PanelFlags and (not pfShowLength); Abort := Off; end;
end;
end;
if P^.Name[1] <> '.' then Inc(TotalLen, P^.Size);
P^.Owner := @CurDir;
if P^.Attr and Hidden <> 0 then P^.Name[9] := '±';
if P^.Attr and SysFile <> 0 then P^.Name[9] := '²';
if Hilite then P^.TType := GetFileType(P^.Name, P^.Attr) else P^.TType := 0;
Files^.Insert(P);
end;
DosError := 0;
FindNext(SR);
end;
if Files^.Count = 0 then S := GetString(dlDINoFiles)
else begin
S := GetString(dlTotal);
if Files^.Count = 1 then S := S+'1~ '+GetString(dlDIFile)
else S := S+ItoS(Files^.Count)+'~ '+GetString(dlDIFiles);
S := S + GetString(dlDIWith) + '~';
if TotalLen = 1 then S := S + '1~ '+GetString(dlDIByte)
else S := S + FStr(TotalLen)+'~ '+GetString(dlDIBytes);
end;
TotalInfo := S;
FreeSpace := '~'+FStr(FreeSpc)+GetString(dlDIFreeDisk)+Copy(CurDir, 1, 2);
if (CurDir[0] > #3) and (PFileRec(Files^.At(0))^.Name <> '.. ') then
begin
New(P);
P^.Name := '.. ';
P^.TType := Byte(Hilite);
P^.Year := 80;
P^.Month := 1;
P^.Day := 1;
P^.Hour := 0;
P^.Min := 0;
P^.Attr := Directory;
P^.Size := 0;
P^.DIZ := nil;
P^.Selected := Off;
if PanelFlags and pfShowLength <> 0 then
begin
P^.Size := GetDirLen(CurDir);
if Abort then begin PanelFlags := PanelFlags and (not pfShowLength); Abort := Off; end;
end;
P^.Owner := @CurDir;
Files^.Insert(P);
end;
if Descriptions <> nil then
for I := 1 to Files^.Count do
begin
P := Files^.At(I-1);
if Descriptions^.Search(P, J) then P^.DIZ := PDesc(Descriptions^.At(J))^.DIZ
else P^.DIZ := nil;
end;
GetDirectory := Files;
end;
procedure TListDrive.GetEmpty;
var
X: Byte;
begin
TWordArray(B)[12] := (TWordArray(B)[12] and $F000) or (C and $0FFF);
end;
procedure TListDrive.MakeTop;
begin
S := GetString(dlListDriveTop) + Strg(32, 255);
end;
procedure TListDrive.GetFull;
var S: String;
X: Byte;
begin
if P^.DIZ <> nil then S := Copy(P^.DIZ^,1,MaxViewWidth) else S := '';
MoveStr(TWordArray(B), P^.Name, C);
MoveStr(TWordArray(B)[13], S, C);
end;
function TListDrive.CalcLength;
begin
CalcLength := MaxViewWidth;
end;
end.