как в функцию GetUrlSize замастрячить скорость скачивания?
не хватает ума в математике.
Помогите решить проблему.
function THTTPDD.GetUrlSize(const URL:string):integer;
var
hSession,hFile:hInternet;
dwBuffer:array[1..20] of char;
dwBufferLen,dwIndex:DWORD;
begin
Result:=0;
hSession:=InternetOpen('GetUrlSize',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
if Assigned(hSession) then
begin
hFile:=InternetOpenURL(hSession,PChar(URL),nil,0,INTERNET_FLAG_RELOAD,0);
dwIndex:=0;
dwBufferLen:=20;
if HttpQueryInfo(hFile,HTTP_QUERY_CONTENT_LENGTH,@dwBuffer,dwBufferLen,dwIndex) then Result:=StrToInt(StrPas(@dwBuffer));
if Assigned(hFile) then InternetCloseHandle(hFile);
InternetCloseHandle(hsession);
end;
end;
function THTTPDD.GetInetFile(const fileURL, FileName: string; Pbar:TProgressBar): boolean;
const
BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: file;
fsize,tmpsz,sp,pp:integer;
sAppName: string;
pause:boolean;
begin
TRY
pause:=false;
form1.ProgressCurrentFile.Visible:=true;
form1.sLabel1.Visible:=true;
Result:=False;
fsize:=GetUrlSize(fileURL);
form1.FileSizeLabel.Caption:='Ðàçìåð ôàéëà: '+inttostr(fsize div 1024)+' Kb';
tmpsz:=0;
sp:=fsize div 100;
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
hURL := InternetOpenURL(hSession,PChar(fileURL),nil,0,0,0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
if pause then
repeat
until not pause else
begin
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen);
tmpsz:=tmpsz+BufferLen;
pp:=tmpsz div sp;
if pp>100 then pp:=0;
Pbar.Position:=pp;
form1.DownloadedLabel.Caption:='Загружено: '+inttostr(pp)+' %';
end;
until
BufferLen = 0;
form1.UpdateFileName.Caption:='';
form1.FileSizeLabel.Caption:='';
form1.DownloadedLabel.Caption:='';
form1.ProgressCurrentFile.Visible:=false;
form1.sLabel1.Visible:=false;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end;
finally
InternetCloseHandle(hSession)
end;
EXCEPT END;
end;