mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-18 16:41:36 -07:00
Handle exception in Icon to ImageSource conversion
This commit is contained in:
parent
f844a654f6
commit
ab6e3a02ea
@ -8,11 +8,28 @@ namespace Bloxstrap.Extensions
|
||||
{
|
||||
public static Icon GetSized(this Icon icon, int width, int height) => new(icon, new Size(width, height));
|
||||
|
||||
public static ImageSource GetImageSource(this Icon icon)
|
||||
public static ImageSource GetImageSource(this Icon icon, bool handleException = true)
|
||||
{
|
||||
using MemoryStream stream = new();
|
||||
icon.Save(stream);
|
||||
return BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
|
||||
if (handleException)
|
||||
{
|
||||
try
|
||||
{
|
||||
return BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
App.Logger.WriteException("IconEx::GetImageSource", ex);
|
||||
Frontend.ShowMessageBox(String.Format(Strings.Dialog_IconLoadFailed, ex.Message));
|
||||
return BootstrapperIcon.IconBloxstrap.GetIcon().GetImageSource(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Bloxstrap/Resources/Strings.Designer.cs
generated
11
Bloxstrap/Resources/Strings.Designer.cs
generated
@ -976,6 +976,17 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The chosen bootstrapper icon could not be loaded.
|
||||
///
|
||||
///{0}.
|
||||
/// </summary>
|
||||
public static string Dialog_IconLoadFailed {
|
||||
get {
|
||||
return ResourceManager.GetString("Dialog.IconLoadFailed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Choose preferred language.
|
||||
/// </summary>
|
||||
|
@ -1198,4 +1198,9 @@ Please manually delete Bloxstrap.exe from the install location or try restarting
|
||||
<data name="Bootstrapper.JsonManagerSaveFailed" xml:space="preserve">
|
||||
<value>Failed to save {0}: {1}</value>
|
||||
</data>
|
||||
<data name="Dialog.IconLoadFailed" xml:space="preserve">
|
||||
<value>The chosen bootstrapper icon could not be loaded.
|
||||
|
||||
{0}</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user