public async Task BeginDownload(DownloaderSettings settings) { await DownloadFiles(settings); Controls.Remove(splitter[0]); Controls.Remove(progressBar[0]); Controls.Remove(labels[0]); splitter.RemoveAt(0); progressBar.RemoveAt(0); labels.RemoveAt(0); if (pendingDownloads.Count != 0) { for (int i = 0; i < pendingDownloads.Count; i++) { splitter[i].Location = new Point(1, splitter[i].Location.Y - 52); progressBar[i].Location = new Point(12, progressBar[i].Location.Y - 52); labels[i].Location = new Point(12, labels[i].Location.Y - 52); } BeginDownload(pendingDownloads[0]); pendingDownloads.RemoveAt(0); } currentDownloads--; }
public async Task DownloadFiles(DownloaderSettings settings) { if (settings.BeforeStartAction != null) { await settings.BeforeStartAction?.Invoke(settings.BeforeStartArgs); } foreach (var file in settings.FilesToDownload) { if (file.BeforeStartAction != null) { await file.BeforeStartAction?.Invoke(file.BeforeStartArgs); } if (!Directory.Exists((LB.AppPath + file.OutputPath).DirectoryOf())) { Directory.CreateDirectory((LB.AppPath + file.OutputPath).DirectoryOf()); } using (var wc = new WebClient()) { var Uri = new Uri(file.Uri); var filename = Path.GetFileName(Uri.LocalPath); labels[0].Text = "Downloading " + filename; wc.DownloadProgressChanged += progressBarUpdate; await wc.DownloadFileTaskAsync(Uri, LB.AppPath + file.OutputPath); if (file.CompletedAction != null) { await file.CompletedAction?.Invoke(file.CompletedArgs); } } } if (settings.CompletedAction != null) { await settings.CompletedAction?.Invoke(settings.CompletedArgs); } }