private void CompleteArticle(EmiliaArticleSegment efs) { if (Settings.Instance.Model.AutoZip) { Monitor.Instance.Push("[Zip Start] " + Path.Combine(download_folder, efs.FolderName)); MainWindow.Instance.ZipCountUp(); System.Threading.Interlocked.Increment(ref zip_count); Application.Current.Dispatcher.BeginInvoke(new Action( delegate { DownloadState.Text = $"{zip_count}개 압축 중"; })); Task.Run(() => Zip(Path.Combine(download_folder, efs.FolderName))); } }
private void StartFirstDownloads() { DispatchInformation dispatch_info = new DispatchInformation(); dispatch_info.DownloadSize = DownloadSize; dispatch_info.DownloadStatus = DownloadStatus; dispatch_info.DownloadRetry = DownloadRetry; dispatch_info.CompleteFile = CompleteFile; dispatch_info.CompleteArticle = CompleteArticle; dispatch_info.CompleteSeries = CompleteSeries; dispatch_info.ErrorOccured = ErrorOcurred; Application.Current.Dispatcher.BeginInvoke(new Action( delegate { CollectStatusPanel.Visibility = Visibility.Visible; DownloadState.Text = $"수집 중"; })); switch (manager.EngineType) { case ManagerEngineType.None: { // // Collect 시작 // int file_count = 0; if (manager.Type == ManagerType.SingleArticleMultipleImages) { article.ImagesLink = manager.ParseImages(NetCommon.DownloadString(article.Archive), article); } else if (manager.Type == ManagerType.SingleSeriesMultipleArticles) { Application.Current.Dispatcher.BeginInvoke(new Action( delegate { ProgressText.Text = $"가져오는 중... [0/{series.Articles.Count}]"; })); var result = EmiliaJob.Instance.AddJob(series.Archive.ToList(), (count) => { Application.Current.Dispatcher.BeginInvoke(new Action( delegate { ProgressText.Text = $"가져오는 중...[{count}/{series.Articles.Count}]"; })); }); for (int i = 0; i < series.Articles.Count; i++) { series.Articles[i].ImagesLink = manager.ParseImages(result[i], series.Articles[i]); file_count += series.Articles[i].ImagesLink.Count; int k = i; Application.Current.Dispatcher.BeginInvoke(new Action( delegate { //ProgressText.Text = $"가져오는 중... [{i}/{series.Articles.Count}] (파일 {file_count}개)"; if (k == 0 && string.IsNullOrEmpty(series.Thumbnail)) { LoadThumbnail(thumbnail = series.Articles[0].ImagesLink[0]); } })); } } Application.Current.Dispatcher.BeginInvoke(new Action( delegate { CollectStatusPanel.Visibility = Visibility.Collapsed; DownloadStatusPanel.Visibility = Visibility.Visible; Progress.Maximum = file_count; ProgressStatus.Text = $"[0/{file_count}]"; })); // // 다운로드 시작 // EmiliaSeriesSegment series_seg = new EmiliaSeriesSegment(); series_seg.Index = EmiliaDispatcher.Instance.GetSeriesIndex(); series_seg.Title = series.Title; download_folder = series_seg.Path = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), manager.Name.Trim()), DeleteInvalid(series.Title)); List <EmiliaArticleSegment> article_segs = new List <EmiliaArticleSegment>(); HashSet <string> folder_names = new HashSet <string>(); int ov = 0; for (int i = 0; i < series.Articles.Count; i++) { EmiliaArticleSegment article_seg = new EmiliaArticleSegment(); article_seg.Index = i; article_seg.Name = series.Articles[i].Title; string folder_name = DeleteInvalid(series.Articles[i].Title).Trim(); if (!folder_names.Contains(folder_name)) { article_seg.FolderName = DeleteInvalid(series.Articles[i].Title).Trim(); } else { article_seg.FolderName = DeleteInvalid(series.Articles[i].Title).Trim() + $" [OV{++ov}]"; } folder_names.Add(article_seg.FolderName); article_seg.SereisIndex = series_seg.Index; Directory.CreateDirectory(Path.Combine(series_seg.Path, article_seg.FolderName)); List <EmiliaFileSegment> file_segs = new List <EmiliaFileSegment>(); List <string> file_names = manager.GetDownloadFileNames(series.Articles[i]); if (!Settings.Instance.Model.DownloadWithRawFileName) { file_names = PathFilenameSorter.SortOnlyFilename(file_names.ToArray()).ToList(); } for (int j = 0; j < series.Articles[i].ImagesLink.Count; j++) { EmiliaFileSegment file_seg = new EmiliaFileSegment(); file_seg.Index = j; file_seg.ArticleIndex = i; file_seg.SeriesIndex = series_seg.Index; file_seg.FileName = file_names[j]; file_seg.Url = series.Articles[i].ImagesLink[j]; SemaphoreExtends se = SemaphoreExtends.MakeDefault(); se.Referer = url; file_seg.Extends = se; file_segs.Add(file_seg); } article_seg.Files = file_segs; article_segs.Add(article_seg); } series_seg.Articles = article_segs; EmiliaDispatcher.Instance.Add(series_seg, dispatch_info); } break; case ManagerEngineType.UsingDriver: { int file_count = 0; if (manager.Type == ManagerType.SingleArticleMultipleImages) { wrapper.Navigate(article.Archive); try { wrapper.ClickXPath("//a[@class='maia-button maia-button-primary']"); } catch { } article.ImagesLink = manager.ParseImages(wrapper.GetHtml(), article); } else if (manager.Type == ManagerType.SingleSeriesMultipleArticles) { Application.Current.Dispatcher.BeginInvoke(new Action( delegate { ProgressText.Text = $"가져오는 중... [0/{series.Articles.Count}]"; })); for (int i = 0; i < series.Articles.Count; i++) { wrapper.Navigate(series.Archive[i]); try { wrapper.ClickXPath("//a[@class='maia-button maia-button-primary']"); } catch { } series.Articles[i].ImagesLink = manager.ParseImages(wrapper.GetHtml(), series.Articles[i]); file_count += series.Articles[i].ImagesLink.Count; int k = i; Application.Current.Dispatcher.BeginInvoke(new Action( delegate { ProgressText.Text = $"가져오는 중... [{i}/{series.Articles.Count}] (파일 {file_count}개)"; if (k == 0 && string.IsNullOrEmpty(series.Thumbnail)) { LoadThumbnail(thumbnail = series.Articles[0].ImagesLink[0]); } })); } } Application.Current.Dispatcher.BeginInvoke(new Action( delegate { CollectStatusPanel.Visibility = Visibility.Collapsed; DownloadStatusPanel.Visibility = Visibility.Visible; Progress.Maximum = file_count; ProgressStatus.Text = $"[0/{file_count}]"; })); // // 다운로드 시작 // EmiliaSeriesSegment series_seg = new EmiliaSeriesSegment(); series_seg.Index = EmiliaDispatcher.Instance.GetSeriesIndex(); series_seg.Title = series.Title; download_folder = series_seg.Path = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), manager.Name.Trim()), DeleteInvalid(series.Title)); List <EmiliaArticleSegment> article_segs = new List <EmiliaArticleSegment>(); for (int i = 0; i < series.Articles.Count; i++) { EmiliaArticleSegment article_seg = new EmiliaArticleSegment(); article_seg.Index = i; article_seg.Name = series.Articles[i].Title; article_seg.FolderName = DeleteInvalid(series.Articles[i].Title).Trim(); article_seg.SereisIndex = series_seg.Index; Directory.CreateDirectory(Path.Combine(series_seg.Path, article_seg.FolderName)); List <EmiliaFileSegment> file_segs = new List <EmiliaFileSegment>(); List <string> file_names = manager.GetDownloadFileNames(series.Articles[i]); if (!Settings.Instance.Model.DownloadWithRawFileName) { file_names = PathFilenameSorter.SortOnlyFilename(file_names.ToArray()).ToList(); } for (int j = 0; j < series.Articles[i].ImagesLink.Count; j++) { EmiliaFileSegment file_seg = new EmiliaFileSegment(); file_seg.Index = j; file_seg.ArticleIndex = i; file_seg.SeriesIndex = series_seg.Index; file_seg.FileName = file_names[j]; file_seg.Url = series.Articles[i].ImagesLink[j]; SemaphoreExtends se = SemaphoreExtends.MakeDefault(); se.Referer = url; file_seg.Extends = se; file_segs.Add(file_seg); } article_seg.Files = file_segs; article_segs.Add(article_seg); } series_seg.Articles = article_segs; EmiliaDispatcher.Instance.Add(series_seg, dispatch_info); } break; } Application.Current.Dispatcher.BeginInvoke(new Action( delegate { DownloadState.Text = $"대기 중"; })); }