-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
2235 lines (1634 loc) · 77.8 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Threading;
using System.Net;
namespace Pixivworm
{
public partial class Form1 : Form
{
// public HttpToolClass httptoll = new HttpToolClass();
public static Thread Thread1;//线程的声明辅助线程
public delegate void UpdateView(prop x);//委托的申明
public UpdateView UpdateV, errordanger;
public struct prop
{
public int pro1max;
public int pro1value;
public int pro2max;
public int pro2value;
public string text;
}
public Form1()
{
InitializeComponent();
}
/// <summary>
/// morelist 多图图片下载地址url合集
/// </summary>
ArrayList morelist = new ArrayList();
/// <summary>
/// orglist 单张图片下载地址url合集
/// </summary>
ArrayList orglist = new ArrayList();
/// <summary>
/// giflist 动态图片zip下载地址url合集
/// </summary>
ArrayList giflist = new ArrayList();
/// <summary>
/// morelisterr 多图图片下载地址url失败合集
/// </summary>
ArrayList morelisterr = new ArrayList();
/// <summary>
/// orglisterr 单张图片下载地址url失败合集
/// </summary>
ArrayList orglisterr = new ArrayList();
/// <summary>
/// giflisterr 动态图片zip下载地址url失败合集
/// </summary>
ArrayList giflisterr = new ArrayList();
/// <summary>
/// morelistname 多图图片 图片名称合集
/// </summary>
ArrayList morelistname = new ArrayList();
/// <summary>
/// orglistname 单张图片 图片名称合集
/// </summary>
ArrayList orglistname = new ArrayList();
/// <summary>
/// gifname 动态图片zip 图片名称合集
/// </summary>
ArrayList gifname = new ArrayList();
/// <summary>
/// 头文件信息
/// </summary>
HttpHeader header = new HttpHeader();
/// <summary>
/// 用来更新UI的结构体
/// 包括progress1的最大值,当前值
/// 包括textbox的当前信息的显示
/// </summary>
prop pr = new prop();
/*-正则相关初始化-*/
Regex reg;
Match match;
/*-lock锁定义-*/
Object locker = new Object();
/*-线程池中单独线程状态计数-*/
/// <summary>
/// 线程池中单独分析图片url线程状态计数
/// </summary>
CountdownEvent handler;
/// <summary>
/// 线程池中图片下载url线程状态计数
/// </summary>
CountdownEvent handler2img;
/*-初始化-*/
/// <summary>
/// P站作者ID
/// </summary>
public String textb1 = "";
/// <summary>
/// 文件保存地址
/// </summary>
public String textblogin = "";
/// <summary>
/// 作者ID图文件保存地址
/// </summary>
public String savename = "NOName";
/// <summary>
/// 登录ID
/// </summary>
public String loginID = "";
/// <summary>
/// 登录密码
/// </summary>
public String loginpassword = "";
/// <summary>
/// 工作线程
/// </summary>
public int workerthread = 5;
/// <summary>
/// IO线程
/// </summary>
public int iothread = 5;
/// <summary>
/// 超时
/// </summary>
// public int timeout = 30000;
/// <summary>
/// 是否自动下载
/// </summary>
public int autodownload = 0;
/// <summary>
/// 重试次数
/// </summary>
public int retry = 5;
/// <summary>
/// 去掉文件夹中的非法字符
/// </summary>
/// <param name="filename">去除前filename</param>
/// <returns>去除后filename</returns>
private string filename(string filename)
{
string str = filename;
str = str.Replace("\\", string.Empty);
str = str.Replace("/", string.Empty);
str = str.Replace(":", string.Empty);
str = str.Replace("*", string.Empty);
str = str.Replace("?", string.Empty);
str = str.Replace("\"", string.Empty);
str = str.Replace("<", string.Empty);
str = str.Replace(">", string.Empty);
str = str.Replace("|", string.Empty);
str = str.Replace(" ", string.Empty);
return str;
}
/// <summary>
/// 正则表达式 返回解析后的match
/// 减少代码量
/// </summary>
/// <param name="regex">正则表达式</param>
/// <param name="str">需要解析的string</param>
/// <returns>解析后的match</returns>
private Match regexmatch(String regex,String str)
{
Regex reg = new Regex(regex);
Match match = reg.Match(Convert.ToString(str).ToString());
return match;
}
/// <summary>
/// 判断每个作品的作品类型
/// 单张大图
/// 多张
/// 动态
/// </summary>
/// <param name="piclist">每个作品的作品类型url合集中的位置[] 由object转int arraylist[x]</param>
private void httpgetpageimg(object piclist)
{
bool getloop=false;
int strp = 0;
do{
try
{
/*----------判断是否为静态图-----------*/
HttpToolClass httptoll = new HttpToolClass();
ArrayList must2 = httptoll.sqlliistGet("http://www.pixiv.net" + piclist.ToString(), "", header);
Match orgpicmatch = regexmatch(@"img\salt=""(.*?)""(.*?)data-src=""(.*?)""(.*?)>", Convert.ToString(must2[0]));
if (orgpicmatch.Groups[0].Value == "")
{
/*----------判断是否为多图-----------*/
string morlistfilename = regexmatch(@"</ul><h1\sclass=""title"">(.*?)</h1><", Convert.ToString(must2[0]).ToString()).Groups[1].ToString();
Match matchmorpic = regexmatch(@"mode=manga(.*?)""", Convert.ToString(must2[0]).ToString());
string urllist = matchmorpic.Groups[0].Value.Replace(@"""", "");
if (urllist != "")
{
urllist = urllist.Replace(@"amp;", "");
ArrayList morepiclist = new ArrayList();
morepiclist.Add(httptoll.sqlliistGet("http://www.pixiv.net/member_illust.php?" + urllist, "", header)[0].ToString());
int lop = 0;
Match match = regexmatch(@"data-filter=""(.*?)""\sdata-src=""(.*?)""", Convert.ToString(morepiclist[0]).ToString());
if (match.Success)
{
match = regexmatch(@"</script><a\shref=""(.*?)"" target=""(.*?)"" class=""(.*?)>", Convert.ToString(morepiclist[0]).ToString());
while (match.Success)
{
urllist = match.Groups[1].Value.Replace(@"""", "");
urllist = urllist.Replace(@"amp;", "");
ArrayList morepiclistorg = new ArrayList();
morepiclistorg.Add(httptoll.sqlliistGet("http://www.pixiv.net" + urllist, "", header)[0].ToString());
Match match2 = regexmatch(@"<body><img src=""(.*?)""", Convert.ToString(morepiclistorg[0]).ToString());
if (match2.Success)
{
lock (locker)
{
morelist.Add(match2.Groups[1].ToString());
morelistname.Add(morlistfilename + "\\" + match2.Groups[1].ToString() + lop);
lop++;
}
pr.text = pr.text + "\r\n" + match2.Groups[1].ToString();
this.BeginInvoke(UpdateV, pr);
}
else
{
this.BeginInvoke(new MethodInvoker(delegate
{
MessageBox.Show("链接:http://www.pixiv.net" + urllist + "无法解析");
}));
}
match = match.NextMatch();
}
}
else
{
/*----------尝试配置漫画模式多图-----------*/
match = regexmatch(@"pixiv.context.originalImages(.*?) = ""(.*?)""", Convert.ToString(morepiclist[0]).ToString());
if (match.Success)
{
while (match.Success)
{
lock (locker)
{
string comicopicurl = match.Groups[2].ToString().Replace(@"/", "");
comicopicurl = comicopicurl.Replace("\\", "/");
morelist.Add(comicopicurl);
morelistname.Add(morlistfilename + "\\" + comicopicurl + lop);
}
match = match.NextMatch();
lop++;
pr.text = pr.text + "\r\n" + match.Groups[2].ToString();
this.BeginInvoke(UpdateV, pr);
}
}
else
{
this.BeginInvoke(new MethodInvoker(delegate
{
MessageBox.Show("链接:http://www.pixiv.net" + piclist.ToString() + "无法解析");
}));
}
}
}
else
{
/*----------判断是否为动态图-----------*/
if (regexmatch(@"ugoku-illust-player-container", Convert.ToString(must2[0]).ToString()).Groups[0].Value != "")
{
lock (locker)
{
giflist.Add(regexmatch(@"ugokuIllustFullscreenData\s\s=\s{""src"":""(.*?)"",", Convert.ToString(must2[0]).ToString().Replace(@"\", "")).Groups[1].Value);
gifname.Add(morlistfilename + "\\");
}
}
else
{
/*----------判断是否为big图-----------*/
string bigpic = regexmatch(@"mode=big(.*?)""", Convert.ToString(must2[0]).ToString()).Groups[0].Value;
if (bigpic != "")
{
lock (locker)
{
CookieClass cookieClass = CookieClass.Instance;
bigpic = bigpic.Replace(@"amp;", "");
bigpic = bigpic.Replace(@"""", "");
ArrayList morepiclist = new ArrayList();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.pixiv.net/member_illust.php?" + bigpic);
ArrayList arrayListpostmid = new ArrayList();
request.CookieContainer = cookieClass.cookie;
request.Method = "GET";
request.ContentType = header.contentType;
request.ServicePoint.ConnectionLimit = header.maxTry;
request.Accept = header.accept;
request.UserAgent = header.userAgent;
request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
bigpic = bigpic.Replace("big", "medium");
request.Referer = "http://www.pixiv.net/member_illust.php?" + bigpic;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
// morepiclist.Add(httptoll.sqlliistGet("http://www.pixiv.net/member_illust.php?" + bigpic.Replace(@"""", ""), "", header)[0].ToString());
morepiclist.Add(retString);
String bigurl = regexmatch(@"img\ssrc=""(.*?)""", Convert.ToString(morepiclist[0]).ToString()).Groups[1].Value;
if (bigurl != "")
{
string value11 = bigurl;
pr.text = value11;
this.BeginInvoke(UpdateV, pr);
// lock (locker)
// {
orglist.Add(value11);
orglistname.Add(morlistfilename);
// }
}
else
{
this.BeginInvoke(new MethodInvoker(delegate
{
MessageBox.Show("链接:http://www.pixiv.net" + piclist.ToString() + "无法解析");
}));
}
}
}
else
{
this.BeginInvoke(new MethodInvoker(delegate
{
MessageBox.Show("链接:http://www.pixiv.net" + piclist.ToString() + "无法解析");
}));
}
}
}
}
else
{
string value11 = orgpicmatch.Groups[3].Value;
pr.text = value11;
this.BeginInvoke(UpdateV, pr);
lock (locker)
{
orglist.Add(value11);
orglistname.Add(orgpicmatch.Groups[1].Value);
}
}
pr.pro1value++;
pr.text = "";
this.BeginInvoke(UpdateV, pr);
handler2img.Signal();
getloop = false;
}
catch(Exception er)
{
getloop = true;
if (strp > retry)
{
pr.pro1value++;
getloop = false;
pr.text = "该链接解析失败:"+"http://www.pixiv.net" + piclist.ToString();
this.BeginInvoke(UpdateV, pr);
}
strp++;
}
} while (getloop);
}
/// <summary>
/// 获取PIVIX用户作品网页内容
/// 获取每个作品的URL
/// </summary>
/// <param name="i">每个作品的地址url合集中的位置[] 由object转int arraylist[x]</param>
private void httpgetpage(object i)
{
HttpToolClass httptoll = new HttpToolClass();
// lock(locker)
// {
pr.pro1value++;
pr.text = "网页分析" + i;
this.BeginInvoke(UpdateV, pr);
// }
/*-获取用户ID作品页面合集中每个作品的单独的url地址
* @"""/member_illust.php\?mode=medium(.*?)"""
* -*/
ArrayList must2 = httptoll.sqlliistGet("http://www.pixiv.net/member_illust.php?id=" + textb1 + "&type=all&p=" + i.ToString(), "", header);
Match match = regexmatch(@"""/member_illust.php\?mode=medium(.*?)""", Convert.ToString(must2[0]).ToString());
ArrayList pic = new ArrayList();
while (match.Success)
{
if (!pic.Contains(match.Groups[0].ToString().Replace(@"amp;", "")) && (match.Groups[0].ToString().Replace(@"amp;", "")!=""))
{
/* 将获取到的每个作品的独立展示页面url
* 放入arraylist类型变量 pic 中保存
* _______*/
pic.Add(match.Groups[0].ToString().Replace(@"amp;", ""));
// lock (locker)
// {
pr.text = match.Groups[0].ToString().Replace(@"amp;", "");
this.BeginInvoke(UpdateV, pr);
// }
}
match = match.NextMatch();
}
// lock(locker)
// {
pr.pro1max = pr.pro1max +pic.Count;
pr.text = "";
this.BeginInvoke(UpdateV, pr);
// }
/*_判断当前激活线程数目
* ThreadPool.GetMaxThreads
*
* 增加线程池线程数量
* SetMaxThreads
*
* 给新增加线程加上计数标记,判断放入线程池中线程是否完成
* handler2img.AddCount
*
* 将获取到的每个作品的独立展示页面url (arraylist pic 集合)
* 放入方法httpgetpageimg中得到每个作品的下载地址url
*
*将httpgetpageimg 方法放入线程池
* _______*/
// int out1 = 0;
// int out2 = 0;
// ThreadPool.GetMaxThreads(out out1,out out2);
// if (out1 + pic.Count > workerthread)
// {
// ThreadPool.SetMaxThreads(workerthread, iothread);
// }
// else
// {
// ThreadPool.SetMaxThreads(out1 + (pic.Count/2), out2 + (pic.Count/2));
// }
// lock (locker)
// {
// ThreadPool.GetMaxThreads(out out1, out out2);
// if (handler2img == null)
// {
handler2img = new CountdownEvent(pic.Count);
// }
// else
// {
// handler2img.AddCount(pic.Count);
// }
// }
for (int x = 0; x < pic.Count; x++)
{
string piclist = pic[x].ToString().Replace(@"\;", "");
piclist = piclist.Replace(@"""", "");
ThreadPool.QueueUserWorkItem(new WaitCallback(httpgetpageimg), piclist);
}
/*本线程完成计数*/
handler.Signal();
}
/// <summary>
/// 从多图url下载地址中下载多图图片并保存
/// </summary>
/// <param name="x">多图图片地址url合集中的位置[] 由object转int arraylist[x]</param>
private void httpmorelistdown(object x)
{
// lock (locker)
// {
int l = Convert.ToInt32(x);
pr.text = "正在下载" + morelist[l].ToString();
this.BeginInvoke(UpdateV, pr);
string rPath = "";
// Stream pictrue = null;
Stream outStream = null;
// Stream inStream = null;
HttpWebResponse pictrue = null;
try
{
/*-获取多图下载地址进行下载
*
* 从流中得到Image类型
*
* -*/
int dowhile = 0;
/*-创建多图文件夹的默认文件夹名称
* piccollectionfilename
* -*/
string piccollectionfilename = "Collection";
do
{
try
{
// pictrue = null;
// httptoll.sqlliistGetimag(morelist[l].ToString(), "", header, ref pictrue);
/// Image imagbox1 = Image.FromStream(pictrue);
string p = morelist[l].ToString();
/*-获取图片扩展名
* pickuoz
* -*/
int pickuoz = p.LastIndexOf(".");
string pickuo = p.Substring(pickuoz);
/*-获取图片名(包含了多图文件夹的名称以//分割)
* rPath
* -*/
rPath = morelistname[l].ToString();
/*-从rPath中获取以//分割的多图文件夹名称(//符号之前的string)
* piccollectionfilename
* -*/
piccollectionfilename = regexmatch(@"(.*?)\\", rPath).Groups[1].Value.Replace(".", "");
/*-从rPath中获取图片名称 去掉了名称中包含的url信息
* rPath
*
* 加上文件后缀名pickuo
*
* rPath+pickuo
* -*/
rPath = filename(regexmatch(@"img/(.*?)\.", rPath).Groups[0].Value.Replace(".", "") + pickuo);
/*-去除不合法的文件名字符
* -*/
piccollectionfilename = filename(piccollectionfilename);
/*-创建储存地址
* -*/
if (!Directory.Exists(textblogin + "\\" + savename + "\\" + piccollectionfilename + "\\"))
{
Directory.CreateDirectory(textblogin + "\\" + savename + "\\" + piccollectionfilename + "\\");//不存在就创建目录
}
/*-创建文件名称 -*/
lock (locker)
{
/*--从流中保存图片到本地-*/
if (File.Exists(textblogin + "\\" + savename + "\\" + piccollectionfilename + "\\" + rPath))
{
/*-创建文件名称重复的话在图片名称前加上string lop
* -*/
int lop = 0;
while (File.Exists(textblogin + "\\" + savename + "\\" + piccollectionfilename + "\\" + (lop.ToString()) + rPath))
{
lop++;
}
rPath = (lop.ToString()) + rPath;
}
// lock (locker)
// {
/*-缓存-*/
outStream = File.Create(textblogin + "\\" + savename + "\\" + piccollectionfilename + "\\" + rPath);
}
// inStream = pictrue2;
/*-每次获取到的流长度-*/
int ll = 0;
/*-获取到的流总共长度-*/
long filestream = 0;
/*-该文件应该的长度-*/
long picrespose = 0;
int picresposeend = 0;
do
{
HttpToolClass httptoll = new HttpToolClass();
pictrue = null;
HttpHeader header = new HttpHeader();
/*-从原始数据的点开始获取数据,用于数据不完整时多次获取-*/
header.Length = (int)filestream;
header.Lengthend = picresposeend;
/*-获取该图片链接返回数据-*/
httptoll.sqlliistGetimag(morelist[l].ToString(), "", header, ref pictrue);
Stream inStream = null;
inStream = pictrue.GetResponseStream();
byte[] buffer = new byte[40960];
if (filestream == 0)
{
picrespose = pictrue.ContentLength;
if (picrespose > 0)
{
picresposeend = (int)(picrespose - 1);
}
else
{
picresposeend = 0;
}
}
// filestream = 0;
do
{
ll = inStream.Read(buffer, 0, buffer.Length);
// ll = pictrue.GetResponseStream().Read(buffer, 0, buffer.Length);
if (ll > 0)
{
outStream.Write(buffer, 0, ll);
filestream = filestream + ll;
}
} while (ll > 0);
if (inStream != null)
{
inStream.Close();
}
} while (filestream != picrespose); /*-判断该次获取的数据长度是否完整,不是的话继续获取剩余数据-*/
//inStream = pictrue;
/* int ll;
do
{
ll = pictrue.GetResponseStream().Read(buffer, 0, buffer.Length);
if (ll > 0)
{
outStream.Write(buffer, 0, ll);
}
} while (ll > 0);*/
// }
// lock (locker)
// {
pr.text = "下载多图ing请稍等" + rPath;
pr.pro1value++;
this.BeginInvoke(UpdateV, pr);
dowhile = retry;
// }
}
catch (Exception er)
{
if (outStream != null)
{
outStream.Close();
}
if (pictrue != null)
{
pictrue.Close();
}
File.Delete(textblogin + "\\" + savename + "\\" + piccollectionfilename + "\\" + rPath);
if (dowhile >= retry)
{
throw new Exception(" " + er.Message);
}
}
dowhile++;
} while (dowhile <= retry);
}
catch (Exception er)
{
// lock (locker)
// {
morelisterr.Add(l);
pr.text = "该链接出错" + er;
pr.pro1value++;
this.BeginInvoke(UpdateV, pr);
// }
}
finally
{
/*--关闭流-*/
if (outStream != null)
{
outStream.Close();
}
/* if (inStream != null)
{
inStream.Close();
}*/
if (pictrue != null)
{
pictrue.Close();
}
/// imagbox1.Dispose();
}
handler.Signal();
this.BeginInvoke(new MethodInvoker(delegate
{
label5.Text = "当前状态:正在下载 剩余 " + handler.CurrentCount + "/" + handler.InitialCount;
}));
// }
}
/// <summary>
/// 从单张大图url下载地址中下载图片并保存
/// </summary>
/// <param name="i">单张大图地址url合集中的位置[] 由object转int arraylist[x]</param>
private void httporglistdown(object i)
{
// lock (locker)
// {
int l = Convert.ToInt32(i);
pr.text = "正在下载" + orglist[l].ToString();
this.BeginInvoke(UpdateV, pr);
string rPath = "";
// Stream pictrue2 = null;
FileStream outStream = null;
HttpWebResponse pictrue2 = null;
// Stream inStream = null;
try
{
int dowhile = 0;
do
{
try
{
// Image imagbox2 = Image.FromStream(pictrue2);
string p = orglist[l].ToString();
int pickuoz = p.LastIndexOf(".");
string pickuo = p.Substring(pickuoz);
rPath = filename(orglistname[l].ToString() + pickuo);
if (!Directory.Exists(textblogin + "\\" + savename + "\\"))
{
Directory.CreateDirectory(textblogin + "\\" + savename + "\\");//不存在就创建目录
}
/*--从流中保存图片到本地-*/
lock (locker)
{
if (File.Exists(textblogin + "\\" + savename + "\\" + rPath))
{
/*-创建文件名称重复的话在图片名称前加上string lop
* -*/
int lop = 0;
while (File.Exists(textblogin + "\\" + savename + "\\" + lop.ToString() + rPath))
{
// rPath = (lop++.ToString()) + rPath;
lop++;
}
rPath = (lop.ToString()) + rPath;
}
// lock (locker)
// {
/*-缓存-*/
outStream = File.Create(textblogin + "\\" + savename + "\\" + rPath);
}
// inStream = pictrue2;
int ll = 0;
int picresposeend = 0;
long filestream = 0;
long picrespose = 0;
do{
HttpToolClass httptoll = new HttpToolClass();
pictrue2 = null;
HttpHeader header=new HttpHeader();
header.Length =(int) filestream;
header.Lengthend = picresposeend;
httptoll.sqlliistGetimag(orglist[l].ToString(), "", header, ref pictrue2);
Stream inStream = null;
inStream = pictrue2.GetResponseStream();
byte[] buffer = new byte[40960];
if (filestream == 0)
{
picrespose = pictrue2.ContentLength;
if (picrespose > 0)
{
picresposeend = (int)(picrespose - 1);
}
else
{
picresposeend = 0;
}
}
// filestream = 0;