handle clipboard copying exceptions

This commit is contained in:
bluepilledgreat 2024-06-18 19:48:25 +01:00
parent e8d311445c
commit 845b5b7074
4 changed files with 41 additions and 2 deletions

View File

@ -87,6 +87,15 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to copy to the clipboard: {0}.
/// </summary>
public static string Bootstrapper_ClipboardCopyFailed {
get {
return ResourceManager.GetString("Bootstrapper.ClipboardCopyFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Roblox is currently running, and launching another instance will close it. Are you sure you want to continue launching?.
/// </summary>

View File

@ -126,6 +126,9 @@
<data name="Bootstrapper.AutoUpdateFailed" xml:space="preserve">
<value>Bloxstrap was unable to auto-update to {0}. Please update it manually by downloading and running the latest release from the GitHub page.</value>
</data>
<data name="Bootstrapper.ClipboardCopyFailed" xml:space="preserve">
<value>Failed to copy to the clipboard: {0}</value>
</data>
<data name="Bootstrapper.ConfirmLaunch" xml:space="preserve">
<value>Roblox is currently running, and launching another instance will close it. Are you sure you want to continue launching?</value>
</data>

View File

@ -1,4 +1,5 @@
using System.Media;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
@ -30,9 +31,20 @@ namespace Bloxstrap.UI.Elements.Dialogs
LocateLogFileButton.Click += delegate
{
if (App.Logger.Initialized)
{
Process.Start("explorer.exe", $"/select,\"{App.Logger.FileLocation}\"");
}
else
Clipboard.SetDataObject(String.Join("\r\n", App.Logger.Backlog));
{
try
{
Clipboard.SetText(String.Join("\r\n", App.Logger.Backlog));
}
catch (COMException ex)
{
Frontend.ShowMessageBox(string.Format(Bloxstrap.Resources.Strings.Bootstrapper_ClipboardCopyFailed, ex.Message), MessageBoxImage.Error);
}
}
};
ReportOptions.DropDownClosed += (sender, e) =>

View File

@ -6,6 +6,7 @@ using System.Collections.ObjectModel;
using Wpf.Ui.Mvvm.Contracts;
using Bloxstrap.UI.Elements.Dialogs;
using System.Runtime.InteropServices;
namespace Bloxstrap.UI.Elements.Menu.Pages
{
@ -341,8 +342,22 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
private void ExportJSONButton_Click(object sender, RoutedEventArgs e)
{
const string LOG_IDENT = "FastFlagEditorPage::ExportJSONButton_Click";
string json = JsonSerializer.Serialize(App.FastFlags.Prop, new JsonSerializerOptions { WriteIndented = true });
Clipboard.SetText(json);
try
{
Clipboard.SetText(json);
}
catch (COMException ex)
{
App.Logger.WriteLine(LOG_IDENT, "Failed to copy to the clipboard");
App.Logger.WriteException(LOG_IDENT, ex);
Frontend.ShowMessageBox(string.Format(Bloxstrap.Resources.Strings.Bootstrapper_ClipboardCopyFailed, ex.Message), MessageBoxImage.Error);
return;
}
Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_JsonCopiedToClipboard, MessageBoxImage.Information);
}