Код:
function GetInetFileSize(const FileUrl:string): integer;
var
idHTTP: TidHTTP;
begin
Try
Result:=0;
idHTTP:=TIdHTTP.Create(nil);
idHTTP.Head(FileUrl);
Result:=idHTTP.Response.ContentLength;
IdHTTP.Free;
Except
Result:=0;
Exit;
End;
end;
Код:
const BufferSize = 1024;
var hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
OpSize,OpSizeAll:Int64;
FileNameTemp:String;
FileNameTemp:=Converter('%Temp%\'+Random(8)+'.tmp');
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
try
hURL := InternetOpenURL(hSession,
PChar(fileURL),nil,0,0,0);
try
AssignFile(f, FileNameTemp);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen);
OpSize:=OpSize+BufferLen;
FormProgress.ProgressBar1.Position:=(OpSize*100) div OpSizeAll;
Application.ProcessMessages;
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL);
end;
finally
InternetCloseHandle(hSession);
FormProgress.ProgressBar1.Visible:=False;
end;