diff --git a/TileIconifier/Controls/IconListView/IconListVewItemCollection.cs b/TileIconifier/Controls/IconListView/IconListVewItemCollection.cs index b5cd682..2ffa13a 100644 --- a/TileIconifier/Controls/IconListView/IconListVewItemCollection.cs +++ b/TileIconifier/Controls/IconListView/IconListVewItemCollection.cs @@ -85,6 +85,21 @@ public void Add(IconListViewItem item) _owner.OnItemAddedInternal(true); } + public void AddRange(List items) + { + if(items == null) + { + throw new ArgumentNullException(nameof(items)); + } + + var newItems = new IconListViewItem[items.Count]; + for(var i = 0; i < items.Count; i++) + { + newItems[i] = items[i]; + } + AddRange(newItems); + } + public void AddRange(IconListViewItem[] items) { if (items == null) diff --git a/TileIconifier/Forms/Shared/FrmIconSelector.cs b/TileIconifier/Forms/Shared/FrmIconSelector.cs index 3528b5a..c69416f 100644 --- a/TileIconifier/Forms/Shared/FrmIconSelector.cs +++ b/TileIconifier/Forms/Shared/FrmIconSelector.cs @@ -103,7 +103,7 @@ private FrmIconSelector(string targetPath) SetUpOpenFileDialog(); SetUpCommonDllComboBox(); SetUpTargetPath(targetPath); - BuildListView(); + BuildListView(); } public static IconSelectorResult GetImage(IWin32Window owner, string defaultPathForIconExtraction = "") @@ -194,14 +194,14 @@ private void BuildListView() { return; } - + try { //Get the icons //icon files don't need extraction if (string.Equals(Path.GetExtension(targetPath), ".ico", StringComparison.InvariantCultureIgnoreCase)) { - _icons = new[] {new Icon(targetPath)}; + _icons = new[] { new Icon(targetPath) }; } else { @@ -210,7 +210,7 @@ private void BuildListView() } //Build the list view items - var items = new IconListViewItem[_icons.Length]; + var items = new List(); for (var i = 0; i < _icons.Length; i++) { var splitIcons = IconUtil.Split(_icons[i]); @@ -218,9 +218,17 @@ private void BuildListView() var largestIcon = splitIcons.OrderByDescending(k => k.Width) .ThenByDescending(k => Math.Max(k.Height, k.Width)) .First(); - - var bmp = IconUtil.ToBitmap(largestIcon); - items[i] = new IconListViewItem(bmp); + Bitmap bmp = null; + try + { + bmp = IconUtil.ToBitmap(largestIcon); + } + catch + { + //icon failed to convert to bitmap + continue; + } + items.Add(new IconListViewItem(bmp)); //Icon cleanup _icons[i].Dispose(); @@ -230,7 +238,7 @@ private void BuildListView() } lvwIcons.Items.AddRange(items); } - catch + catch (Exception ex) { // ignored }