Skip to content

Commit

Permalink
Handle exception in Icon to ImageSource conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 21, 2024
1 parent f844a65 commit ab6e3a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Bloxstrap/Extensions/IconEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,28 @@ public static class IconEx
{
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 changes: 11 additions & 0 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit ab6e3a0

Please sign in to comment.