-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqDccGet.pas
More file actions
197 lines (173 loc) · 4.66 KB
/
qDccGet.pas
File metadata and controls
197 lines (173 loc) · 4.66 KB
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
unit qDccGet;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, Gauges, WSocket, StdCtrls, Buttons,
ExtCtrls;
type
TDccGet = class(TForm)
Close: TBitBtn;
Label1: TLabel;
Filename: TLabel;
Size: TLabel;
Label2: TLabel;
Label5: TLabel;
Received: TLabel;
Label3: TLabel;
Timeleft: TLabel;
Status: TLabel;
Label4: TLabel;
WSocket1: TWSocket;
Percent: TGauge;
Timer1: TTimer;
Timer2: TTimer;
CPS: TLabel;
procedure WndProc(var Message: TMessage); override;
procedure ChangeColor(Sender: TObject; Msg: Integer);
procedure GetFile(Nick, Fle, Host: String; Port: Integer; Size: Cardinal);
procedure WSocket1SessionConnected(Sender: TObject; Error: Word);
procedure WSocket1SessionClosed(Sender: TObject; Error: Word);
procedure FormCreate(Sender: TObject);
procedure WSocket1DataAvailable(Sender: TObject; Error: Word);
procedure Send(A: String);
procedure CloseClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Timer2Timer(Sender: TObject);
function Avg: Integer;
private
public
AmountGot, OldAmount: Cardinal;
F: File Of Char;
DeCPS: Array[1..10] Of Integer;
DePos: Byte;
DeTimeOut: Byte;
end;
var
DccGet: TDccGet;
implementation
{$R *.DFM}
procedure TDccGet.GetFile(Nick, Fle, Host: String; Port: Integer; Size: Cardinal);
begin
Self.Caption := 'DCC From ' + Nick;
Fle := ExtractFileName(Fle);
AssignFile(F, 'C:\' + Fle);
Rewrite(F);
Self.Size.Caption := IntToStr(Size);
Self.Filename.Caption := Fle;
Self.Status.Caption := 'Connecting to remote host.';
WSocket1.Addr := Host;
WSocket1.Port := IntToStr(Port);
WSocket1.Connect;
end;
procedure TDccGet.WndProc(var Message : TMessage);
begin
If (Message.LParam = LongInt(Close)) Then
ChangeColor(Close, Message.Msg);
Inherited WndProc(Message);
end;
procedure TDccGet.ChangeColor(Sender : TObject; Msg : Integer);
Begin
If (Sender Is TBitBtn) Then Begin
If (Msg = CM_MOUSELEAVE) Then
(Sender As TBitBtn).Font.Color := clWindowText;
If (Msg = CM_MOUSEENTER) Then Begin
(Sender As TBitBtn).Font.Color := clRed;
End;
End;
End;
procedure TDccGet.WSocket1SessionConnected(Sender: TObject; Error: Word);
begin
Self.Status.Caption := 'Session established!';
Timer2.Enabled := True;
end;
procedure TDccGet.WSocket1SessionClosed(Sender: TObject; Error: Word);
begin
If (AmountGot = StrToInt(Self.Size.Caption)) Then Begin
Self.Status.Caption := 'File transfer complete!';
End Else
Self.Status.Caption := 'File transfer error!';
CloseFile(F);
Timer1.Enabled := True;
AmountGot := 0;
Timer2.Enabled := False;
end;
procedure TDccGet.FormCreate(Sender: TObject);
begin
Self.AmountGot := 0;
DePos := 0;
DeTimeOut := 0;
end;
procedure TDccGet.WSocket1DataAvailable(Sender: TObject; Error: Word);
var
S: String;
G, K: Array[1..4] of Char;
I: Integer;
begin
S := WSocket1.ReceiveStr;
If (Length(S) = 0) Then Exit;
OldAmount := AmountGot;
For I := 1 To Length(S) Do Begin
Write(F, S[I]);
Inc(AmountGot);
End;
Self.Percent.Progress := Trunc((AmountGot / StrToInt(Self.Size.Caption)) * 100);
Self.Received.Caption := IntToStr(AmountGot);
Move(AmountGot, G, SizeOf(Cardinal));
K[1] := G[4];
K[2] := G[3];
K[3] := G[2];
K[4] := G[1];
Self.Send(K);
DeTimeOut := 0;
DeCPS[DePos] := AmountGot - OldAmount;
Self.CPS.Caption := IntToStr(Avg);
Application.ProcessMessages;
end;
procedure TDccGet.Send(A: String);
begin
If (WSocket1.State = wsConnected) Then
WSocket1.SendStr(A);
end;
procedure TDccGet.CloseClick(Sender: TObject);
begin
WSocket1.Close;
CloseFile(F);
Self.Release;
end;
procedure TDccGet.Timer1Timer(Sender: TObject);
begin
If (AmountGot = 5) Then
Self.Status.Caption := 'Closing in 5 secs...';
If (AmountGot = 10) Then Begin
WSocket1.Close;
Self.Release;
End;
Inc(AmountGot);
end;
procedure TDccGet.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := False;
end;
procedure TDccGet.Timer2Timer(Sender: TObject);
var
I: Integer;
begin
Inc(DePos);
Inc(DeTimeOut);
If (DePos = 11) Then DePos := 1;
I := DePos + 1;
If (I = 11) Then I := 1;
If (DeTimeOut > 1) Then
DeCPS[I] := 0;
end;
function TDccGet.Avg: Integer;
var
I, Amt: Integer;
begin
Amt := 0;
For I := 1 To 10 Do
Inc(Amt, DeCPS[I]);
Result := Amt Div 10;
end;
end.