private async void DownloadAnime(CancellationToken Token) { var vals = new Dictionary <string, string>(); StaticsClass.InvokeIfRequired(EpisodesFlowPanel, (() => { EpisodesFlowPanel.Controls.Cast <EpisodeControl>().ToList().Where(x => x.Checked).ToList().ForEach(x => vals.Add(x.Text, x.Tag.ToString())); CloseBox.Enabled = false; })); foreach (var keyValPair in vals) { var episodeName = GetSafeFilename(keyValPair.Key); try { _infoFrm.Invoke((MethodInvoker)(() => { _infoFrm.textBox1.Text = "Downloading: " + episodeName; _infoFrm.textBox1.Refresh(); })); } catch (ObjectDisposedException) { Token.ThrowIfCancellationRequested(); } var episodeUrl = keyValPair.Value; var directoryPath = _path + @"\" + GetSafeFilename(AnimeName.Text); Directory.CreateDirectory(directoryPath); string redirectorLink; if (VariablesClass.MasterURL == VariablesClass.KissLewdURL) { var animeurlname = _phantomObject.Url.Substring(_phantomObject.Url.LastIndexOf("/", StringComparison.Ordinal) + 1); redirectorLink = WebDriverClass.RunViaDesktop(AnimeUrl, animeurlname, episodeName, episodeUrl); } else { redirectorLink = (await GetGoogleLink(episodeUrl)).Replace("&", "&"); } if (redirectorLink != "no") { if (WebDriverClass.FileDoesNotExist(redirectorLink)) { var animeurlname = _phantomObject.Url.Substring(_phantomObject.Url.LastIndexOf("/", StringComparison.Ordinal) + 1); redirectorLink = WebDriverClass.RunViaDesktop(AnimeUrl, animeurlname, episodeName, episodeUrl); } Invoke((MethodInvoker)(() => _de.addDownload(redirectorLink, episodeName, directoryPath))); } } if (InvokeRequired) { Invoke((MethodInvoker)(() => { CloseBox.Enabled = true; _infoFrm.Close(); })); } else { CloseBox.Enabled = true; _infoFrm.Close(); } }
private async void DownloadNow(object sender, EventArgs e) { var fbd = new FolderBrowserDialog(); var result = fbd.ShowDialog(); if (result != DialogResult.OK) { return; } _path = fbd.SelectedPath; UseWaitCursor = true; DownloadBtn.Enabled = false; WatchNowBtn.Enabled = false; GetUrlsBtn.Enabled = false; var token = new CancellationToken(); try { await Task.Run(async() => { var vals = new Dictionary <string, string>(); StaticsClass.InvokeIfRequired(EpisodesFlowPanel, (() => { EpisodesFlowPanel.Controls.Cast <EpisodeControl>().ToList().Where(x => x.Checked).ToList().ForEach(x => vals.Add(x.Text, x.Tag.ToString())); CloseBox.Enabled = false; })); var directoryPath = _path + @"\" + GetSafeFilename(AnimeName.Text); Directory.CreateDirectory(directoryPath); var Urls = await GetDownloadUrls(vals, "Downloading"); foreach (var keyValPair in Urls) { var ActualUrl = keyValPair.Value; var EpisodeNum = keyValPair.Key; Invoke((MethodInvoker)(() => _de.addDownload(ActualUrl, EpisodeNum, directoryPath))); } StaticsClass.InvokeIfRequired(this, () => CloseBox.Enabled = true); }, token); } catch (OperationCanceledException) { //Messagebox disposed, stop doing this. } DownloadBtn.Enabled = true; WatchNowBtn.Enabled = true; GetUrlsBtn.Enabled = true; UseWaitCursor = false; }