procedure TmhThread.WorkonPart;
var
i,Start,Total:longint;
hFindFile: THandle;
FindFileData: WIN32_FIND_DATA;
Str,mhpicpath:string;
begin
for i:=PartTot downto 1 do
begin
if (DirectoryExists(PartName[i]+'\')) and
(not FileExists(PartName[i]+'\'+PartURL[i])) and
(FileExists(PartName[i]+'\000.jpg'))
then begin
hFindFile := FindFirstFile(pchar(IncludeTrailingPathDelimiter(PartName[i])+'*.*'),
FindFileData);
if hFindFile <> 0 then begin
repeat
Str:=FindFileData.cFileName;
if (Str='.') or (Str='..') then continue;
EnterCriticalSection(CSforMark); try
Mark:=Mark+1;
finally LeaveCriticalSection(CSforMark); end;
until FindNextFile(hFindFile, FindFileData) = false;
windows.FindClose(hFindFile);
continue;
end;
end;
CreateDir(PartName[i]);
Chdir(PartName[i]);
if not FileExists('000.jpg')
then HtmlDownload(mhURL+'/'+PartURL[i],PartURL[i]);
AssignFile(Input,PartURL[i]);
Reset(Input);
Start:=0; Total:=0;
while not eof(Input) do
begin
readln(Input,Str);
if pos(S5,Str)<>0
then begin
delete(Str,1,pos(S5,Str)+length(S5)-1);
mhpicpath:=copy(Str,1,pos('"',Str)-1);
end;
if pos(S6,Str)<>0
then begin
delete(Str,1,pos(S6,Str)+length(S6)-1);
start:=strtoint(copy(Str,1,pos('<',Str)-1));
end;
if pos(S7,Str)<>0
then begin
delete(Str,1,pos(S7,Str)+length(S7)-1);
total:=strtoint(copy(Str,1,pos('<',Str)-1));
end;
end;
PicDownload(mhpicpath,Start,total);
CloseFile(Input);
DeleteFile(PartURL[i]);
chdir('..');
end;
end;
procedure TForm1.CanvasInitialize;
begin
Edit1.Visible:=False;
Image1.Visible:=true;
Image1.Canvas.Lock;
Image1.Canvas.Pen.Width:=0;
Image1.Canvas.Pen.Color:=Form1.Color;
Image1.Canvas.Brush.Color:=Form1.Color;
Image1.Canvas.Rectangle(-1,-1,Image1.Width+1,Image1.Height+1);
Image1.Canvas.Pen.Color:=$00ffffff;
Image1.Canvas.Roundrect(0,0,Image1.Width,Image1.Height,Image1.Height,Image1.Height div 2);
Image1.Canvas.Unlock;
end;
procedure TForm1.DrawProgressBar;
var
tmpMark,tmpMax:Longint;
begin
EnterCriticalSection(CSforMark);
EnterCriticalSection(CSforMax); try
tmpMark:=Mark;
tmpMax:=Max;
finally LeaveCriticalSection(CSforMark);
LeaveCriticalSection(CSforMax); end;
Image1.Canvas.Lock;
Image1.Canvas.Brush.Color:=$00ffffff;
Image1.Canvas.Roundrect(0,0,Image1.Width,Image1.Height,Image1.Height,Image1.Height div 2);
Image1.Canvas.Brush.Color:=$00ffD500;
Image1.Canvas.Roundrect(0,0,round(tmpMark*Image1.Width/tmpMax),Image1.Height,Image1.Height,Image1.Height div 2);
Image1.Canvas.Unlock;
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=13
then begin
with TmhThread.Create(TRUE) do
begin
FreeonTerminate:=true;
mhURL:=Edit1.Text;
Resume;
end;
CanvasInitialize;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
DrawProgressBar;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Halt;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitializeCriticalSection(CSforMark);
InitializeCriticalSection(CSforThreadTot);
InitializeCriticalSection(CSforMax);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteCriticalSection(CSforMark);
DeleteCriticalSection(CSforThreadTot);
DeleteCriticalSection(CSforMax);
end;
end.
2014年04月30日 04点04分
10