-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patharvidavt.pas
1967 lines (1904 loc) · 58.4 KB
/
arvidavt.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{/////////////////////////////////////////////////////////////////////////
//
// 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 ArvidAvt;
interface
uses
Arvid, Objects2, Streams, Messages, DNApp, Commands, Objects,
Views, Drivers, Startup, UKeyMap, Advance, Lfnvp, Files, Dos, Tree,
FilesCol, Advance2, Drives, FlPanel, Memory
, Defines
;
function AvtCMP(S1, S2: String): Integer;
function AvtCellText(Offset: LongInt; var S: TStream): String;
function AvtCellName(const C: TAvtFileCell; var AStream: TStream): String;
function AvtCellDesc(const C: TAvtFileCell; var AStream: TStream): String;
function AvtGetCell(AvtDr: PArvidDrive): LongInt;
procedure AvtFreeCell(AvtDr: PArvidDrive; const l: LongInt);
function AvtCellRotateLeft(AvtDr: PArvidDrive; Loc: LongInt): LongInt;
function AvtCellRotateRight(AvtDr: PArvidDrive; Loc: LongInt): LongInt;
{procedure AvtCheckTree(AvtDr:PArvidDrive);}
function AvtDelFile(AvtDr: PArvidDrive; AName: String): Boolean;
function AvtNewFile(AvtDr: PArvidDrive;
AName: String;
ADescription: String;
AIsDir: Boolean;
AChildOrSize: LongInt;
ATime: LongInt;
AStartSector: LongInt;
AAttr: Word): Word;
procedure AvtSeekDirectory(AvtDr: PArvidDrive);
procedure AvtGetDirectory(AvtDr: PArvidDrive; var ALocation: LongInt;
var FC: PFilesCollection; const FileMask: String);
function CopyFilesToArvid(const S: String; Files: PCollection;
MoveMode: Boolean; Owner: Pointer): Boolean;
procedure AvtCopyFilesInto(AvtDr: PArvidDrive; AFiles: PCollection;
Own: PView; MoveMode: Boolean);
procedure AvtEraseFiles(AvtDr: PArvidDrive; AFiles: PCollection);
procedure AvtMakeDir(AvtDr: PArvidDrive);
procedure AvtEditDescription(AvtDr: PArvidDrive; var S, Nam: String);
procedure AvtCalcTotal(AvtDr: PArvidDrive; const Offset: LongInt;
var LL: TSize);
function AvtInit(AvtDr: PArvidDrive): Boolean;
implementation
uses
PDSetup, Advance1
;
var
FCtemp, FCLtemp, FCRtemp: TAvtFileCell;
ArvidDeleteAllFiles: Boolean;
function AvtCMP(S1, S2: String): Integer;
begin
UpStr(S1);
UpStr(S2);
if S1 = S2 then
AvtCMP := 0
else if S1 < S2 then
AvtCMP := -1
else
AvtCMP := 1;
end;
function AvtCellText(Offset: LongInt; var S: TStream): String;
var
T: TAvtTextCell;
S1: String;
begin
S1 := '';
while Offset <> 0 do
begin
S.Seek(Offset);
S.Read(T, SizeOf(T));
if S.Status <> stOK then
Break;
S1 := S1+Copy(T.Data, 1, 36);
Offset := T.NextTextCell;
end;
AvtCellText := S1;
end;
function AvtCellName(const C: TAvtFileCell; var AStream: TStream): String;
var
S: String;
begin
case C.Flags and AvtCellFormat of
avtCell0:
S := Copy(C.Name0, 1, 16);
avtCell1:
S := Copy(C.Name1, 1, 12);
avtCell2:
S := Copy(C.Name2, 1, 12);
avtCell3:
S := AvtCellText(C.NamePtr, AStream);
end {case};
while (Length(S) <> 0) and (S[Length(S)] = #0) do
SetLength(S, Length(S)-1);
AvtCellName := S;
end;
function AvtCellDesc(const C: TAvtFileCell; var AStream: TStream): String;
var
S: String;
begin
case C.Flags and AvtCellFormat of
avtCell2:
S := AvtCellText(C.DescPtr2, AStream);
avtCell3:
S := AvtCellText(C.DescPtr3, AStream);
else {case}
S := '' {avtCell0,avtCell1};
end {case};
while (Length(S) <> 0) and (S[Length(S)] = #0) do
SetLength(S, Length(S)-1);
AvtCellDesc := S;
end;
function AvtGetCell(AvtDr: PArvidDrive): LongInt;
var
T: TAvtTextCell;
M: TAvtMediaCell;
B: PChar;
begin
with AvtDr^ do
begin
if AVT.FreeCell = 0 then
begin
AvtGetCell := AVT.AfterLastCell;
Inc(AVT.AfterLastCell, SizeOf(T));
if (PosTableOfs <> 0) and (AVT.AfterLastCell >= PosTableOfs) then
begin
Stream^.Seek(AVT.AvtMediaCell);
Stream^.Read(M, SizeOf(M));
GetMem(B, M.PositionTableSize);
Stream^.Seek(PosTableOfs);
Stream^.Read(B^, M.PositionTableSize);
Inc(PosTableOfs, 512);
M.PositionTable := PosTableOfs;
Stream^.Seek(PosTableOfs);
Stream^.Write(B^, M.PositionTableSize);
FreeMem(B, M.PositionTableSize);
Stream^.Seek(AVT.AvtMediaCell);
Stream^.Write(M, SizeOf(M));
end;
end
else
begin
AvtGetCell := AVT.FreeCell;
Stream^.Seek(AVT.FreeCell);
Stream^.Read(T, SizeOf(T));
AVT.FreeCell := T.NextTextCell;
end;
end
end { AvtGetCell };
procedure AvtFreeCell(AvtDr: PArvidDrive; const l: LongInt);
var
T: TAvtTextCell;
begin
with AvtDr^ do
begin
if l = 0 then
Exit;
T.NextTextCell := AVT.FreeCell;
Stream^.Seek(l);
Stream^.Write(T, SizeOf(T));
AVT.FreeCell := l;
end
end;
function AvtCellRotateLeft(AvtDr: PArvidDrive; Loc: LongInt): LongInt;
var
Right: LongInt;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FCtemp, SizeOf(FCtemp));
Stream^.Seek(FCtemp.RightFileCell);
Stream^.Read(FCRtemp, SizeOf(FCRtemp));
if (FCRtemp.Flags and avtBalance) = $00000300 then
begin
Right := AvtCellRotateRight(AvtDr, FCtemp.RightFileCell);
Stream^.Seek(Loc);
Stream^.Read(FCtemp, SizeOf(FCtemp));
FCtemp.RightFileCell := Right;
Stream^.Seek(FCtemp.RightFileCell);
Stream^.Read(FCRtemp, SizeOf(FCRtemp));
end;
Right := FCtemp.RightFileCell;
FCtemp.RightFileCell := FCRtemp.LeftFileCell;
FCRtemp.LeftFileCell := Loc;
if FCRtemp.Flags and avtBalance = 0
then
FCtemp.Flags := (FCtemp.Flags and (not avtBalance))
{or $00000000}
else
FCtemp.Flags := (FCtemp.Flags and (not avtBalance)) or $00000300;
FCRtemp.Flags := (FCRtemp.Flags and (not avtBalance)) or $00000300;
Stream^.Seek(Loc);
Stream^.Write(FCtemp, SizeOf(FCtemp));
Stream^.Seek(Right);
Stream^.Write(FCRtemp, SizeOf(FCRtemp));
AvtCellRotateLeft := Right;
end
end { AvtCellRotateLeft };
function AvtCellRotateRight(AvtDr: PArvidDrive; Loc: LongInt): LongInt;
var
Left: LongInt;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FCtemp, SizeOf(FCtemp));
Stream^.Seek(FCtemp.LeftFileCell);
Stream^.Read(FCLtemp, SizeOf(FCLtemp));
if (FCLtemp.Flags and avtBalance) = $00000100 then
begin
Left := AvtCellRotateLeft(AvtDr, FCtemp.LeftFileCell);
Stream^.Seek(Loc);
Stream^.Read(FCtemp, SizeOf(FCtemp));
FCtemp.LeftFileCell := Left;
Stream^.Seek(FCtemp.LeftFileCell);
Stream^.Read(FCLtemp, SizeOf(FCLtemp));
end;
Left := FCtemp.LeftFileCell;
FCtemp.LeftFileCell := FCLtemp.RightFileCell;
FCLtemp.RightFileCell := Loc;
if (FCLtemp.Flags and avtBalance) = 0
then
FCtemp.Flags := (FCtemp.Flags and (not avtBalance))
{or $00000000}
else
FCtemp.Flags := (FCtemp.Flags and (not avtBalance)) or $00000100;
FCLtemp.Flags := (FCLtemp.Flags and (not avtBalance)) or $00000100;
Stream^.Seek(Loc);
Stream^.Write(FCtemp, SizeOf(FCtemp));
Stream^.Seek(Left);
Stream^.Write(FCLtemp, SizeOf(FCLtemp));
AvtCellRotateRight := Left;
end
end { AvtCellRotateRight };
{
procedure AvtCheckTree(AvtDr: PArvidDrive);
function AvtNodeHight(const Loc: LongInt): LongInt;
var
LeftHight: LongInt;
RightHight: LongInt;
begin with AvtDr^ do begin
AvtNodeHight:=0;
if Loc <> 0 then begin
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
LeftHight:=AvtNodeHight(FCtemp.LeftFileCell);
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
RightHight:=AvtNodeHight(FCtemp.RightFileCell);
if LeftHight >= RightHight then
AvtNodeHight:=LeftHight + 1 else
AvtNodeHight:=RightHight + 1;
end;
end end;
procedure AvtNodeCheck(const Loc: LongInt);
var
LeftHight: LongInt;
RightHight: LongInt;
Balance: LongInt;
begin with AvtDr^ do begin
if Loc <> 0 then begin
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
if (FCtemp.Flags and avtIsDir) <> 0 then begin
AvtNodeCheck(FCtemp.ChildOrSize);
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
end;
AvtNodeCheck(FCtemp.LeftFileCell);
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
AvtNodeCheck(FCtemp.RightFileCell);
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
LeftHight:=AvtNodeHight(FCtemp.LeftFileCell);
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
RightHight:=AvtNodeHight(FCtemp.RightFileCell);
Balance:=RightHight-LeftHight;
if (Balance < -1) or (Balance > 1) then
MessageBox(GetString(erInvalidFileFormat), nil, mfError + mfOKButton)
else begin
Balance:=(Balance shl 8) and $00000300;
Stream^.Seek(Loc); Stream^.Read(FCtemp, SizeOf(FCtemp));
if Balance <> (FCtemp.Flags and $00000300) then
MessageBox(GetString(erInvalidFileFormat), nil, mfError + mfOKButton);
end;
end;
end end;
begin
AvtNodeCheck(AvtDr^.AVT.RootDirCell);
end;
}
function AvtDelFile(AvtDr: PArvidDrive; AName: String): Boolean;
var
SaveCurDir: String;
CurDir2: String;
Dr: String;
Nm: String;
Xt: String;
SN: String;
FC: TAvtFileCell;
FCL: TAvtFileCell;
FCR: TAvtFileCell;
NewCurDirPos: LongInt;
DelDirAnswer: Word;
label 1;
procedure AvtDelCell(Loc: LongInt);
var
FC: TAvtFileCell;
T: TAvtTextCell;
L: LongInt;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
case FC.Flags and AvtCellFormat of
avtCell2:
L := FC.DescPtr2;
avtCell3:
L := FC.DescPtr3;
else {case}
L := 0 {avtCell0,avtCell1};
end {case};
while L <> 0 do
begin
Stream^.Seek(L);
Stream^.Read(T, SizeOf(T));
AvtFreeCell(AvtDr, L);
L := T.NextTextCell;
end;
if FC.Flags and AvtCellFormat = avtCell3
then
L := FC.NamePtr
else
L := 0 {avtCell0,avtCell1,avtCell2};
while L <> 0 do
begin
Stream^.Seek(L);
Stream^.Read(T, SizeOf(T));
AvtFreeCell(AvtDr, L);
L := T.NextTextCell;
end;
AvtFreeCell(AvtDr, Loc);
end
end { AvtDelCell };
procedure AvtFreeTree(const Loc: LongInt);
begin
with AvtDr^ do
begin
if Loc = 0 then
Exit;
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
if FC.Flags and AvtIsDir <> 0 then
begin
AvtFreeTree(FC.ChildOrSize);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
end;
AvtFreeTree(FC.LeftFileCell);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
AvtFreeTree(FC.RightFileCell);
AvtDelCell(Loc);
end
end;
function AvtTreeNodeRemove(const Loc: LongInt): LongInt;
var
OldBalance: LongInt;
L0, L1, L2: LongInt;
function AvtRestoreLeftBalance(Loc: LongInt;
const OldBalance: LongInt): LongInt;
var
LeftBalance: LongInt;
CurBalance: LongInt;
RightZeroBal: Boolean;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
CurBalance := FC.Flags and avtBalance;
if FC.LeftFileCell <> 0 then
begin
Stream^.Seek(FC.LeftFileCell);
Stream^.Read(FCL, SizeOf(FCL));
LeftBalance := FCL.Flags and avtBalance;
end;
if (FC.LeftFileCell = 0) or
( (LeftBalance <> OldBalance) and (LeftBalance = 0))
then
begin
FC.Flags := FC.Flags and (not avtBalance);
{ if CurBalance = $00000300 then FC.Flags:=FC.Flags or $00000000 else}
if CurBalance = $00000000 then
FC.Flags := FC.Flags or $00000100
else
{ if CurBalance = $00000100}
begin
Stream^.Seek(FC.RightFileCell);
Stream^.Read(FCR, SizeOf(FCR));
RightZeroBal := (FCR.Flags and avtBalance) = 0;
Loc := AvtCellRotateLeft(AvtDr, Loc);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
Stream^.Seek(FC.LeftFileCell);
Stream^.Read(FCL, SizeOf(FCL));
if RightZeroBal then
begin
FC.Flags := (FC.Flags and (not avtBalance)) or $00000300;
FCL.Flags := (FCL.Flags and (not avtBalance)) or $00000100;
end
else
begin
FC.Flags := (FC.Flags and (not avtBalance)) {or $00000000};
FCL.Flags := (FCL.Flags and (not avtBalance)) {or $00000000};
end;
Stream^.Seek(FC.LeftFileCell);
Stream^.Write(FCL, SizeOf(FCL));
end;
Stream^.Seek(Loc);
Stream^.Write(FC, SizeOf(FC));
end;
AvtRestoreLeftBalance := Loc;
end
end { AvtRestoreLeftBalance };
function AvtRestoreRightBalance(Loc: LongInt;
const OldBalance: LongInt): LongInt;
var
RightBalance: LongInt;
CurBalance: LongInt;
LeftZeroBal: Boolean;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
CurBalance := FC.Flags and avtBalance;
if FC.RightFileCell <> 0 then
begin
Stream^.Seek(FC.RightFileCell);
Stream^.Read(FCR, SizeOf(FCR));
RightBalance := FCR.Flags and avtBalance;
end;
if (FC.RightFileCell = 0) or
( (RightBalance <> OldBalance) and (RightBalance = 0))
then
begin
FC.Flags := FC.Flags and $FFFFFCFF;
{ if CurBalance = $00000100 then FC.Flags:=FC.Flags or $00000000 else}
if CurBalance = $00000000 then
FC.Flags := FC.Flags or $00000300
else
{ if CurBalance = $00000300}
begin
Stream^.Seek(FC.LeftFileCell);
Stream^.Read(FCL, SizeOf(FCL));
LeftZeroBal := (FCL.Flags and avtBalance) = 0;
Loc := AvtCellRotateRight(AvtDr, Loc);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
Stream^.Seek(FC.RightFileCell);
Stream^.Read(FCR, SizeOf(FCR));
if LeftZeroBal then
begin
FC.Flags := (FC.Flags and (not avtBalance)) or $00000100;
FCR.Flags := (FCR.Flags and (not avtBalance)) or $00000300;
end
else
begin
FC.Flags := (FC.Flags and (not avtBalance)) {or $00000000};
FCR.Flags := (FCR.Flags and (not avtBalance)) {or $00000000};
end;
Stream^.Seek(FC.RightFileCell);
Stream^.Write(FCR, SizeOf(FCR));
end;
Stream^.Seek(Loc);
Stream^.Write(FC, SizeOf(FC));
end;
AvtRestoreRightBalance := Loc;
end
end { AvtRestoreRightBalance };
function AvtTreeRemoveLeftmost(const Loc: LongInt): LongInt;
var
OldBalance: LongInt;
L1, L2: LongInt;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
if FC.LeftFileCell = 0 then
begin
l0 := Loc;
AvtTreeRemoveLeftmost := FC.RightFileCell;
Exit;
end;
L1 := FC.LeftFileCell;
Stream^.Seek(L1);
Stream^.Read(FC, SizeOf(FC));
OldBalance := FC.Flags and avtBalance;
L2 := AvtTreeRemoveLeftmost(L1);
if L1 <> L2 then
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
FC.LeftFileCell := L2;
Stream^.Seek(Loc);
Stream^.Write(FC, SizeOf(FC));
end;
AvtTreeRemoveLeftmost := AvtRestoreLeftBalance(Loc, OldBalance);
end
end { AvtTreeRemoveLeftmost };
function AvtTreeRemoveRightmost(const Loc: LongInt): LongInt;
var
OldBalance3: LongInt;
L1, L2: LongInt;
begin
with AvtDr^ do
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
if FC.RightFileCell = 0 then
begin
l0 := Loc;
AvtTreeRemoveRightmost := FC.LeftFileCell;
Exit;
end;
L1 := FC.RightFileCell;
Stream^.Seek(L1);
Stream^.Read(FC, SizeOf(FC));
OldBalance := FC.Flags and avtBalance;
L2 := AvtTreeRemoveRightmost(L1);
if L1 <> L2 then
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
FC.RightFileCell := L2;
Stream^.Seek(Loc);
Stream^.Write(FC, SizeOf(FC));
end;
AvtTreeRemoveRightmost := AvtRestoreRightBalance(Loc, OldBalance);
end
end { AvtTreeRemoveRightmost };
{ function AvtTreeNodeRemove(const Loc: LongInt): LongInt; }
begin { AvtTreeNodeRemove }
with AvtDr^ do
begin
AvtTreeNodeRemove := Loc;
if Loc = 0 then
Exit;
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
SN := AvtCellName(FC, Stream^);
if AvtCMP(AName, SN) < 0 then
begin
L1 := FC.LeftFileCell;
if L1 <> 0 then
begin
Stream^.Seek(L1);
Stream^.Read(FC, SizeOf(FC));
OldBalance := FC.Flags and avtBalance;
L2 := AvtTreeNodeRemove(L1);
if L1 <> L2 then
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
FC.LeftFileCell := L2;
Stream^.Seek(Loc);
Stream^.Write(FC, SizeOf(FC));
end;
AvtTreeNodeRemove := AvtRestoreLeftBalance(Loc, OldBalance);
end;
end
else if AvtCMP(AName, SN) > 0 then
begin
L1 := FC.RightFileCell;
if L1 <> 0 then
begin
Stream^.Seek(L1);
Stream^.Read(FC, SizeOf(FC));
OldBalance := FC.Flags and avtBalance;
L2 := AvtTreeNodeRemove(L1);
if L1 <> L2 then
begin
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
FC.RightFileCell := L2;
Stream^.Seek(Loc);
Stream^.Write(FC, SizeOf(FC));
end;
AvtTreeNodeRemove := AvtRestoreRightBalance(Loc, OldBalance);
end;
end
else
begin
if (FC.Flags and AvtIsDir) <> 0 then
begin
DelDirAnswer := cmOK;
if (not ArvidDeleteAllFiles) then
begin
Dec(SkyEnabled);
if Confirms and cfEraseSubDir = 0 then
DelDirAnswer := cmYes
else
begin
DelDirAnswer := cmCancel;
if FC.ChildOrSize = 0 then
DelDirAnswer := cmOK
else
begin
Stream^.Seek(FC.ChildOrSize);
Stream^.Read(FCR, SizeOf(FCR));
if (FCR.LeftFileCell = 0) and (FCR.RightFileCell = 0)
then
DelDirAnswer := cmOK
else
begin
if AvtCellName(FCR, Stream^) = '..' then
DelDirAnswer := cmOK
else
DelDirAnswer := MessageBox
(^C+GetString(dlDirectory)+' '+
CharToOemStr(Cut(AName, 40))+
GetString(dlEraseDirNotEmpty), nil,
mfConfirmation+mfNoButton+mfAllButton+
mf2YesButton+mfCancelButton);
end;
end;
end;
Inc(SkyEnabled);
ArvidDeleteAllFiles := DelDirAnswer = cmOK;
Abort := DelDirAnswer = cmCancel;
end;
if not (DelDirAnswer in [cmYes, cmOK]) then
Exit;
AvtFreeTree(FC.ChildOrSize);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
end;
AvtDelFile := True;
if FC.RightFileCell = 0 then
AvtTreeNodeRemove := FC.LeftFileCell
else
case (FC.Flags and avtBalance) of
0, $00000100:
begin
L1 := FC.RightFileCell;
Stream^.Seek(L1);
Stream^.Read(FCR, SizeOf(FCR));
OldBalance := FCR.Flags and avtBalance;
L2 := AvtTreeRemoveLeftmost(L1);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
FC.RightFileCell := L2;
Stream^.Seek(L0);
Stream^.Read(FCL, SizeOf(FCL));
FCL.LeftFileCell := FC.LeftFileCell;
FCL.RightFileCell := FC.RightFileCell;
FCL.Flags := (FCL.Flags and (not avtBalance))
or (FC.Flags and $00000300);
Stream^.Seek(L0);
Stream^.Write(FCL, SizeOf(FCL));
AvtTreeNodeRemove := AvtRestoreRightBalance(L0, OldBalance);
end;
$00000300:
begin
L1 := FC.LeftFileCell;
Stream^.Seek(L1);
Stream^.Read(FCL, SizeOf(FCL));
OldBalance := FCL.Flags and avtBalance;
L2 := AvtTreeRemoveRightmost(L1);
Stream^.Seek(Loc);
Stream^.Read(FC, SizeOf(FC));
FC.LeftFileCell := L2;
Stream^.Seek(L0);
Stream^.Read(FCR, SizeOf(FCR));
FCR.LeftFileCell := FC.LeftFileCell;
FCR.RightFileCell := FC.RightFileCell;
FCR.Flags := (FCR.Flags and (not avtBalance))
or (FC.Flags and $00000300);
Stream^.Seek(L0);
Stream^.Write(FCR, SizeOf(FCR));
AvtTreeNodeRemove := AvtRestoreLeftBalance(L0, OldBalance);
end;
end {case};
AvtDelCell(Loc);
end;
end
end { AvtTreeNodeRemove };
{ function AvtDelFile( AName: PathStr): Boolean; }
begin { AvtDelFile }
with AvtDr^ do
begin
AvtDelFile := False;
SaveCurDir := CurDir;
if (filetype <> avdAvt) or (Length(AName) = 0) then
goto 1;
CurDir2 := CurDir;
MakeSlash(CurDir2);
if AName[1] <> '/' then // slash change by unxed
begin
AName := CurDir2+AName;
end;
lFSplit(AName, Dr, Nm, Xt);
if (Dr[1] = '/') and (Length(Dr) > 1) then // slash change by unxed
Delete(Dr, 1, 1); {DelFC(Dr);}
if CurDir2 <> Dr then
begin
CurDir := Dr;
SeekDirectory;
CurDir2 := CurDir;
MakeSlash(CurDir2);
if CurDir <> Dr then
goto 1;
end;
AName := Nm+Xt;
if Length(AName) = 0 then
goto 1;
Stream^.Status := stOK;
OemToCharSt(AName);
NewCurDirPos := AvtTreeNodeRemove(CurDirPos);
if NewCurDirPos <> CurDirPos then
begin
if CurDirCellPos = 0 then
begin
AVT.RootDirCell := NewCurDirPos;
Stream^.Seek(0);
Stream^.Write(AVT, SizeOf(AVT));
end
else
begin
Stream^.Seek(CurDirCellPos);
Stream^.Read(FC, SizeOf(FC));
FC.ChildOrSize := NewCurDirPos;
Stream^.Seek(CurDirCellPos);
Stream^.Write(FC, SizeOf(FC));
end;
CurDirPos := NewCurDirPos;
end;
1:
CurDir := SaveCurDir;
SeekDirectory;
end
end { AvtDelFile };
function AvtNewFile(
AvtDr: PArvidDrive;
AName: String;
ADescription: String;
AIsDir: Boolean;
AChildOrSize: LongInt;
ATime: LongInt;
AStartSector: LongInt;
AAttr: Word): Word;
var
SaveCurDir: String;
CurDir2: String;
Dr: String;
Nm: String;
Xt: String;
SN: String;
SS: String;
FC: TAvtFileCell;
NewCurDirPos: LongInt;
NewCell: LongInt;
Lv: Integer;
NewCellFailed: Boolean;
FailedCellIsDir: Boolean;
CreatedCellIsDir: Boolean;
NewCellIsDir: Boolean;
FirstNameProcessed: Boolean;
function AvtPutText(S: String): LongInt;
var
T: TAvtTextCell;
L, L2: LongInt;
I: Integer;
begin
with AvtDr^ do
begin
if S = '' then
begin
AvtPutText := 0;
Exit;
end;
L := AvtGetCell(AvtDr);
AvtPutText := L;
while L <> 0 do
begin
for I := 1 to 36 do
begin
if Length(S) <> 0 then
begin
T.Data[I] := S[1];
Delete(S, 1, 1); {DelFC(S);}
end
else
T.Data[I] := #0;
end;
L2 := 0;
if Length(S) <> 0 then
L2 := AvtGetCell(AvtDr);
T.NextTextCell := L2;
Stream^.Seek(L);
L := L2;
Stream^.Write(T, SizeOf(T));
end;
end
end { AvtPutText };
procedure AvtPutName(S: String);
var
I: Integer;
begin
with AvtDr^ do
begin
if Length(S) < 13 then
begin
FC.Flags := (FC.Flags and (not AvtCellFormat)) or avtCell2;
for I := 1 to 12 do
begin
if Length(S) <> 0 then
begin
FC.Name2[I] := S[1];
Delete(S, 1, 1); {DelFC(S);}
end
else
FC.Name2[I] := #0;
end;
end
else
begin
FC.Flags := (FC.Flags and (not AvtCellFormat)) or avtCell3;
FC.NamePtr := AvtPutText(S);
end;
end
end { AvtPutName };
procedure AvtPutDesc(S: String);
begin
with AvtDr^ do
begin
if Length(S) <> 0 then
FC.DescPtr2 := AvtPutText(S)
else
FC.DescPtr2 := 0;
end
end;
procedure AvtNewCell;
begin
with AvtDr^ do
begin
NewCell := AvtGetCell(AvtDr);
FC.Flags := 0;
if (AName[1] = '/') or AIsDir then // slash change by unxed
AAttr := AAttr or Directory
else
AAttr := AAttr and not Directory;
FC.Attr := AAttr;
FC.LeftFileCell := 0;
FC.RightFileCell := 0;
FC.StartSector := 0;
FC.ChildOrSize := AChildOrSize;
FC.Time := ATime;
if (AName[1] = '/') or AIsDir then // slash change by unxed
begin
FC.Flags := (FC.Flags and (not AvtIsDir)) or AvtIsDir;
end;
if (AName = '') or (AName = '/') then // slash change by unxed
AvtPutDesc(ADescription)
else
AvtPutDesc('');
AvtPutName(SS);
CreatedCellIsDir := True;
if (FC.Flags and AvtIsDir) = 0 then
begin
FC.StartSector := AStartSector;
CreatedCellIsDir := False;
end;
Stream^.Seek(NewCell);
Stream^.Write(FC, SizeOf(FC));
AvtNewFile := 1;
end
end { AvtNewCell };
function AvtTreeNodeInsert(APos: LongInt): LongInt;
var
OldBalance: LongInt;
NewPointer: LongInt;
begin
with AvtDr^ do
begin
if APos = 0 then
begin
AvtNewCell;
AvtTreeNodeInsert := NewCell;
Exit;
end;
Stream^.Seek(APos);
Stream^.Read(FCtemp, SizeOf(FCtemp));
SN := AvtCellName(FCtemp, Stream^);
AvtTreeNodeInsert := APos;
if SS = SN then
begin
FailedCellIsDir := (FCtemp.Flags and AvtIsDir) <> 0;
NewCellFailed := True;
Exit;
end;
if AvtCMP(SS, SN) < 0 then
begin
if FCtemp.LeftFileCell <> 0 then
begin
Stream^.Seek(FCtemp.LeftFileCell);
Stream^.Read(FCLtemp, SizeOf(FCLtemp));
OldBalance := FCLtemp.Flags and avtBalance;
NewPointer := AvtTreeNodeInsert(FCtemp.LeftFileCell);
Stream^.Seek(APos);
Stream^.Read(FCtemp, SizeOf(FCtemp));
if NewPointer <> FCtemp.LeftFileCell then
begin
FCtemp.LeftFileCell := NewPointer;
Stream^.Seek(APos);
Stream^.Write(FCtemp, SizeOf(FCtemp));
end;
Stream^.Seek(FCtemp.LeftFileCell);
Stream^.Read(FCLtemp, SizeOf(FCLtemp));
if ( (FCLtemp.Flags and avtBalance) <> OldBalance) and
( (FCLtemp.Flags and avtBalance) <> 0)
then