//下载一个解析好的Album对象,把每张图片存入本地 private async Task donwloadAlbumObject(Album album) { //判断是否需要为相册创建单独的文件夹 StorageFolder saveFolder = DownloadFolder; if (NeedIndividualFolder) { saveFolder = await DownloadFolder.CreateFolderAsync(album.AlbumName, CreationCollisionOption.GenerateUniqueName); } int picNum = 0; foreach (string imagePageUrl in album.ImagePageUrlList) { picNum++; Picture picture = await findPictureInImagePage(album.AlbumName, picNum, imagePageUrl); album.PictureList.Add(picture); //让程序暂停,但已经开始的Task还是会完成下载。 while (IsPausing) { await Task.Delay(1000); } imageDownload(picture, saveFolder); } album.IsDownloaded = true; //album.DownloadStateIcon = Symbol.Accept; }
//去图标网站下载图标 private async Task downloadIconsFromWeb(Album album) { string htmlPage = await htmlDownloadAsync(album.AlbumUrlUserInput); string pattern1 = "srcset=\"[^\"]+"; MatchCollection matches = Regex.Matches(htmlPage, pattern1); string pattern2 = "[a-zA-z]+://[^\\s]*"; //List<string> imageUrls = new List<string>(); foreach (Match match in matches) { MatchCollection matches1 = Regex.Matches(match.Value, pattern2); foreach (Match match_1 in matches1) { if (match_1.Value.Contains("/previews/")) { } else { string[] temp = match_1.Value.Split("/"); string fileName = temp[temp.Length - 1]; string pictureUrl = match_1.Value; album.PictureList.Add( new Picture() { PictureUrl = pictureUrl, PictureFileName = fileName, PicturePageUrl = pictureUrl, } ); } } } album.AlbumName = searchFolderNameInHtml(htmlPage); //判断是否需要为相册创建单独的文件夹 StorageFolder saveFolder = DownloadFolder; if (NeedIndividualFolder) { saveFolder = await DownloadFolder.CreateFolderAsync(album.AlbumName, CreationCollisionOption.GenerateUniqueName); } foreach (Picture picture in album.PictureList) { imageDownload(picture, saveFolder); } }