private async Task DownloadWorker(List <AddonFile> files, string source, DirectoryInfo modpackDirectory, FileDownloadStatus[] states) { List <Task> tasks = new List <Task>(); for (int i = 0; i < files.Count; i++) { await Semaphore.WaitAsync(); AddonFile f = files[i]; string localPath = Path.Combine(modpackDirectory.FullName, f.Path); string remotePath = Path.Combine(source, f.Path); using (var c = new WebClient()) { c.DownloadProgressChanged += states[i].DownloadProgressHandler; c.DownloadFileCompleted += DownloadCompleted; string dir = Path.GetDirectoryName(localPath); Directory.CreateDirectory(dir); var t = c.DownloadFileTaskAsync( remotePath, localPath ); tasks.Add(t); } } await Task.WhenAll(tasks); }
public ModConfigurationDialog(AddonFile af, MainWindow mainWindow, bool continueMode) { InitializeComponent(); Title = af.FriendlyName; mainWindowRef = mainWindow; DataContext = af; List <ConfigurableModInterface> configurableItems = new List <ConfigurableModInterface>(); configurableItems.AddRange(af.ChoiceFiles); configurableItems.AddRange(af.CopyFiles.Where(s => s.Optional)); configurableItems.AddRange(af.ZipFiles.Where(s => s.Optional)); ListView_ChoiceFiles.ItemsSource = configurableItems; if (af.ComparisonsLink == null) { Comparison_Button.Visibility = Visibility.Collapsed; } if (!continueMode) { Cancel_Button.Visibility = Visibility.Collapsed; } else { Close_Button.Content = "Continue"; } }