วันนี้ฉันเห็นโพสต์ใน S8S8 สคริปต์เชลล์, ภาษา C, C ++, VBS, PHP, Perl, Java และ C#, มันเป็นความตั้งใจ แต่หลังจากอ่านภาพถ่ายสองสามภาพพวกเขาทั้งหมดไม่เหมาะสำหรับเด็ก ๆ
รหัสโปรแกรมที่สมบูรณ์:
// การเขียนค่อนข้างหยาบ แต่โดยทั่วไปสามารถตระหนักถึงฟังก์ชั่นการดาวน์โหลดดังนั้นฉันจึงไม่สามารถควบคุมได้มากนัก
หน่วย getmm;
ส่วนต่อประสาน
ใช้
Windows, ข้อความ, sysutils, ตัวแปร, คลาส, กราฟิก, การควบคุม, รูปแบบ,
กล่องโต้ตอบ, stdctrls, idbasecomponent, idComponent, idtcpconnection,
IDTCPClient, IDHTTP;
const
url = 'http: //www.sergeaura.net/tgp/';
Offi = 192;
Offj = 16;
girlpic = 'c:/girlpic/';
// คลาสเธรด
พิมพ์
tgetmm = คลาส (tthread)
ได้รับการคุ้มครอง
fmmurl: สตริง;
fdestpath: สตริง;
fsubj: สตริง;
ขั้นตอนดำเนินการ; แทนที่;
สาธารณะ
ตัวสร้างสร้าง (mmurl, destpath, subj: string);
จบ;
พิมพ์
tform1 = คลาส (tform)
ปุ่ม 1: tbutton;
button2: tbutton;
memo1: tmemo;
IDHTTP1: TIDHTTP;
CheckBox1: tcheckbox;
ขั้นตอน button1click (ผู้ส่ง: tobject);
ขั้นตอน button2click (ผู้ส่ง: tobject);
ส่วนตัว
{ประกาศส่วนตัว}
rgetmm: tthread;
ขั้นตอน getMMTHREAD (MMURL, DESTPATH, SUBJ: String);
สาธารณะ
{ประกาศสาธารณะ}
จบ;
วาจา
Form1: TFORM1;
การดำเนินการ
{$ r *.dfm}
// กระบวนการดาวน์โหลด
ขั้นตอน tform1.button1click (ผู้ส่ง: tobject);
วาจา
ฉัน, J: จำนวนเต็ม;
subi, subj, cururl, destpath: string;
Strm: TMemorystream;
เริ่ม
memo1.lines.clear;
// สร้างไดเรกทอรี
ถ้าไม่ได้มีไดเรกทอรี (Girlpic) แล้ว
Mkdir (Girlpic);
พยายาม
strm: = tmemorystream.create;
สำหรับ i: = 1 ถึง Offi Do
เริ่ม
สำหรับ J: = 1 ถึง Offj Do
เริ่ม
ถ้า (i <10) แล้ว
subi: = '00'+inttoStr (i)
อื่นถ้า (i> 9) และ (i <100) แล้ว
subi: = '0'+inttoStr (i)
อื่น subi: = inttoStr (i);
ถ้า (j> 9) แล้ว
subj: = inttoStr (j)
อื่น subj: = '0'+inttostr (j);
cururl: = url+subi+'/images/';
destpath: = girlpic+subi+'/';
ถ้าไม่ได้มีไดเรกทอรี (destpath) แล้ว
Forcedirectories (Destpath);
// ใช้เธรดความเร็วสามารถเพิ่มขึ้นได้มากกว่า n ครั้ง
ถ้าช่องทำเครื่องหมายที่ตรวจสอบแล้ว
เริ่ม
getMMTHREAD (CURURL, DESTPATH, SUBJ);
นอนหลับ (500);
จบสิ้น
// ไม่มีการใช้เธรด
เริ่ม
พยายาม
strm.clear;
idhttp1.get (cururl+subj+'. jpg', strm);
strm.savetofile (destpath+subj+'. jpg');
memo1.lines.add (cururl+'ดาวน์โหลดตกลง!');
strm.clear;
idhttp1.get (cururl+'tn _'+subj+'. jpg', strm);
strm.savetofile (destpath+'tn _'+subj+'. jpg');
memo1.lines.add (cururl+'ดาวน์โหลดตกลง!');
ยกเว้น
memo1.lines.add (cururl+'ข้อผิดพลาดดาวน์โหลด!');
จบ;
จบ;
จบ;
จบ;
memo1.lines.add ('ทั้งหมดตกลง!');
ในที่สุด
strm.free;
จบ;
จบ;
ขั้นตอน TFORM1.Button2Click (ผู้ส่ง: TOBJECT);
เริ่ม
ปิด;
จบ;
{tgetmm}
constructor tgetmm.create (mmurl, destpath, subj: string);
เริ่ม
fmmurl: = mmurl;
fdestpath: = destpath;
fsubj: = subj;
สืบทอดมาสร้าง (เท็จ);
จบ;
ขั้นตอน tgetmm.execute;
วาจา
Strm: TMemorystream;
idgetmm: tidhttp;
DestFile: String;
เริ่ม
พยายาม
strm: = tmemorystream.create;
idgetMm: = tidhttp.create (ไม่มี);
พยายาม
destFile: = fdestpath+fsubj+'. jpg';
ถ้าไม่ใช่ fileexists (destFile) แล้ว
เริ่ม
strm.clear;
idgetmm.get (fmmurl+fsubj+'. jpg', strm);
strm.savetofile (destfile);
จบ;
destFile: = fdestpath+'tn _'+fsubj+'. jpg';
ถ้าไม่ใช่ fileexists (destFile) แล้ว
เริ่ม
strm.clear;
idgetmm.get (fmmurl+'tn _'+fsubj+'. jpg', strm);
strm.savetofile (destfile);
จบ;
ยกเว้น
จบ;
ในที่สุด
strm.free;
idgetmm.free;
จบ;
จบ;
ขั้นตอน tform1.getmmthread (mmurl, destpath, subj: string);
เริ่ม
rgetmm: = tgetmm.create (mmurl, destpath, subj);
จบ;
จบ.