Blood_Magic » 20 мар 2007, 12:21
Код: Выделить всё
var hSession: HINTERNET; hService: HINTERNET; lpBuffer: array[0..1024] of Char; dwBytesRead: DWORD; dwIndex :D WORD; f:file;begin NoError:=False; CurDownload:=0; TotalDownload:=0; hSession:=InternetOpen('Microsoft Internet Explorer', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); try if Assigned(hSession) then begin dwBytesRead:=1024; hService:=InternetOpenUrl(hSession, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0); if Assigned(hService) then try dwIndex:=0; dwBytesRead:=1024; If HttpQueryInfo(hService,HTTP_QUERY_CONTENT_LENGTH,@lpBuffer,dwBytesRead,dwIndex) then TotalDownload:=StrToInt(StrPas(@lpBuffer)) else TotalDownload:=0; If not flGetSize then begin AssignFile(f,FileName); {$I-}ReWrite(f,1){$I+}; If IOResult=0 then begin While not (Terminated or Application.Terminated) do begin dwBytesRead:=1024; InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead); If dwBytesRead = 0 then break; BlockWrite(f,lpBuffer,dwBytesRead); Inc(CurDownload,dwBytesRead); end; CloseFile(f); If Terminated then DeleteFile(FileName); end else MessageBox(0,PChar('Не удалось создать файл. Возможно у вас нет прав. Попробуйте перезагрузить компьютер и повторить попытку!'#0),'Ошибка',MB_OK or MB_ICONERROR or MB_APPLMODAL); end; NoError:=True; finally InternetCloseHandle(hService); end; end; finally InternetCloseHandle(hSession); end;
[code]var hSession: HINTERNET; hService: HINTERNET; lpBuffer: array[0..1024] of Char; dwBytesRead: DWORD; dwIndex :D WORD; f:file;begin NoError:=False; CurDownload:=0; TotalDownload:=0; hSession:=InternetOpen('Microsoft Internet Explorer', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); try if Assigned(hSession) then begin dwBytesRead:=1024; hService:=InternetOpenUrl(hSession, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0); if Assigned(hService) then try dwIndex:=0; dwBytesRead:=1024; If HttpQueryInfo(hService,HTTP_QUERY_CONTENT_LENGTH,@lpBuffer,dwBytesRead,dwIndex) then TotalDownload:=StrToInt(StrPas(@lpBuffer)) else TotalDownload:=0; If not flGetSize then begin AssignFile(f,FileName); {$I-}ReWrite(f,1){$I+}; If IOResult=0 then begin While not (Terminated or Application.Terminated) do begin dwBytesRead:=1024; InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead); If dwBytesRead = 0 then break; BlockWrite(f,lpBuffer,dwBytesRead); Inc(CurDownload,dwBytesRead); end; CloseFile(f); If Terminated then DeleteFile(FileName); end else MessageBox(0,PChar('Не удалось создать файл. Возможно у вас нет прав. Попробуйте перезагрузить компьютер и повторить попытку!'#0),'Ошибка',MB_OK or MB_ICONERROR or MB_APPLMODAL); end; NoError:=True; finally InternetCloseHandle(hService); end; end; finally InternetCloseHandle(hSession); end;[/code]