procedure TDownload.Execute;
var FS:TFileStream;
slTime,elTime:TDateTime;
fail:Boolean;
Leechedsize,Filesize:int64;
begin
http := TidHTTP.Create;
dir := appdir + '
data/download/';
FOrm1.p_download.Caption := '
Action: Trying ' + rls;
Form1.lv_download.Items.Add.Caption := TITLE;
gitem := Form1.lv_download.Items.Count-1;
if DirectoryExists(dir)
then
begin
Form1.lv_download.Items[gitem].SubItems.Add('
Already Exists');
end
else
begin
Form1.p_download.Caption := '
Action: Start Downloading ' + rls;
Form1.lv_download.Items[gitem].SubItems.Add('
Downloading');
slTime := now;
FS:=Tfilestream.Create(dir + '
/' + TITLE,fmCreate);
fail := False;
leechedsize := 0;
http.Head(
URL);
filesize := http.Response.ContentLength;
Form1.lv_download.Items[gitem].SubItems[0] := '
Downloading ('+GetSizeName(leechedsize)+'
/'+GetSizeName(filesize)+'
)';
repeat
if (filesize-leechedsize) > cFileSplitSize
then
Http.Request.Range := Format('
%d-%d', [leechedsize, (leechedsize+cFileSplitSize-1)])
else
Http.Request.Range := Format('
%d-', [leechedsize]);
try
HTTP.Get(
URL,FS);
except
fail := True;
end;
Form1.lv_download.Items[gitem].SubItems[0] := '
Downloading ('+GetSizeName(leechedsize)+'
/'+GetSizeName(filesize)+'
)';
leechedsize := leechedsize+cFileSplitSize;
until (leechedsize >= filesize);
elTime := now - slTime;
if fail
then
Form1.lv_download.Items[gitem].SubItems[0] := '
Download Failed'
else
Form1.lv_download.Items[gitem].SubItems[0] := '
Finished ('+FormatDateTime('
hh:mm:ss',elTime)+'
)';
Form1.p_download.Caption := '
Action: Finished ' + rls;
end;
http.free;
Inc(Form1.CurThreads,-1);
end;