예제 #1
0
 /// <summary>
 /// 下载插画
 /// </summary>
 /// <param name="path">下载路径</param>
 private void DownIllustration(string path)
 {
     foreach (var x in img.Urls)
     {
         ImgList temp = new ImgList();
         temp.url  = x;
         temp.path = path;
         imgList.Add(temp);
     }
 }
예제 #2
0
        private void btn_SaveImages_Click(object sender, EventArgs e)
        {
            //移除空白字符
            string path = txt_FloderPath.Text.Trim();

            //判断文件夹是否存在,不存在则创建文件夹后继续。若路径名含有不能使用字符,返回错误信息
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //保存描述
            //string titleCheck = Regex.Replace(img.Author, "[\\u005C/:\\u002A\\u003F\"<>\'\\u007C]", "_");
            string       title    = Regex.Match(path, ".*\\\\(?<name>.+)").Groups["name"].Value.ToString();
            string       infoPath = path + "\\" + title;
            string       value    = txt_words.Text;
            FileStream   fs       = new FileStream(infoPath + ".txt", FileMode.OpenOrCreate);
            StreamWriter sw       = new StreamWriter(fs);

            sw.WriteAsync(value);
            sw.Flush();
            sw.Close();
            fs.Close();

            //保存链接
            using (StreamWriter writer = new StreamWriter(infoPath + ".url"))
            {
                writer.WriteLine("[InternetShortcut]");
                writer.WriteLine("URL=" + txt_Url.Text);
                writer.WriteLine(@"IconFile=C:\Windows\system32\SHELL32.dll");
                writer.WriteLine("IconIndex=13");
                writer.Flush();
            }

            //获取链接
            string          source  = txt_address.Text;
            Regex           linkreg = new Regex(@"<img class='detail_std detail_clickable' src='(?<info>.+?)/w650' />");
            MatchCollection urls    = linkreg.Matches(source);

            foreach (Match x in urls)
            {
                string str;
                str = x.Groups["info"].Value;
                if (!string.IsNullOrEmpty(str))
                {
                    ImgList temp = new ImgList();
                    temp.url  = str;
                    temp.path = path;
                    imgList.Add(temp);
                }
            }

            //激活打开文件夹按钮
            btn_OpenFloder.Enabled = true;
        }
예제 #3
0
 ImgList GetUrl()
 {
     if (imgList.Count > 0)
     {
         ImgList url = imgList[0];
         imgList.Remove(url);
         if (isFirst)
         {
             status  = 1;
             isFirst = false;
         }
         return(url);
     }
     else
     {
         if (!isFirst)
         {
             status = 2;
         }
         return(null);
     }
 }
예제 #4
0
        /// <summary>
        /// 下载Cosplay和日常图片
        /// </summary>
        /// <param name="path">下载路径</param>
        private void DownCosplay(string path)
        {
            //保存描述
            //string title = Regex.Match(path, ".*\\\\(?<name>.+)").Groups["name"].Value.ToString();
            string title    = Path.GetFileNameWithoutExtension(path);
            string infoPath = Path.Combine(path, title);
            string value    = img.Description;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            FileStream   fs = new FileStream(infoPath + ".txt", FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);

            sw.WriteAsync(value);
            sw.Flush();
            sw.Close();
            fs.Close();

            //保存链接
            using (StreamWriter writer = new StreamWriter(infoPath + ".url"))
            {
                writer.WriteLine("[InternetShortcut]");
                writer.WriteLine("URL=" + txt_Url.Text);
                writer.WriteLine(@"IconFile=C:\Windows\system32\SHELL32.dll");
                writer.WriteLine("IconIndex=13");
                writer.Flush();
            }

            foreach (var x in img.Urls)
            {
                ImgList temp = new ImgList();
                temp.url  = x;
                temp.path = path;
                imgList.Add(temp);
            }
        }
예제 #5
0
 void DownImg()
 {
     while (downStart)
     {
         ImgList img = GetUrl();
         if (img == null)
         {
             if (!isFirst && status == 2)
             {
                 MessageBox.Show("全部下载任务已完成!", "提示");
                 status  = 0;
                 isFirst = true;
             }
             Thread.Sleep(3000);
             continue;
         }
         string name = Regex.Match(img.url, ".*/(?<name>.+)").Groups["name"].ToString();
         using (WebClient client = new WebClient())
         {
             client.DownloadFile(new Uri(img.url), img.path + "\\" + name);
         }
     }
 }
예제 #6
0
 /// <summary>
 /// 下载图片线程
 /// </summary>
 void DownImg()
 {
     while (downStart)
     {
         ImgList img = GetUrl();
         if (img == null)
         {
             if (!isFirst && status == 2)
             {
                 MessageBox.Show("本次下载任务已完成!", "提示");
                 status  = 0;
                 isFirst = true;
             }
             Thread.Sleep(3000);
             continue;
         }
         if (!WebApi.DownloadFile(img.url, img.path))
         {
             string fileName = Path.GetFileName(img.url);
             string dirName  = Path.GetFileName(img.path);
             MessageBox.Show(dirName + " - " + fileName + " 下载出错!", "提示");
         }
     }
 }