-
Notifications
You must be signed in to change notification settings - Fork 2
/
FILECOPY.PAS
2594 lines (2395 loc) · 80.2 KB
/
FILECOPY.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 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).
//
//////////////////////////////////////////////////////////////////////////}
{$I STDEFINE.INC}
{$I DN.DEF}
unit FileCopy;
interface
uses Advance, Objects, Views, Dialogs, Drivers, FilesCol, Dos;
type
PCopyRec = ^TCopyRec;
TCopyRec = record
FC: PFilesCollection;
Owner: PView;
Where: TPoint;
end;
const
SkipCopyDialog: Boolean = Off;
CopyDirName: PathStr = '';
function GetFileAttr(const S: String): Word;
function SetFileAttr(const S: String; Attr: Word):Word;
procedure CopyFiles(Files: PCollection; Owner: PView; MoveMode: Boolean; FromTemp: Byte);
function SelectDialog(Select: Boolean; var St: String; var XORSelect: Boolean): Boolean;
procedure MakeListFile(APP: Pointer; Files: PCollection);
function CreateDirInheritance(var S: String; Confirm: Boolean): Byte;
procedure SetDescription(PF: PFileRec; DIZOwner: PathStr);
procedure BeepAfterCopy;
function GetDIZOwner(const Path, LastOwner: String; Add: Boolean): String;
function CalcDPath(P: PDIZ; Owen: PString): PathStr;
procedure DeleteDIZ(const DPath: PathStr; Name: Str12);
function CopyDialog( var CopyDir: PathStr; var Mask: Str12;
var CopyOpt: Word; var CopyMode: Word;
var CopyPrn: Boolean; {var Inheread: Byte;}
MoveMode: Boolean; Files: PCollection;
FromTemp: Byte; Owner: PView; Link: Boolean): Boolean;
implementation
uses DNApp, Startup, ExtraMemory, Memory, Messages, HistList, Commands,
DiskTool, xTime, Validate,
{$IFDEF MODEM}
NavyLink,
{$ENDIF}
Gauge, FileFind,
DNUtil, RStrings, Tree, Archiver, Drives, DiskInfo;
const
cpmOverwrite = 0;
cpmAppend = 1;
cpmAskOver = 2;
cpmSkipAll = 3;
cpmRefresh = 4;
cpoCheckFree = $01;
cpoVerify = $02;
cpoDesc = $04;
cpoMove = $08;
cpoFromTemp = $80;
cpoCopyDesc = $40;
cpoDirEmpty = $20;
var { SR: SearchRec;}
AppendInstalled: Boolean;
AppendState: Word;
SeekPos: LongInt;
type
PDir = ^TDir;
TDir = record
Created: (sNone, sCreated, sErased);
XName,Name: PString;
end;
Str80 = String[80];
PFileCopyRec = ^TFileCopyRec;
TFileCopyRec = record
Name: String[12];
Attr: Byte;
Size: LongInt;
Dir: PDir;
Owner: PFileRec;
DIZ: PDIZ;
end;
PCopyCollection = ^TCopyCollection;
TCopyCollection = object(TCollection)
procedure FreeItem(P: Pointer); virtual;
end;
PDirCollection = ^TDirCollection;
TDirCollection = object(TSortedCollection)
procedure FreeItem(P: Pointer); virtual;
function Compare(P1, P2: Pointer): Integer; virtual;
end;
function MemAvail: LongInt;
begin
MemAvail := MemAdjust(System.MemAvail);
end;
function MaxAvail: LongInt;
begin
MaxAvail := MemAdjust(System.MaxAvail);
end;
procedure GetFTimeSizeAttr(const A: string; var ATime, ASize: LongInt; AAttr: Word);
var
SR: SearchRec;
begin
ClrIO; FindFirst(A, $FF, SR);
ATime := SR.Time;
ASize := SR.Size;
AAttr := SR.Attr;
end;
function SetFileAttr(const S: String; Attr: Word) : Word; assembler;
asm
push ds
lds dx, S
inc dx
mov cx, Attr
mov ax, 4301h
int 21h
jc @@1
sub ax,ax
@@1:
pop ds
end;
function GetFileAttr(const S: String): Word; assembler;
asm
push ds
lds dx, S
inc dx
mov ax, 4300h
int 21h
pop ds
mov ax, cx
end;
function CorrectFile(const N: String): Boolean;
var I: Integer;
begin
CorrectFile := Off;
for I := 1 to Length(N) do
if N[I] in [#0..#31,'+','-','[',']','>','/','\',':','>','<','|'] then Exit;
CorrectFile := On;
end;
function GetPossibleDizOwner(N: Integer): String;
var DIZ: String;
I: Integer;
begin
GetPossibleDizOwner := '';
DIZ := FMSetup.DIZ;
while (N > 0) and (Diz <> '') do
begin
I := PosChar(';', DIZ); if I = 0 then I := Length(DIZ)+1;
if CorrectFile(Copy(DIZ,1,I-1)) then
begin
Dec(N);
if N = 0 then
begin
GetPossibleDizOwner := Copy(DIZ,1,I-1);
Exit;
end;
end;
Delete(DIZ, 1, I);
end;
end;
function GetDIZOwner;
var SR: SearchRec;
I: Integer;
lAdd: Boolean;
procedure Prepare;
var F: File;
C: Char;
I,J: Word;
begin
if lAdd then Exit;
Assign(F, MakeNormName(Path, SR.Name)); ClrIO;
FileMode := $42;
Reset(F, 1);
if IOResult <> 0 then Exit;
System.Seek(F, FileSize(F)-1);
BlockRead(F, C, 1, J);
if (IOResult = 0) and (C <> #13) and (C <> #10) then
begin
C := #13; BlockWrite(F, C, 1, J);
C := #10; BlockWrite(F, C, 1, J);
end;
ClrIO; Close(F); ClrIO;
end;
begin
lAdd := Add; SR.Name := LastOwner; Add := False;
I := 1;
if LastOwner = '' then GetDIZOwner := '' else
begin
GetDIZOwner := MakeNormName(Path, LastOwner);
FindFirst(MakeNormName(Path, LastOwner), Archive+ReadOnly+Hidden+SysFile, SR);
if DOSError = 0 then begin Prepare; Exit; end;
I := 1;
end;
repeat
SR.Name := GetPossibleDizOwner(I); Inc(I);
if SR.Name = '' then Exit;
FindFirst(MakeNormName(Path, SR.Name), Archive+ReadOnly+Hidden+SysFile, SR);
if DOSError = 0 then begin Prepare; GetDIZOwner := MakeNormName(Path, SR.Name); Exit end;
until False;
end;
procedure ReplaceT(P: PTextReader; var F: Text);
var
I: Integer;
FName: PathStr;
begin
FName := P^.FileName;
Dispose(P,Done); ClrIO;
Close(F); ClrIO;
EraseByName(FName);
I := IOResult; ClrIO;
System.Rename(F, FName);
if (IOResult <> 0) then
begin
if (I<>0) then System.Erase(F);
CantWrite(FName);
end;
ClrIO;
end;
procedure SetDescription;
var DIZ: String;
I: Integer;
F1: PTextReader;
F2: Text;
Name,NM: Str12;
MM: Boolean;
SSS: string;
begin
FileMode := $40;
if (PF = nil){or (PF^.Attr and Directory <> 0)} then Exit;
if DIZOwner = '' then
begin
Diz := GetPossibleDizOwner(1);
if DIZ = '' then
begin
MessageBox(GetString(dlNoPossibleName), nil, mfError);
Exit;
end;
DIZOwner := DIZ;
end else DIZOwner := GetName(DizOwner);
DIZOwner := GetDizOwner(PF^.Owner^, DizOwner, Off);
if (PF^.DIZ = nil) or (PF^.DIZ^.DIZ = nil) then DIZ := ''
else DIZ := PF^.DIZ^.DIZ^;
if InputBox(GetString(dlEditDesc),GetString(dl_D_escription), DIZ, 255, hsEditDesc) <> cmOK then Exit;
DelLeft(DIZ);
{Assign(F1, DIZOwner); ClrIO;}
if PF^.DIZ <> nil then
begin
Name := MakeFileName(PF^.Name); LowStr(Name);
FileMode := $40;
F1 := New(PTextReader, Init(DIZOwner)); if F1 = nil then Exit;
Assign(F2, GetPath(DIZOwner) + '$DN'+ItoS(DNNumber)+'$.DIZ');
Rewrite(F2); if IOResult <> 0 then begin Dispose(F1, Done); Exit; end;
MM := Off;
repeat
SSS := F1^.GetStr;
if MM or (SSS = '') or (SSS[1] = ' ') then
begin
if not F1^.EOF then WriteLn(F2, SSS);
end else
begin
I := 1;
While (I <= Length(SSS)) and (I <= 12) and (SSS[I] <> ' ') do Inc(I);
NM := Copy(SSS, 1, I-1); LowStr(NM);
if (NM = Name) or (NM = Name+'.') then
begin
if DIZ <> '' then WriteLn(F2, UpStrg(AddSpace(MakeFileName(UpStrg(PF^.Name)),13)), DIZ);
MM := On;
end else WriteLn(F2, SSS);
end;
until F1^.EOF or (IOResult <> 0);
ReplaceT(F1, F2);
end else
begin
ClrIO; Assign(F2, DIZOwner);
Append(F2); if Abort then Exit;
if IOResult <> 0 then Rewrite(F2);
if IOResult <> 0 then
begin
CantWrite(DIZOwner);
Exit;
end;
WriteLn(F2, UpStrg(AddSpace(MakeFileName(PF^.Name),13)), DIZ);
Close(F2);
end;
RereadDirectory(PF^.Owner^);
end;
procedure TCopyCollection.FreeItem;
begin
if P <> nil then Dispose(PFileCopyRec(P));
end;
procedure TDirCollection.FreeItem;
begin
if P <> nil then
with PDir(P)^ do
begin
DisposeStr(XName);
DisposeStr(Name);
Dispose(PDir(P));
end;
end;
function TDirCollection.Compare;
var S1, S2: String;
begin
Compare := 1;
if PDir(P1)^.Name <> nil then S1 := PDir(P1)^.Name^ else S1 := '';
if PDir(P2)^.Name <> nil then S2 := PDir(P2)^.Name^ else S2 := '';
if S1 < S2 then Compare := -1
else if S1 = S2 then
begin
if PDir(P1)^.XName <> nil then S1 := PDir(P1)^.XName^ else S1 := '';
if PDir(P2)^.XName <> nil then S2 := PDir(P2)^.XName^ else S2 := '';
if S1 < S2 then Compare := -1
else if S1 = S2 then Compare := 0
end
end;
procedure BeepAfterCopy;
var C: Char;
begin
DelayTics(1);
for C := 'A' to 'D' do
begin
Sound(1259);
DelayTics(1);
Sound(1400);
DelayTics(1);
end;
Sound(1259);
DelayTics(2);
NoSound;
end;
procedure MakeListFile;
label AddrError;
var I, J, K: Integer;
D, Dr, SR, Sn: PathStr;
P: PFileRec;
S: TMakeListRec;
T: Text;
Nm: NameStr;
Xt: ExtStr;
FidoMode: Boolean;
SS: String;
PP: PString;
ZZ, NN, ND, PT: Word;
BB: Boolean;
FLD, Dr_: PathStr;
procedure MakeStr(D: String);
label Fail;
var Drr: Boolean;
begin
{ BB means "Is filename occurs in Action?" }
Replace('!!', #0, D);
Sn := P^.Name; Replace( '!', #0, Sn ); { Fix for .!!! extension }
If ( S.Options and 2 = 2 ) and ( SR <> Dr ) and
( Pos( '!\', D ) = 0 ) and
( Pos( '!/', D ) = 0 ) and
( Pos( '!:', D ) = 0 ) then begin { Need to force insert !\ }
K := Pos( '.!', D );
If K = 0 then begin
K := PosChar( '!', D );
If K = 0 then goto Fail;
end else
If ( K <> 1 ) and ( D[ K - 1 ] = '!' )
then Dec( K )
else goto Fail;
Insert( '!\', D, K );
end;
Fail: { Cannot find place to insert !\ }
if SR[Length(SR)] <> '\' then AddStr(SR, '\');
BB := Replace('!\',SR, D) or BB;
BB := Replace('!/',Copy(SR,1,Length(SR)-1),D) or BB;
BB := Replace('!:',Copy(SR,1,2),D) or BB;
BB := Replace('.!', '.' + Copy(Sn, 10, 3), D) or BB;
BB := Replace('!', DelSpaces(Copy(Sn, 1, 8)), D) or BB;
Replace(#0, '!', D);
Replace(#1, ';', D);
if not BB then
begin
Dr_ := SR;
SR := MakeFileName(P^.Name);
if (S.Options and 1 = 1) or (S.Options and 2 <> 0)
and (Dr_ <> Dr) then
begin
SR := MakeNormName(DelSpaces(P^.Owner^),DelSpaces(SR));
end;
D := S.Action + SR;
end;
WriteLn(T, D);
end;
begin
if Files^.Count = 0 then Exit;
FillChar(S, SizeOf(S), 0);
S.FileName := HistoryStr(hsMakeList, 0);
if S.FileName = '' then S.FileName := 'DNLIST.BAT';
S.Action := HistoryStr(hsExecDOSCmd, 0);
S.Options := MakeListFileOptions;
if S.Options and cmlPathNames <> 0 then
begin
BB := Off;
for I := 1 to Files^.Count - 1 do
begin
BB := BB or (PFileRec(Files^.At(I-1))^.Owner <> PFileRec(Files^.At(I))^.Owner);
if BB then Break;
end;
if BB then S.Options := S.Options or cmlPathNames
else S.Options := S.Options and not cmlPathNames;
end;
if (ExecResource(dlgMakeList, S) <> cmOK) then Exit;
MakeListFileOptions := S.Options;
while S.Action[Length(S.Action)] = ' ' do Dec(S.Action[0]);
if S.Action <> '' then S.Action := S.Action + ' '; FileMode := 2;
Abort := Off;
if S.FileName[1] in ['+', '%', '/'] then
begin
FidoMode := True;
SS := FMSetup.DIZ;
I := SearchFor('/FIDO=', SS[1], Length(SS), Off);
if I = 1 then
begin
AddrError:
Msg(dlNoFTNset, nil, mfError+mfOKButton);
Exit;
end;
Delete(SS, 1, I+5);
I := PosChar(';', SS); if I = 0 then I := Length(SS)+1; SS[0] := Char(I-1);
I := PosChar(',', SS); if I = 0 then Goto AddrError;
ParseAddress(Copy(SS, 1, I-1), ZZ, NN, ND, PT); K := ZZ;
ParseAddress(Copy(S.FileName, 2, 255), ZZ, NN, ND, PT);
Delete(SS, 1, I); if SS[Length(SS)] = '\' then Dec(SS[0]);
FSplit(SS, Dr, Nm, Xt);
if K <> ZZ then Xt := '.'+Copy(Hex4(ZZ), 2, 3);
SS := Dr+Nm+Xt;
if PT = 0 then Nm := Hex4(NN)+Hex4(ND)
else begin
SS := MakeNormName(SS , Hex4(NN) + Hex4(ND) + '.PNT\');
Nm := Hex8(PT);
end;
Xt := '.hlo';
case S.FileName[1] of
'+': Xt[2] := 'c';
'%': Xt[2] := 'f';
end;
SS := MakeNormName(SS, Nm + Xt);
S.FileName := SS;
S.Options := S.Options or cmlPathNames;
end;
D := Advance.FExpand(S.FileName); FSplit(D, Dr, Nm, Xt); ClrIO;
FLD := Dr;
CreateDirInheritance(Dr, Off);
if Abort then Exit;
Assign(T, D); ClrIO;
Reset(T);
if IOResult = 0 then
begin
Close(T);
PP := @SS; SS := Cut(D, 40);
if FidoMode then I := cmOK
else I := MessageBox(GetString(dlED_OverQuery)
, @PP, mfYesButton+mfCancelButton+mfAppendButton+mfWarning);
case I of
cmOK: Append(T);
cmYes: Rewrite(T);
else Exit;
end;
end else Rewrite(T);
if Abort then Exit;
if IOResult<>0 then
begin
MessageBox(GetString(dlFBBNoOpen)+S.FileName, nil, mfError + mfOKButton);
Exit;
end;
for I := 1 to Files^.Count do
begin
P := Files^.At(I-1);
Message(APP, evCommand, cmCopyUnselect, P);
BB := False;
SR := P^.Owner^;
Replace('!', #0, SR);
if SR[Byte(Sr[0])] <> '\' then SR := SR +'\';
SS := S.Action;
if SS <> '' then
begin
Replace(';;', #1, SS);
while SS <> '' do
begin
J := PosChar(';', SS);
if J = 0 then J := Length(SS)+1;
MakeStr(Copy(SS, 1, J-1));
Delete(SS, 1, J);
end;
end else
If (S.Options and cmlPathNames <> 0) or (S.Options and 2 <> 0) and (SR <> FLD)
then MakeStr( '!\!.!' )
else MakeStr('!.!');
end;
Close(T);
RereadDirectory(Dr);
GlobalMessage(evCommand, cmRereadInfo, nil);
GlobalMessage(evCommand, cmRereadTree, @Dr);
end;
function SelectDialog;
var
I: Integer;
XorSel: Boolean;
S: String[12];
Idx: TDlgIdx;
D: PDialog;
V, V1: PView;
R: TRect;
function FindLine(P: PView): Boolean; far;
begin
FindLine := (P <> nil) and (P^.DataSize > 5);
end;
begin
XORSel := XORSelect;
SelectDialog := False;
if LowMemory then Exit;
if Select then Idx := dlgSelect else Idx := dlgUnselect;
D := PDialog(Application^.ValidView(PDialog(LoadResource(Idx))));
if D = nil then Exit;
S := HistoryStr(hsSelectBox, 0);
if S = '' then S := x_x;
V := D^.FirstThat(@FindLine);
if V <> nil then PInputLine(V)^.SetValidator(New(PFilterValidator,
Init([#32..#255]-
['+','|','>','<',']','['])));
D^.SetData(S);
if Desktop^.ExecView(D) = cmCancel then begin Dispose(D, Done); HistoryAdd(hsSelectBox, S); Exit; end;
SelectDialog := True;
D^.GetData(S);
Dispose(D, Done);
S := UpStrg(Norm12(S));
S[9] := ' '; St := S;
XORSelect := XORSel;
end;
function CreateDirInheritance;
var I, J: Integer;
SR: SearchRec;
LS: Byte absolute S;
M: PathStr;
BB: Boolean;
begin
CreateDirInheritance := 0; BB := On;
ClrIO; S := Advance.FExpand(S); if Abort then Exit;
I := PosChar(':',S);
if I = 0 then Exit;
Inc(I);
while I < LS do
begin
J := I;
repeat Inc(I); if I > LS then Exit until (S[I] = '\') or (I = LS);
M := Copy(S, 1, I-Byte(S[I] = '\'));
ClrIO; FindFirst(M, $3F xor VolumeID, SR);
if Abort then Exit;
if DOSError <> 0 then
begin
if BB and (S[I] = '\') then
begin CreateDirInheritance := J-1; BB := Off end;
if Confirm and ( Confirms and cfCreateSubDir <> 0) then
begin
if (S[0] > #3) and (S[Length(S)] = '\') then Dec(S[0]);
if (MessageBox(GetString(dlQueryCreateDir)+Cut(S, 40)+' ?', nil, mfYesNoConfirm) <> cmYes)
then Exit;
end;
ClrIO; MkDir(M);
if Abort or (IOResult <> 0) then
begin
MessageBox(GetString(dlFCNoCreateDir) + S, nil, mfError + mfOKButton);
Exit;
end;
CreateDirectory(M, Off);
end;
end;
end;
type
TBlock = record
Len : Word;
Time: LongInt;
EOF : Boolean;
Last: Boolean;
end;
const
eoStart = $01;
eoEnd = $02;
eoAppend = $04;
eoDir = $08;
eoCheck = $10;
MemStream: PMemoryStream = nil;
EMSStream: PEMSStream = nil;
NoUseEMS: Boolean = Off;
XMSStream: PXMSStream = nil;
NoUseXMS: Boolean = Off;
var
ToDo: LongInt;
type
PLine = ^TLine;
TLine = object(TObject)
Owner: Pointer;
OldName: Pointer;
NewName: PString;
Size, Pos, Date: LongInt;
Len: Word;
EOF: Byte;
Attr: Byte;
constructor Init(var ALen: LongInt; AOwner: Pointer; const AOldName, ANewName: String;
ASize, ADate: LongInt; AAttr: Byte; AEOF: ShortInt);
procedure PrepareToWrite; virtual;
function Stream: PStream; virtual;
procedure Write(var B);
procedure Read(var B);
destructor Done; virtual;
end;
PEMSLine = ^TEMSLine;
TEMSLine = object(TLine)
procedure PrepareToWrite; virtual;
function Stream: PStream; virtual;
end;
PXMSLine = ^TXMSLine;
TXMSLine = object(TLine)
procedure PrepareToWrite; virtual;
function Stream: PStream; virtual;
end;
PDirName = ^TDirName;
TDirName = object(TObject)
OldName, NewName: PString;
Check: Boolean;
CopyIt: Boolean;
Own: Pointer;
Attr: Byte;
constructor Init(const AOld, ANew: String; ACopy: Boolean; AnOwn: Pointer; AnAttr: Byte);
function Old: String;
function New: String;
destructor Done; virtual;
end;
{ TDirName }
constructor TDirName.Init;
begin
inherited Init;
OldName := NewStr(AOld);
NewName := NewStr(ANew);
CopyIt := ACopy;
Own := AnOwn;
Attr := AnAttr;
end;
function TDirName.New;
begin
if NewName = nil then New := '' else New := NewName^;
end;
function TDirName.Old;
begin
if OldName = nil then Old := '' else Old := OldName^;
end;
destructor TDirName.Done;
begin
DisposeStr(OldName);
DisposeStr(NewName);
end;
{ TLine }
constructor TLine.Init;
begin
inherited Init;
if MaxAvail < 2048 then Fail;
Len := ALen; EOF := AEOF; Attr := AAttr; Date := ADate; Size := ASize;
if Len <> 0 then
begin
PrepareToWrite;
if Len <= 0 then Fail;
ALen := Len;
end else EOF := eoStart + eoEnd;
Owner := AOwner;
if EOF and (eoStart or eoEnd) <> 0 then
OldName := NewStr(AOldName);
NewName := NewStr(ANewName);
end;
procedure TLine.Write;
begin
if Stream <> nil then Stream^.Write(B, Len);
end;
procedure TLine.Read;
begin
FillChar(B, Len, 0);
if Stream <> nil then
begin
Stream^.Seek(Pos);
Stream^.Read(B, Len);
end;
end;
destructor TLine.Done;
begin
DisposeStr(NewName);
DisposeStr(OldName);
inherited Done;
end;
procedure TLine.PrepareToWrite;
begin
if (XMSStream <> nil) or (EMSStream <> nil) then begin Len := 0; Exit; end;
if MemStream = nil then
begin
Pos := MaxAvail-$4000;
if Pos < $E000 then Pos := MaxAvail - $3000;
if Pos < $A000 then Pos := MaxAvail - $2000;
if Pos < $8000 then Pos := MaxAvail - $1000;
if Pos < $1000 then begin Len := 0; Exit end;
New(MemStream, Init(Pos, 2048));
end;
Pos := Stream^.GetPos;
if Pos + Len > Stream^.GetSize then Len := Stream^.GetSize - Pos;
end;
function TLine.Stream: PStream;
begin
Stream := MemStream;
end;
{ TEMSLine }
procedure TEMSLine.PrepareToWrite;
begin
if not EMSFound or NoUseEMS or (XMSStream <> nil) then begin Len := 0; Exit; end;
if EMSStream = nil then
begin
Pos := LongInt(EMSFreePages);
if Pos < 32 then begin NoUseEMS := True; Len := 0; Exit end;
if Pos > 512 then Pos := 512;
Pos := (Pos-1) * LongInt(16384);
if Pos > ToDo+10240 then Pos := ToDo+10240;
New(EMSStream, Init(Pos, Pos));
if EMSStream^.Status <> stOK then
begin
Dispose(EMSStream, Done);
EMSStream := nil;
Len := 0;
NoUseEMS := On;
Exit;
end;
end;
Pos := Stream^.GetPos;
if Pos + Len > Stream^.GetSize then Len := Stream^.GetSize - Pos;
end;
function TEMSLine.Stream: PStream;
begin
Stream := EMSStream;
end;
{ TXMSLine }
procedure TXMSLine.PrepareToWrite;
begin
if not XMSFound or NoUseXMS then begin Len := 0; Exit; end;
if XMSStream = nil then
begin
Pos := LongInt(XMSFree);
if Pos < 512 then begin NoUseXMS := On; Len := 0; Exit end;
if Pos > 8192 then Pos := 8192;
Pos := LongInt(Pos-1) shl 10;
if Pos > ToDo+10240 then Pos := ToDo+10240;
New(XMSStream, Init(Pos, Pos));
if XMSStream^.Status <> stOK then
begin
Dispose(XMSStream, Done);
XMSStream := nil;
NoUseXMS := On;
Len := 0;
Exit;
end;
end;
Pos := Stream^.GetPos;
if Pos + Len > Stream^.GetSize then Len := Stream^.GetSize - Pos;
end;
function TXMSLine.Stream: PStream;
begin
Stream := XMSStream;
end;
{ ----------------------------- File Copy ------------------------------ }
function CDRomInstalled : Boolean;
var
R : Registers;
begin
FillChar(R, SizeOf(R), 0);
with R do begin
AX := $1500;
Intr($2F, R);
CDRomInstalled := (BX <> 0);
end;
end;
procedure DisableAppend;
begin
if AppendInstalled then
asm
mov ax, $B707
mov bx, AppendState
and bx, $FFFE
push bp
int $2F
pop bp
end
end;
procedure DeleteDIZ(const DPath: PathStr; Name: Str12);
var F1: PTextReader;
F2: Text;
WB: Boolean;
I: Integer;
NM: Str12;
S: string;
begin
Name := MakeFileName(Name); LowStr(Name);
FileMode := $40; DisableAppend;
F1 := New(PTextReader, Init(DPath)); if F1 = nil then Exit;
Assign(F2, GetPath(DPath) + '$DN'+ItoS(DNNumber)+'$.DIZ');
DisableAppend;
Rewrite(F2); if IOResult <> 0 then begin Dispose(F1, Done); Exit; end;
WB := Off;
repeat
S := F1^.GetStr;
if WB or (S = '') or (S[1] = ' ') then WriteLn(F2, S)
else begin
I := 1;
While (I <= Length(S)) and (I <= 12) and (S[I] <> ' ') do Inc(I);
NM := Copy(S, 1, I-1); LowStr(NM);
if (NM = Name) or (NM = Name+'.') then
begin
WB := On;
repeat
S := F1^.GetStr;
until F1^.EOF or (S = '') or not (S[1] in [' ','.']) or (IOResult <> 0);
end;
WriteLn(F2, S);
end;
until F1^.EOF or (IOResult <> 0);
ReplaceT(F1, F2);
end;
function CalcDPath(P: PDIZ; Owen: PString): PathStr;
var
I: Integer;
DPath: PathStr;
SR: SearchRec;
begin
if (P = nil) or (P^.Owner = nil) then
begin
for I := 1 to 128 do
begin
DPath := GetPossibleDizOwner(I);
if DPath = '' then Exit;
DPath := MakeNormName(CnvString(Owen), DPath);
FindFirst(DPath, Archive+ReadOnly+Hidden, SR);
if DOSError = 0 then Break;
end;
end else DPath := P^.Owner^;
CalcDPath := DPath;
end;
procedure FilesCopy(Files: PCollection; Owner: PView;
const CopyDir, Mask: String; CopyMode, CopyOptions: Word; CopyPrn: Boolean);
var ReadStream: file;
WriteStream: file;
ReadPos: LongInt;
CopyCancel: Boolean;
B: Pointer;
BSize: Word;
TRead, TWrite,
ToRead, ToWrite: LongInt;
CopyQueue, Dirs: PCollection;
Info: PWhileView;
SoftMode: Boolean;
R: TRect;
Drv, InhR: Byte;
ReD: set of Char;
C: Char;
SS: string[1];
Timer: TEventTimer;
CD_Drives: set of Char;
AdvCopy, Use40: Boolean;
_Tmr: TEventTimer;
IOR: Integer;
SSS: string;
function GetPercent(N: Longint): Str12;
var
T: LongInt;
begin
if ToDo = 0 then N := 100 else
begin
T := ToDo; LowPrec(T, N);
N := (N*100) div T;
end;
GetPercent := ' ('+ItoS(N)+'%)';
end;
function MkName(Nm: Str12): Str12;
var I: Integer;
begin