private async void CombineClicked(object sender, RoutedEventArgs e) { if (runningTask != null && !runningTask.IsCompleted) { busyIndicator.IsBusy = true; await Task.Run(() => { runningTask.Wait(); }); busyIndicator.IsBusy = false; } if (fileList.Items.Count < 2) { ErrorDialog.Show("You need to select at least 2 files"); return; } var fileName = Path.GetFileName(fileList.Items[0].File); foreach (Item item in fileList.Items) { if (Path.GetFileName(item.File) != fileName) { ErrorDialog.Show("All files must have the same name"); } } busyIndicator.IsBusy = true; try { var items = fileList.Items.Select(item => item.File).ToList <string>(); var alertCollissions = rbAdvancedCombine.IsChecked == true; await Task.Run(() => { Combiner.Combine(items, alertCollissions); }); busyIndicator.IsBusy = false; MessageBox.Show(this, "Combined mod can be found in dropzone folder", "Success", MessageBoxButton.OK, MessageBoxImage.None); } catch (Exception ex) { busyIndicator.IsBusy = false; Errors.Handle("Failed to combine mods", ex); } busyIndicator.BusyContent = "Deleting temporary files"; runningTask = TempFolder.ClearAsync(); }
public async void AddFileToList(string file) { if (Directory.Exists(file)) { ErrorDialog.Show("Can't combine directories"); return; } FileStream stream = null; try { stream = File.Open(file, FileMode.Open, FileAccess.Read); } catch (Exception ex) { Errors.Handle(ex); return; } finally { if (stream != null) { stream.Close(); stream.Dispose(); } } if (!await FileFormats.IsKnownFormat(file)) { ErrorDialog.Show("Can't combine " + Path.GetExtension(file) + " files. If you need to combine these let me know at jc3mods.com"); return; } foreach (Item item in Items) { if (Path.Equals(item.File, file)) { return; } } Items.Add(new Item(file)); }