-
Notifications
You must be signed in to change notification settings - Fork 10
/
arvidtdr.pas
381 lines (359 loc) · 11 KB
/
arvidtdr.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Open Source 1.51.08
// Based on Dos Navigator (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).
//
//////////////////////////////////////////////////////////////////////////}
{$I STDEFINE.INC}
unit ArvidTdr;
interface
uses
Arvid, Objects2, Streams, Advance1, Messages, DNApp, Commands, Objects,
Views, Drivers, Startup, UKeyMap, Advance, Lfnvp, Files, Dos, Tree,
FilesCol, Advance2, Drives, FlPanel, Memory
, Defines
;
procedure TdrSeekDirectory(AvtDr: PArvidDrive);
procedure TdrGetDirectory(AvtDr: PArvidDrive; var ALocation: LongInt;
var FC: PFilesCollection; const FileMask: String);
procedure TdrEditDescription(AvtDr: PArvidDrive; var S, Nam: String;
var PF: PFileRec);
procedure TdrCalcTotal(AvtDr: PArvidDrive; const Offset: LongInt;
var LL: TSize);
function TdrInit(AvtDr: PArvidDrive): Boolean;
function TdrMakeFileName(S: String): String; {JO}
implementation
uses
Archiver {TdrInit:_Cardinal} {piwamoto}
;
function TdrMakeFileName(S: String): String;
var
I: Integer;
begin
S[9] := '.';
I := 8;
while (I > 0) and (S[I] = ' ') do
begin
Delete(S, I, 1);
Dec(I);
end;
while S[Length(S)] = ' ' do
SetLength(S, Length(S)-1);
if S[Length(S)] = '.' then
SetLength(S, Length(S)-1);
Result := S;
end;
procedure TdrSeekDirectory;
var
I, J: LongInt;
Lv: Integer;
DD: TTdrDirCell;
SS: String;
// removed [12] to fix build by unxed
//SS: String[12];
S: String;
begin
with AvtDr^ do
begin
Stream^.Status := stOK;
Stream^.Seek(D.DirTableOfs);
Stream^.Read(DD, SizeOf(DD));
CurDirPos := i32(Stream^.GetPos);
S := CurDir;
CurLevel := 0;
CurDir := '';
Lv := 1;
if S[1] = '/' then // slash change by unxed
Delete(S, 1, 1); {DelFC(S);}
while S <> '' do
begin
SS := '';
while (S[1] <> '/') and (S <> '') do // slash change by unxed
begin
SS := SS+S[1]; {AddStr(SS, S[1]);}
Delete(S, 1, 1); {DelFC(S);}
if Length(SS) = 12 then
Break;
end;
Delete(S, 1, 1); {DelFC(S);}
SS := Norm12(SS);
UpStr(SS); {JO ??? for OS/2}
{AK155: ¥«ì§ï 㡨à âì! ਠ祬 âãâ OS/2 ª €à¢¨¤ã? }
Delete(SS, 9, 1);
repeat
Stream^.Read(DD, SizeOf(DD));
until (UpStrg(Copy(DD.Name, 1, 11)) = SS) and (DD.Level = Lv)
or (DD.Level < Lv);
if (DD.Level < Lv) or (DD.Level = 0) then
Break;
Insert('.', SS, 9);
MakeSlash(CurDir);
CurDir := CurDir+TdrMakeFileName(SS);
CurDirPos := i32(Stream^.GetPos);
CurLevel := Lv;
Inc(Lv);
end;
CurDate := DD.Time;
CurFile := DD.Files;
CurFileNum := DD.NumFiles;
end
end { TdrSeekDirectory };
procedure TdrGetDirectory(AvtDr: PArvidDrive; var ALocation: LongInt;
var FC: PFilesCollection; const FileMask: String);
var
FF: TTdrFileCell;
DD: TTdrDirCell;
I: LongInt;
J, SeekPos: LongInt;{!!s}
F: PFileRec;
procedure AddFile;
var
S: String;
b: Byte;
begin
with AvtDr^ do
begin
S := FF.Name;
Insert('.', S, 9);
{ if (s[01] in [#0..#31]) or
(s[02] in [#0..#31]) or
(s[03] in [#0..#31]) or
(s[04] in [#0..#31]) or
(s[05] in [#0..#31]) or
(s[06] in [#0..#31]) or
(s[07] in [#0..#31]) or
(s[08] in [#0..#31]) or
(s[09] in [#0..#31]) or
(s[10] in [#0..#31]) or
(s[11] in [#0..#31]) or
(s[12] in [#0..#31]) then exit; }
{AK155: ¢ à¨â« ¡®¢áª®¬ í⮣® ¥ ¡ë«® }
if
not (ArvidWithDN and Security and (FF.Attr and (Hidden+SysFile) <>
0))
and (AllFiles or (FF.Attr and Directory <> 0) or InFilter(S,
FileMask))
then
begin
{$IFDEF DualName}
F := NewFileRec(TdrMakeFileName(S), S, FF.Size, FF.Time, 0, 0,
FF.Attr, @CurDir);
{$ELSE}
F := NewFileRec(TdrMakeFileName(S), FF.Size, FF.Time, 0, 0,
FF.Attr, @CurDir);
{$ENDIF}
New(F^.DIZ);
F^.DIZ^.Container := nil;
F^.DIZ^.Line := SeekPos;
if FF.Description <> 0 then
begin
j := i32(Stream^.GetPos);
Stream^.Seek(D.DescTableOfs+FF.Description-1);
{Cat:warn AnsiString}
Stream^.Read(FreeStr, 2);
Stream^.Read(FreeStr[1], Length(FreeStr));
Stream^.Seek(j);
F^.DIZ^.DIZText := FreeStr;
end
else
F^.DIZ^.DIZText := '';
if FF.Attr and Directory = 0 then
begin
Inc(TotFiles);
TotLen := TotLen+FF.Size;
end;
FC^.Insert(F);
end;
end
end { AddFile };
begin { TdrGetDirectory }
with AvtDr^ do
begin
Stream^.Seek(CurDirPos);
repeat
SeekPos := i32(Stream^.GetPos+2);
Stream^.Read(DD, SizeOf(DD));
if DD.Level = CurLevel+1 then
begin
Move(DD.Name, FF, SizeOf(FF));
FF.Attr := FF.Attr or Directory;
AddFile;
end;
until (DD.Level = 0) or (DD.Level <= CurLevel);
Stream^.Status := stOK;
Stream^.Seek(D.FileTableOfs+CurFile*SizeOf(TTdrFileCell));
FC^.SetLimit(FC^.Count+CurFileNum);
for I := 1 to CurFileNum do
begin
SeekPos := i32(Stream^.GetPos);
Stream^.Read(FF, SizeOf(FF));
AddFile;
end;
end
end { TdrGetDirectory };
procedure TdrEditDescription;
var
FF: TTdrFileCell;
I, J{!!s}: LongInt;
procedure ExpandStream;
var
I, J: LongInt;
L: Word;
B: array[1..512] of Byte;
begin
with AvtDr^ do
begin
J := i32(Stream^.GetSize);
repeat
I := J-512;
if I < D.PosTableOfs then
I := D.PosTableOfs;
L := J-I;
Stream^.Seek(I);
Stream^.Read(B, L);
Stream^.Seek(I+512);
Stream^.Write(B, L);
J := I;
until J <= D.PosTableOfs;
FillChar(B, 512, 0);
Stream^.Seek(I);
Stream^.Write(B, 512);
Inc(D.PosTableOfs, 512);
end
end { ExpandStream };
begin { TdrEditDescription }
with AvtDr^ do
begin
Stream^.Read(FF, SizeOf(FF));
if Length(S) <= Length(PF^.DIZ^.DIZText) then
begin
if S = '' then
begin
FF.Description := 0;
Stream^.Seek(PF^.DIZ^.Line);
Stream^.Write(FF, SizeOf(FF));
end
else
begin
Stream^.Seek(D.DescTableOfs+FF.Description-1);
I := Length(S);
Stream^.Write(I, 2);
Stream^.Write(S[1], I);
end;
end
else
begin
if D.PosTableOfs-D.DescTableOfs-D.DescTableLen < 2+Length(S)
then
ExpandStream;
FF.Description := D.DescTableLen+1;
{+1 by piwamoto:new desc creation fix}
Stream^.Seek(PF^.DIZ^.Line);
Stream^.Write(FF, SizeOf(FF));
Inc(D.DescTableLen, Length(S)+2);
Stream^.Seek(D.DescTableOfs+FF.Description-1);
I := Length(S);
Stream^.Write(I, 2);
Stream^.Write(S[1], I);
end;
end
end { TdrEditDescription };
procedure TdrCalcTotal;
var
DD: TTdrDirCell;
SPos: LongInt;{!!s}
procedure CountDirectory(DD, Num: LongInt);
var
FF: TTdrFileCell;
I: Integer;
begin
with AvtDr^ do
begin
Stream^.Status := stOK;
Stream^.Seek(D.FileTableOfs+DD*SizeOf(TTdrFileCell));
for I := 1 to Num do
begin
Stream^.Read(FF, SizeOf(FF));
LL := LL+FF.Size;
end;
end
end;
begin
with AvtDr^ do
begin
SPos := CurDirPos;
repeat
Stream^.Seek(SPos);
Stream^.Read(DD, SizeOf(DD));
SPos := i32(Stream^.GetPos);
if DD.Level > CurLevel then
CountDirectory(DD.Files, DD.NumFiles);
until (DD.Level = 0) or (DD.Level <= CurLevel);
CountDirectory(CurFile, CurFileNum);
end
end { TdrCalcTotal };
function TdrInit;
var
J: Word;
begin
with AvtDr^ do
begin
TdrInit := False;
filetype := avdTdr;
Stream^.Seek(0);
Stream^.Read(D, SizeOf(D));
if (Stream^.Status <> stOK) or
(_Cardinal(D.PosTableOfs) > Stream^.GetSize)
then
Exit; {piwamoto: reject invalid TDRs}
TapeFmt := D.TapeFmt;
TapeTotalTime := D.TapeLen;
PosTableOfs := D.PosTableOfs;
Stream^.Seek(D.PosTableOfs);
Stream^.Read(J, SizeOf(J));
{ if Stream^.Status <> stOK then exit;} {commented by piwamoto}
TapeRecordedTime := J*8;
TdrInit := True;
end
end { TdrInit };
end.