diff --git a/ModAssistant/Classes/Utils.cs b/ModAssistant/Classes/Utils.cs
index 4f1c425..3181d0b 100644
--- a/ModAssistant/Classes/Utils.cs
+++ b/ModAssistant/Classes/Utils.cs
@@ -439,5 +439,30 @@ namespace ModAssistant
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
caller.BeginInvoke(Message, null, null, null);
}
+
+ ///
+ /// Attempts to write the specified string to the .
+ ///
+ /// The string to be written
+ public static void SetClipboard(string text)
+ {
+ bool success = false;
+ try
+ {
+ Clipboard.SetText(text);
+ success = true;
+ }
+ catch (Exception)
+ {
+ // Swallow exceptions relating to writing data to clipboard.
+ }
+
+ // This could be placed in the try/catch block but we don't
+ // want to suppress exceptions for non-clipboard operations
+ if (success)
+ {
+ Utils.SendNotify($"Copied text to clipboard");
+ }
+ }
}
}
diff --git a/ModAssistant/Pages/Mods.xaml.cs b/ModAssistant/Pages/Mods.xaml.cs
index 5d925bd..35d6751 100644
--- a/ModAssistant/Pages/Mods.xaml.cs
+++ b/ModAssistant/Pages/Mods.xaml.cs
@@ -716,8 +716,14 @@ namespace ModAssistant.Pages
private void CopyText(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
- System.Windows.Clipboard.SetText(((TextBlock)sender).Text);
- Utils.SendNotify("Copied text to clipboard");
+ var textBlock = sender as TextBlock;
+ if (textBlock == null) { return; }
+ var text = textBlock.Text;
+
+ // Ensure there's text to be copied
+ if (string.IsNullOrWhiteSpace(text)) { return; }
+
+ Utils.SetClipboard(text);
}
private void SearchButton_Click(object sender, RoutedEventArgs e)
diff --git a/ModAssistant/Pages/Options.xaml.cs b/ModAssistant/Pages/Options.xaml.cs
index f9d6035..d722b58 100644
--- a/ModAssistant/Pages/Options.xaml.cs
+++ b/ModAssistant/Pages/Options.xaml.cs
@@ -206,7 +206,7 @@ namespace ModAssistant.Pages
await Task.Run(async () => await UploadLog());
System.Diagnostics.Process.Start(LogURL);
- Clipboard.SetText(LogURL);
+ Utils.SetClipboard(LogURL);
MainWindow.Instance.MainText = (string)Application.Current.FindResource("Options:LogUrlCopied");
}
catch (Exception exception)