[Peek] Fix crash when opening Peek with no files selected (#26470)

* catch exception

* Check count of items to avoid the exception being thrown

* Fix regression from #26364

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
Seraphima Zykova
2023-05-30 12:56:07 +02:00
committed by GitHub
parent 4905258c94
commit b72af5e247
2 changed files with 38 additions and 23 deletions

View File

@@ -87,10 +87,20 @@ namespace Peek.UI.Helpers
private static IShellItemArray? GetShellItemArray(IShellBrowser shellBrowser, bool onlySelectedFiles)
{
var shellView = (IFolderView)shellBrowser.QueryActiveShellView();
var selectionFlag = onlySelectedFiles ? (uint)_SVGIO.SVGIO_SELECTION : (uint)_SVGIO.SVGIO_ALLVIEW;
shellView.Items(selectionFlag, typeof(IShellItemArray).GUID, out var items);
return items as IShellItemArray;
var shellViewObject = shellBrowser.QueryActiveShellView();
var shellView = shellViewObject as IFolderView;
if (shellView != null)
{
var selectionFlag = onlySelectedFiles ? (uint)_SVGIO.SVGIO_SELECTION : (uint)_SVGIO.SVGIO_ALLVIEW;
shellView.ItemCount(selectionFlag, out var countItems);
if (countItems > 0)
{
shellView.Items(selectionFlag, typeof(IShellItemArray).GUID, out var items);
return items as IShellItemArray;
}
}
return null;
}
}
}