-
Notifications
You must be signed in to change notification settings - Fork 2
/
NAVYLINK.PAS
1433 lines (1259 loc) · 37.6 KB
/
NAVYLINK.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).
//
//////////////////////////////////////////////////////////////////////////}
unit NavyLink;
{$I LINK.INC} interface uses
Advance, Dos, Objects, Views, Drives, Drivers,
xTime, Gauge, DiskInfo, FilesCol, ObjType;
type
TLinkMode = (lcmUnknown, lcmLinkToLocal, lcmLocalToLink);
PLinker = ^TLinker;
TLinker = object(TView)
NumErrors: Integer;
DriveCache: LongInt;
SlaveJob: PObject;
constructor Init(var R: TRect);
constructor Load(var S: TStream);
procedure HandleEvent(var Event: TEvent); virtual;
function Valid(C: Word): Boolean; virtual;
procedure Draw; virtual;
destructor Done; virtual;
procedure Update; virtual;
private
Pohui: Boolean;
RefreshWndTimer: TEventTimer;
MainTimeOut: TEventTimer;
Grd: PWhileView;
_Mask: Str12;
_Name: Str12;
CopyOpt: Word;
CopyMode: Word;
CopyPrn: Boolean;
CopyFileBuf: Pointer;
MoveMode: Boolean;
LinkMode: TLinkMode;
DirLevel: Byte;
CopyOwner: PView;
KillEmAll: Boolean;
procedure Initialize;
end;
PLinkDrive = ^TLinkDrive;
TLinkDrive = object(TDrive)
constructor Init(D: Char);
procedure ChDir(ADir: PathStr); virtual;
function GetDir: PathStr; virtual;
function GetDirectory(SortMode, PanelFlags: Integer; const FileMask: String;
var FreeSpace, TotalInfo: String ): PCollection; virtual;
procedure RereadDirectory(S: PathStr); virtual;
procedure CopyFiles(AFiles: PCollection; Own: PView; MoveMode: Boolean); virtual;
{ From Link to Local Drive }
procedure CopyFilesInto(AFiles: PCollection; Own: PView; MoveMode: Boolean); virtual;
procedure EraseFiles(AFiles: PCollection); virtual;
function GetRealName: String; virtual;
procedure MakeDir; virtual;
procedure ChangeUp(var S: String); virtual;
procedure GetFreeSpace(var S: String); virtual;
procedure GetDirInfo(var B: TDiskInfoRec); virtual;
procedure UseFile(P: PFileRec; Command: Word); virtual;
end;
const
RLinker: TStreamRec = (
ObjType: otLinker;
VmtLink: Ofs(TypeOf(TLinker)^);
Load: @TLinker.Load;
Store: @TLinker.Store);
RLinkDrive: TStreamRec = (
ObjType: otLinkDrive;
VmtLink: Ofs(TypeOf(TLinkDrive)^);
Load: @TLinkDrive.Load;
Store: @TLinkDrive.Store);
procedure StartLink;
procedure CopyToLinkDrive(AFiles: PCollection; AOwner: PView; const RealDest: PathStr; Mask: Str12);
{ From Local to Link Drive }
procedure CopyFromLinkDrive(AFiles: PCollection; AOwner: PView; const RealDest: PathStr);
{ From Link to Local Drive }
procedure CL_GetLinkDrives(var CSet: CharSet);
function NewLinkDrive(C: Char): PDrive;
implementation
uses {$IFDEF CL_LOG} ComLnk, {$ENDIF}
Dialogs,
LinkTyp, FlPanel, Memory, ApPort,
OOCom, ModemIO, Commands, DNApp, Messages, DnHelp, FileCopy,
ApMisc, LinkUtil, Startup, Eraser;
function NewLinkDrive;
begin
NewLinkDrive := New(PLinkDrive, Init(C));
end;
procedure Reread_Dir(const ADir: PathStr);
begin
Drives.RereadDirectory(ADir);
end;
const MainTimeOutSecs = 60;
procedure InitMainTimeOut; begin NewTimerSecs(PLinker(Linker)^.MainTimeOut,MainTimeOutSecs) end;
function Ask(const Msg: String; Params: Pointer; AOptions: Word ): Word;
begin
Ask := MessageBox(Msg, Params, AOptions);
InitMainTimeOut;
end;
function WaitRemote: Boolean; forward;
procedure StartLink;
var D: PDialog;
R: TRect;
begin
if ComPort = nil then InitModem;
if ComPort = nil then Exit;
if Linker <> nil then begin PLinker(Linker)^.Owner^.Select; Exit end;
if (System.MemAvail<80*1024) or (System.MaxAvail<32*1024) then
begin Application^.OutOfMemory; Exit; end;
R.Assign(1,2,39,9);
New(D, Init(R, GetString(dlLinkTitle)));
D^.HelpCtx := hcLinkStatusWnd;
D^.GetExtent(R); R.Grow(-1,-1);
Linker := New(PLinker, Init(R)); D^.Insert(Linker);
D^.Hide;
Desktop^.InsertView(D, DeskTop^.Last);
D^.Show;
if WaitRemote then Msg(dlLinkStarted, nil, mfInformation+mfOKButton);
end;
procedure CreateGrd(const Title: string);
var
R: TRect;
begin with PLinker(Linker)^ do begin
if Grd <> nil then Exit;
R.Assign(0,0,40,9);
Grd := New(PWhileView, Init(R));
PWhileView(Grd)^.Top := Title;
Desktop^.Insert(Grd);
end end;
procedure DisposeGrd;
begin with PLinker(Linker)^ do begin
if Grd = nil then Exit;
Dispose(Grd, Done);
Grd := nil;
end end;
procedure SetBottom(const S: string);
begin
with PLinker(Linker)^.Grd^ do begin Bottom := S; DrawView end;
end;
procedure WriteGrd(N: Integer; const S: string);
begin
PLinker(Linker)^.Grd^.Write(N, S);
end;
procedure DispatchGrd(var B: Boolean);
begin with PLinker(Linker)^ do begin
B := False; DispatchEvents(PWhileView(Grd), B);
B := B or CtrlBreakHit;
CtrlBreakHit := False;
end end;
procedure TLinker.Initialize;
begin
RegisterToPrior(@Self);
UpdTicks := 1;
NewTimer(RefreshWndTimer,0);
CL_InitLink;
Inc(SkyEnabled);
Pohui := False;
end;
constructor TLinker.Init;
begin
inherited Init(R);
Options := Options or ofSelectable;
EventMask := evCommand or evKeyDown;
HelpCtx := hcLinkStatusWnd;
Initialize;
end;
constructor TLinker.Load;
begin
if ComPort = nil then InitModem;
if ComPort = nil then Fail;
TObject.Init;
inherited Load(S);
Linker := @Self;
Initialize;
end;
destructor TLinker.Done;
begin
Dec(SkyEnabled);
Deregister(@Self);
CL_DoneLink;
Linker := nil;
inherited Done;
end;
procedure TLinker.HandleEvent;
begin
case Event.What of
evCommand: if Event.Command = cmGetName then
begin
PString(Event.InfoPtr)^ := GetString(dlLinkTitle);
ClearEvent(Event);
end;
evKeyDown: if Event.KeyCode = kbESC then
begin
Event.What := evCommand;
Event.Command := cmClose; Event.InfoPtr := nil;
end;
end;
inherited HandleEvent(Event);
end;
function TLinker.Valid;
begin
Valid := Pohui; if Pohui then Exit;
case C of
cmQuit : Pohui := (CL_Abort) or (Msg(dlLinkQueryExit, nil, mfYesNoConfirm) = cmYes);
cmClose : Pohui := Msg(dlLinkClose, nil, mfYesNoConfirm) = cmYes;
else begin Valid := True; Exit end;
end;
if Pohui then GlobalMessage(evCommand, cmCloseLinked, nil);
Valid := Pohui;
end;
function Nice(s: string): string;
begin
if s <> '' then while Length(s) < CL_StatusStrWdth do s := ' '+s+' ';
Nice := s;
end;
procedure TLinker.Draw;
var
C: Word;
B: TDrawBuffer;
R: TRect;
si: TCL_StatusInfo;
procedure Wrt(Y: Byte; const S: string);
begin
MoveChar(B, ' ', C, Size.X); MoveStr(B, Nice(S), C);
WriteLine(0,Y,Size.X,1,B);
end;
function StatusStr: string;
begin
if not si.ConnectOK then StatusStr := GetString(dlLinkNoRemoteLink) else
if SlaveJob = nil then StatusStr := GetString(dlLinkWaitingCmd) else
StatusStr := PCL_SlaveJob(SlaveJob)^.InfoStr;
end;
begin
with si do
begin
ConnectOK := not CL_Abort;
ComPort^.GetLine(Speed, ParityType(Parity), DataBitType(DataBits), StopBitType(StopBits), False);
ComNum := Byte(ComPort^.GetComName)+1;
ErrStr := GetString(dlLinkErrors);
CL_GetLinkNfo(si);
end;
C := GetColor(1);
Wrt(0, '');
Wrt(1, si.PortStr);
Wrt(2, StatusStr);
Wrt(3, si.ErrStr);
Wrt(4, '');
end;
function ESC_Pressed: Boolean;
var E: TEvent; begin GetKeyEvent(E); ESC_Pressed := (E.What = evKeyDown) and (E.KeyCode = kbEsc) end;
procedure GiveSlice; var ET: TEventTimer;
begin NewTimer(ET, 1); repeat Application^.Idle until TimerExpired(ET) end;
procedure ReportRemoteError(Code: Word);
var
L: LongInt;
begin
L := Code;
Ask(GetString(dlLinkRemoteError), @L, mfError+mfOkButton);
end;
procedure __Halt;
begin
{$IFDEF CL_LOG}CL_WLog('*** Halted ***');Close(CL_LogF);{$ENDIF}
RunError(222);
end;
procedure UnExp;
begin
{$IFDEF CL_LOG}CL_WLog('Unexpected condition');{$ENDIF}
__Halt;
end;
{$IFNDEF DN}
var SlaveJob: PObject;
{$ENDIF}
procedure SlaveGetFile(const FName: string);
var
SJ: PCL_SlaveFileJob;
begin
{$IFDEF NLSLAVE} SlaveInfo('Get file '+FName); {$ENDIF}
if {$IFDEF DN}PLinker(Linker)^.{$ENDIF}SlaveJob <> nil then __Halt;
SJ := New(PCL_SlaveFileSend, Init(FName, 0));
{$IFDEF DN}PLinker(Linker)^.{$ENDIF}SlaveJob := SJ;
end;
procedure WipeObj(var P: PCL_SlaveJob);
begin
if P = nil then Exit;
Dispose(P, Done);
P := nil;
end;
function DoSlaveJob{$IFDEF DN}(var SlaveJob: PObject){$ENDIF}: Boolean;
var
J: PCL_SlaveJob absolute SlaveJob;
begin
if J <> nil then
begin
if (CL_Abort) or (not J^.Next) then WipeObj(J);
end;
DoSlaveJob := {True}J = nil;
end;
procedure SlaveCatchFile(const Nfo: TCL_FileNfo; const FName: string);
var
SJ: PCL_SlaveFileJob;
begin
{$IFDEF NLSLAVE} SlaveInfo('Catch file '+FName); {$ENDIF}
if {$IFDEF DN}PLinker(Linker)^.{$ENDIF}SlaveJob <> nil then __Halt;
SJ := New(PCL_SlaveFileRece, Init(Nfo, FName, 0));
{$IFDEF DN}PLinker(Linker)^.{$ENDIF}SlaveJob := SJ;
end;
procedure ProcessInCmd;
var
P: PCL_InCmd;
begin
P := CL_InCmd^.At(0);
case P^.Typ of
ic_GetDrives : CL_PostDriveSet;
ic_FileNfo : with PCL_FileNfoCmd (P)^ do SlaveCatchFile(Nfo, s);
ic_GetFile : with PCL_StrCmd (P)^ do SlaveGetFile(s);
ic_EraseFile : with PCL_StrCmd (P)^ do CL_EraseFile(s);
ic_EraseDir : with PCL_StrCmd (P)^ do CL_EraseDir(s);
ic_GetDir : with PCL_DirReqCmd (P)^ do CL_PostDirEntries(Dir, Mask, R);
ic_GetDirNfo : with PCL_StrCmd (P)^ do CL_PostDirNfo(s);
ic_GetDirValid : with PCL_StrCmd (P)^ do CL_PostDirValid(s);
ic_MkDir : with PCL_StrCmd (P)^ do CL_MakeDirectory(s);
else UnExp;
end;
CL_InCmd^.AtFree(0);
end;
function CollectInData: Boolean;
begin
CL_CollectInData;
while DoSlaveJob{$IFDEF DN}(PLinker(Linker)^.SlaveJob){$ENDIF} and CL_CanProcInCmds do ProcessInCmd;
CollectInData := not CL_Abort;
end;
procedure ClrGrd(const s: string);
begin
WriteGrd(1,s);
WriteGrd(2,'');
WriteGrd(3,'');
SetBottom('');
end;
function WaitRemote;
var
C: Boolean;
A: Boolean;
T: TEventTimer;
begin
A := CL_Abort;
if A then
begin
A := False;
CreateGrd(GetString(dlLinkTitle));
ClrGrd(GetString(dlLinkRemoteWait));
NewTimer(T, 20);
repeat
if CL_Abort then NewTimer(T, 20);
GiveSlice;
C := Off; DispatchGrd(C);
C := C or CtrlBreakHit;
CtrlBreakHit := Off;
if C then begin A := True; break end;
until (not CL_Abort) and TimerExpired(T);
DisposeGrd;
end;
WaitRemote := not A;
end;
function ApplicationIdle: Boolean;
var
C: Boolean;
begin
GiveSlice;
if PLinker(Linker)^.Grd = nil then C := ESC_Pressed else DispatchGrd(C);
if C then C := Ask(GetString(dlLinkQueryExit), nil, mfYesNoConfirm) = cmYes;
if C then
begin
CL_ClearAll;
WipeObj(PCL_SlaveJob(PLinker(Linker)^.SlaveJob));
end;
ApplicationIdle := C;
end;
function LoopBreak: Boolean;
var
B: Boolean;
begin
B := TimerExpired(PLinker(Linker)^.MainTimeout) or ApplicationIdle;
if B then CL_ClearAll;
LoopBreak := B;
end;
function CL_Abort: Boolean;
var
A: Boolean;
begin
A := LinkUtil.CL_Abort;
if A then with PLinker(Linker)^ do
begin
DriveCache := 0;
WipeObj(PCL_SlaveJob(SlaveJob));
end;
CL_Abort := A;
end;
function GetDriveSet: LongInt;
var
P: PCL_InDat;
Sent: Boolean;
begin
GetDriveSet := 0; InitMainTimeOut; Sent := False;
repeat
if not CollectInData then Exit;
case Sent of
False : if CL_OutQueueFree then
begin
CL_RequestRemoteDrives;
Sent := True
end;
True : if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
if P^.Typ <> id_Drives then UnExp{Exit};
GetDriveSet := PCL_DriveData(P)^.DriveSet;
CL_InData^.AtFree(0);
Exit;
end;
end;
until LoopBreak;
end;
function NotRoot(const Dir: string): Boolean;
begin
NotRoot := Length(Dir)>3;
end;
type
PCL_DirCollection =
{$IFDEF DN} PFilesCollection {$ENDIF}
{$IFDEF NLCLIENT} PStringCollection {$ENDIF};
function GetRemoteDirCycle(DP: PByteArray; N: Word
;Owner: PObject; SortMode: Integer; CurDir: PString;
TotalInfo, FreeSpace: PString
): PCL_DirCollection;
var
nm,xt: string;
I: LongInt;
D: TCL_DirEntry;
C: PCL_DirCollection;
TFiles: Word;
Fs, Ts, TotalLen: TSize;
begin
TFiles := 0;
TotalLen := 0;
C := New(PCL_DirCollection, Init((N div 16+1)*16, 4));
{$IFDEF DN} C^.Owner := Owner; C^.SortMode := SortMode; {$ENDIF}
with PCL_DirPrefix(DP)^ do
begin
Fs := DrvFree;
if DrvFree <> -1 then Fs := Fs * 1024;
Ts := TotalLen;
Ts := Ts * 1024;
end;
if N > 0 then for I:=0 to N-1 do
begin
Move(DP^[i*CL_DirRecSz+SizeOf(TCL_DirPrefix)], D, CL_DirRecSz);
nm := CL_UnpackStr(d.Name,8);
xt := CL_UnpackStr(d.Ext,3);
if d.Attr and Directory = 0 then begin Inc(TFiles); TotalLen := TotalLen+d.Size; end;
C^.Insert(NewFileRec(nm+'.'+xt, d.Size, d.Time, d.Attr {$IFDEF DN},CurDir{$ENDIF}));
end;
if TotalInfo <> nil then TotalInfo^ := CalcTotalInfo(N, TFiles, Ts);
if (FreeSpace <> nil) and (CurDir <> nil) then
begin
if Fs = -1 then FreeSpace^ := FmtStrId(dlLinkNoRemote,Copy(CurDir^, 1, 2))
else FreeSpace^ := '~'+FStr(Fs)+GetString(dlDIFreeDisk)+Copy(CurDir^, 1, 2);
end;
GetRemoteDirCycle := C;
end;
function WaitRemoteDirData(ReqP: Pointer; ReqS: Word): PCL_PtrData;
var
P : PCL_InDat;
Sent : Boolean;
begin
WaitRemoteDirData := nil; InitMainTimeOut; Sent := False;
repeat
if not CollectInData then Exit;
case Sent of
False : if CL_OutQueueFree then
begin
CL_RequestRemoteDir(ReqP, ReqS);
Sent := True
end;
True : if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
if P^.Typ <> id_Dir then UnExp {Exit};
WaitRemoteDirData := PCL_PtrData(P);
CL_InData^.AtDelete(0);
Exit;
end;
end;
until LoopBreak;
end;
function GetRemoteDir(
Owner: PObject; SortMode: Integer;
CurDir: Pointer;
ReqP: Pointer;
ReqS: Word;
TotalInfo, FreeSpace: PString)
:PCL_DirCollection;
procedure FreeReq; begin FreeMem(ReqP, ReqS) end;
var
P: PCL_PtrData;
begin
if not WaitRemote then begin FreeReq; GetRemoteDir := nil; Exit end;
P := WaitRemoteDirData(ReqP, ReqS); FreeReq;
if P = nil then GetRemoteDir := nil else
begin
GetRemoteDir := GetRemoteDirCycle(P^.DatP, (P^.DatS-SizeOf(TCL_DirPrefix)) div CL_DirRecSz,
Owner,SortMode,CurDir,TotalInfo,FreeSpace
);
Dispose(P, Done);
end;
end;
procedure RefreshGauge(var AUpdTmr, AStrtTmr: TEventTimer; ATot, ALeft: LongInt);
var
etm, Progress: LongInt;
begin
if not TimerExpired(AUpdTmr) then Exit;
NewTimer(AUpdTmr,6);
Progress := ATot-ALeft;
WriteGrd(2, StrGrd(ATot, Progress, PLinker(Linker)^.Grd^.Size.X - 6));
etm := ElapsedTime(AStrtTmr);
WriteGrd(3, FStr(Progress)+GetString(dlBytesOf)+FStr(ATot));
if (etm>50) and (Progress>0) then SetBottom('CPS: '+ItoS((Progress*18) div etm));
end;
function ReceiveFile(const RemoteName, LocalName: string): Boolean;
var
StartRece, UpdateGauge: TEventTimer;
Sent: Boolean;
P: PCL_InDat;
Nfo: TCL_FileNfo;
Left: LongInt;
F: File;
BS: Word;
BP: Pointer;
procedure CDI;
var
S: string;
begin
S := GetPath(LocalName);
CreateDirInheritance(S, True);
end;
begin
InitMainTimeOut; ReceiveFile := False; Abort := False; Sent := False;
{$IFDEF DN}
ClrGrd(FmtFileId(dlLinkWaitFile,LocalName));
{$ENDIF}
repeat
if not CollectInData then Break;
case Sent of
False : if CL_OutQueueFree then
begin
CL_RequestFile(RemoteName);
Sent := True
end;
True : if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
case P^.Typ of
id_FileNfo : ;
id_IOstat :
begin
ReportRemoteError(PCL_InIOstat(P)^.Stat.Error);
CL_InData^.AtFree(0);
Break;
end;
else UnExp;
end;
WriteGrd(1,FmtFileId(dlLinkReceivingFile, LocalName));
Nfo := PCL_FileNfoData(P)^.Nfo;
CL_InData^.AtFree(0);
Left := Nfo.Size;
CDI; if Abort then Break;
Assign(F, LocalName); Rewrite(F, 1);
NewTimer(StartRece,0); NewTimer(UpdateGauge,0);
while Left > 0 do
begin
if not CollectInData then Break;
RefreshGauge(UpdateGauge, StartRece, Nfo.Size, Left);
if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
if P^.Typ <> id_FileBlk then UnExp;
with PCL_PtrData(P)^ do begin BP := DatP; BS := DatS end;
BlockWrite(F, BP^, BS); InitMainTimeout;
Dec(Left, BS);
CL_InData^.AtFree(0);
end else if LoopBreak then Break;
end;
ReceiveFile := Left = 0;
Close(f);
{ if ReseiveFile then Set File Date}
Break;
end;
end;
until LoopBreak;
Abort := False;
(*
{$IFDEF DN}MessageBox({$ELSE}WriteLn({$ENDIF}
'Done for '+ItoS(ElapsedTimeInSecs(StartRece))+' secs'
{$IFDEF DN},nil,mfOkButton{$ENDIF});
*)
end;
function GetLinkDiskInfo(const ADir: string): PCL_DirNfo;
var
P: PCL_InDat;
Sent: Boolean;
begin
GetLinkDiskInfo := nil;
InitMainTimeOut; Sent := False;
repeat
CollectInData;
case Sent of
False : if CL_OutQueueFree then
begin
CL_RequestRemoteDirInfo(ADir);
Sent := True
end;
True : if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
if P^.Typ <> id_DirNfo then UnExp;
GetLinkDiskInfo := PCL_PtrData(P)^.DatP;
CL_InData^.AtDelete(0);
Exit;
end;
end;
until LoopBreak;
end;
function SendFile(const FName, DestFName: string; ABuf: Pointer): Boolean;
var
StartSend, UpdateGauge: TEventTimer;
P: PCL_InDat;
Nfo: TCL_FileNfo;
L, Left: LongInt;
F: File;
BS: Word;
BP: Pointer;
function StartSending: Boolean;
var
Sent: Boolean;
begin
StartSending := False; Sent := False; InitMainTimeOut;
repeat
if not CollectInData then
Break;
case Sent of
False : if CL_OutQueueFree then
begin
CL_PostFileNfo(Nfo, DestFName);
Sent := True
end;
True : if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
if P^.Typ <> id_IOstat then
UnExp;
with PCL_InIOstat(P)^.Stat do
begin
case Status of
CL_stOK : StartSending := True;
CL_stError : ReportRemoteError(Error);
else
UnExp;
end;
end;
CL_InData^.AtFree(0);
Break;
end;
end;
until LoopBreak;
end;
function WaitEOF: Boolean;
begin
InitMainTimeout; WaitEOF := False;
repeat
if not CollectInData then Break;
if CL_InData^.Count > 0 then
begin
P := CL_InData^.At(0);
if P^.Typ <> id_IOstat then UnExp;
with PCL_InIOstat(P)^.Stat do
case Status of
CL_stOK : WaitEOF := True;
CL_stError : ReportRemoteError(Error);
else UnExp;
end;
CL_InData^.AtFree(0);
Break;
end;
until LoopBreak;
end;
function AllDone: Boolean;
begin
AllDone := False;
if Left = 0 then
begin
SendFile := WaitEOF;
AllDone := True;
end;
end;
begin
SendFile := False;
ClrIO; FileMode := $40; Assign(F, FName); Reset(F, 1); if IOResult <> 0 then Exit;
CL_FillFileNfo(F, Nfo, False); Left := Nfo.Size;
ClrGrd(FmtFileId(dlLinkTransmitFile, FName));
if not StartSending then Exit;
NewTimer(StartSend, 0); NewTimer(UpdateGauge, 0); InitMainTimeOut;
repeat
RefreshGauge(UpdateGauge, StartSend, Nfo.Size, Left);
if not CollectInData then Break;
if AllDone then Break;
if CL_FreeToFSend then
begin
L := Left; if L > CL_FileBuf then L := CL_FileBuf;
BlockRead(F, ABuf^, L); InitMainTimeout;
CL_PostFileBlock(ABuf, L);
Dec(Left, L);
if AllDone then Break;
end else if LoopBreak then Break;
until False;
Close(F);
end;
procedure TLinker.Update;
begin
CollectInData;
if TimerExpired(RefreshWndTimer) then
begin
NewTimer(RefreshWndTimer,5);
DrawView;
end;
end;
procedure CL_GetLinkDrives;
begin with PLinker(Linker)^ do begin
if not CL_Abort then
if DriveCache = 0 then DriveCache := GetDriveSet;
CL_UnpackDriveSet(DriveCache, CSet);
end end;
{---------------------------------- Drive -----------------------------------}
constructor TLinkDrive.Init;
begin
TObject.Init;
{HelpCtx := hcLinkPanel;}
Curdir := D + ':\';
DriveType := dtLink;
end;
procedure TLinkDrive.ChDir;
var Dr: DirStr;
Nm: NameStr;
Xt: ExtStr;
begin
if ADir = #0 then Exit;
FSplit(ADir, Dr, Nm, Xt);
if Xt = '..' then
begin
if Dr <> '' then CurDir := Dr;
if CurDir[1] <> '\' then Insert('\', CurDir, 1);
repeat Dec(CurDir[0]) until (CurDir = '') or (CurDir[Length(CurDir)] = '\');
if CurDir <> '' then Dec(CurDir[0]);
end else CurDir := ADir;
While (CurDir[0] > #3) and (PosChar(CurDir[Length(CurDir)], ' .\') > 0) do Dec(CurDir[0]);
end;
function TLinkDrive.GetDir;
begin
GetDir := cLINK_+CurDir;
end;
procedure CreateDirRequest(
var P: Pointer;
var Ofst: Word;
const CurDir: PathStr;
const FileMask: string;
APanelFlags, ASortMode: Integer);
var
S: string;
R: TCL_DirReq;
sl1, fl1: Byte;
procedure Mve(const Buf; Size: Word);
begin Move(Buf, PByteArray(P)^[Ofst], Size); Inc(Ofst, Size) end;
begin
Ofst := 0;
S := MakeNormName(CurDir, '');
sl1 := Length(S)+1; fl1 := Length(FileMask)+1;
GetMem(P, SizeOf(TCL_DirReq)+sl1+fl1);
R.PanelFlags := APanelFlags;
R.SortMode := ASortMode;
Mve(R, SizeOf(R));
Mve(S, sl1);
Mve(FileMask, fl1);
end;
function TLinkDrive.GetDirectory;
var
Ofst: Word;
P: Pointer;
var
PC: PFilesCollection;
begin
FreeSpace := ''; TotalInfo := '';
CreateDirRequest(P, Ofst, CurDir, FileMask, PanelFlags, SortMode);
if WaitRemote then PC := GetRemoteDir(Owner, SortMode, @CurDir, P, Ofst, @TotalInfo, @FreeSpace)
else PC := nil;
if PC = nil then
begin
{PC := New(PFilesCollection, Init(0, 0));}
FreeSpace := FmtStrId(dlLinkNoRemote, Copy(CurDir, 1, 2));
end {else
begin
if NotRoot(CurDir) then PC^.AtInsert(0, NewFileRec('..',0,0,Directory,@CurDir));
end};
GetDirectory := PC;
end;
procedure TLinkDrive.RereadDirectory;
begin
if Prev <> nil then Prev^.RereadDirectory(S);
end;
procedure TLinkDrive.CopyFilesInto;
begin
{CopyToLinkDrive(AFiles,Own,CurDir,'');}
end;
function MkName(Nm: Str12; const Mask: Str12): Str12;
var I: Integer;
begin
for I := 1 to 12 do if Mask[I] <> '?' then Nm[I] := Mask[I];
Nm[9] := '.';
MkName := MakeFileName(Nm);
end;
function ValidRemoteDir(const ADir: string; var IsValid: Boolean): Boolean;
var
P: PCL_InDat;
Sent: Boolean;
begin
ValidRemoteDir := False; InitMainTimeOut; Sent := False;
repeat
if not CollectInData then Exit;
case Sent of
False : if CL_OutQueueFree then