From 2f2bbb3dc0353336a696681c5ded875097010159 Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 11 Aug 2015 07:09:21 +0400 Subject: [PATCH] (AddSelectionExec): wrapped method body into try/catch block. --- MainWindow.xaml.cs | 71 +++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 95900edc..309641d1 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1061,42 +1061,49 @@ namespace GARbro.GUI /// void AddSelectionExec (object sender, ExecutedRoutedEventArgs e) { - var mask_list = new SortedSet(); - foreach (var entry in ViewModel) + try { - var ext = Path.GetExtension (entry.Name).ToLowerInvariant(); - if (!string.IsNullOrEmpty (ext)) - mask_list.Add ("*" + ext); - } - var selection = new EnterMaskDialog (mask_list); - selection.Owner = this; - var result = selection.ShowDialog(); - if (!result.Value) - return; - if ("*.*" == selection.Mask.Text) - { - CurrentDirectory.SelectAll(); - return; - } - var mask = Regex.Escape (selection.Mask.Text).Replace (@"\*", ".*").Replace (@"\?", "."); - var glob = new Regex ("^"+mask+"$", RegexOptions.IgnoreCase); - var matching = ViewModel.Where (entry => glob.IsMatch (entry.Name)); - if (!matching.Any()) - { - SetStatusText (string.Format (guiStrings.MsgNoMatching, selection.Mask.Text)); - return; - } - int count = 0; - foreach (var item in matching) - { - if (!CurrentDirectory.SelectedItems.Contains (item)) + var ext_list = new SortedSet(); + foreach (var entry in ViewModel) { - CurrentDirectory.SelectedItems.Add (item); - ++count; + var ext = Path.GetExtension (entry.Name).ToLowerInvariant(); + if (!string.IsNullOrEmpty (ext)) + ext_list.Add (ext); } + var selection = new EnterMaskDialog (ext_list.Select (ext => "*"+ext)); + selection.Owner = this; + var result = selection.ShowDialog(); + if (!result.Value) + return; + if ("*.*" == selection.Mask.Text) + { + CurrentDirectory.SelectAll(); + return; + } + var mask = Regex.Escape (selection.Mask.Text).Replace (@"\*", ".*").Replace (@"\?", "."); + var glob = new Regex ("^"+mask+"$", RegexOptions.IgnoreCase); + var matching = ViewModel.Where (entry => glob.IsMatch (entry.Name)); + if (!matching.Any()) + { + SetStatusText (string.Format (guiStrings.MsgNoMatching, selection.Mask.Text)); + return; + } + int count = 0; + foreach (var item in matching) + { + if (!CurrentDirectory.SelectedItems.Contains (item)) + { + CurrentDirectory.SelectedItems.Add (item); + ++count; + } + } + if (count != 0) + SetStatusText (Localization.Format ("MsgSelectedFiles", count)); + } + catch (Exception X) + { + SetStatusText (X.Message); } - if (count != 0) - SetStatusText (Localization.Format ("MsgSelectedFiles", count)); } void SelectAllExec (object sender, ExecutedRoutedEventArgs e)