private async Task DownloadChapter(DownloadChapterTask task, string mangaLocalPath, IProgress <int> progress) { var chapter = task.Chapter; progress.Report(0); var service = FrameworkProvider.GetService(chapter.Url); var images = await service.FindImages(chapter, new Progress <int>(count => { progress.Report(count / 2); }), _source.Token); var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempFolder); await DownloadImages(images, tempFolder, progress); var folderName = chapter.Name; var finalFolder = Path.Combine(mangaLocalPath, folderName); if (task.Formats.Contains(OutputFormat.Folder)) { if (!Directory.Exists(finalFolder)) { Directory.CreateDirectory(finalFolder); } ExtensionHelper.SuperMove(tempFolder, finalFolder); } if (task.Formats.Contains(OutputFormat.CBZ)) { PackageCbzHelper.Create(tempFolder, Path.Combine(task.SaveToFolder, task.Chapter.Name + ".cbz")); } progress.Report(100); }
public WorkerController(ServiceManager sm, ILogger logger, PackageCbzHelper cbz, IDownloader downloader) { this.logger = logger; logger.Info("> Worker()"); ServiceManager = sm; this.cbz = cbz; this.downloader = downloader; _source = new CancellationTokenSource(); _sema = new SemaphoreSlim(2); }