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
|
procedure TUploadThread.Execute;
begin
if not Connexion then exit;
if not Upload then exit;
DeConnexion;
end;
procedure TUploadThread.callOnPacketSent();
begin
if Assigned(fOnPacketSent)then
begin
fOnPacketSent(LenSent,LenTot)
end;
end;
function TUploadThread.Upload():boolean;
var
temp,chaineIconv:string;
code3:string;
LenToSend:integer;
begin
result := false;
fStream.LoadFromFile(ffileSrc);
temp := TRAME_UPLOAD_THREAD;
CnvA2E(temp);
chaineIconv := temp+ ShortToString(length(fFileDest));
temp := fFileDest;
cnvA2E(temp);
chaineIconv := chaineIconv + temp;
fTcpClient.Sendln(chaineIconv,'');
code3 := receptionAlpha(fTcpClient,3);
if(Code3 =TRAME_MESSAGE_ERREUR)then
begin
if assigned(fOnErrorUpload)then
begin
fOnErrorUpload(teFileName);
end;
exit;
end;
result := true;
LenSent := 0;
fStream.Seek(0,soFromBeginning);
LenTot := fStream.Size;
while(LenSent < LenTot)do
begin
LenToSend := fStream.Size - LenSent;
if(LenToSend) > fPacketSize then
begin
LenToSend := fPacketSize;
end;
SetString(temp,nil,lenToSend);
fStream.Read(temp[1],lenToSend);
chaineIconv := #1 + inttostring(LenToSend) +temp;
fTcpClient.Sendln(chaineIConv,'');
LenSent := LenSent + LenToSend;
code3 := receptionAlpha(fTcpClient,3);
if(Code3 =TRAME_MESSAGE_ERREUR)then
begin
if assigned(fOnErrorUpload)then
begin
fOnErrorUpload(teWrite);
end;
exit;
end;
Synchronize(callOnPacketSent);
if(fToStop)then
begin
chaineIconv := #0;
fTcpClient.Sendln(chaineIConv,'');
receptionAlpha(fTcpClient,3);
end;
end;
chaineIconv := #0;
fTcpClient.Sendln(chaineIConv,'');
code3 := receptionAlpha(fTcpClient,3);
if(Code3 =TRAME_MESSAGE_ERREUR)then
begin
if assigned(fOnErrorUpload)then
begin
fOnErrorUpload(teSync);
end;
exit;
end;
Synchronize(callOnEndUpload);
end;
//fonction appelée dans l'evenement onPacketSent
procedure TFormDesigner.MySent(sent:integer;Total:integer);
begin
Label1.Caption := inttostr(sent)+'/'+inttostr(total);
ProgressBar1.Max := total;
ProgressBar1.Position := sent;
end; |
Partager