mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
[PTRun][Program]Exception handling and checks at startup thumbnail generation (#28534)
* [PTRun] Exception handling and other checks are added. * [PTRun] Revert lines
This commit is contained in:
@@ -96,12 +96,18 @@ namespace Wox.Infrastructure.Image
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static IntPtr GetHBitmap(string fileName, int width, int height, ThumbnailOptions options)
|
private static IntPtr GetHBitmap(string fileName, int width, int height, ThumbnailOptions options)
|
||||||
|
{
|
||||||
|
IntPtr hBitmap = IntPtr.Zero;
|
||||||
|
IShellItem nativeShellItem = null;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Guid shellItem2Guid = new Guid(IShellItem2Guid);
|
Guid shellItem2Guid = new Guid(IShellItem2Guid);
|
||||||
int retCode = NativeMethods.SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out IShellItem nativeShellItem);
|
int retCode = NativeMethods.SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out nativeShellItem);
|
||||||
|
|
||||||
if (retCode != 0)
|
if (retCode != 0)
|
||||||
{
|
{
|
||||||
|
Log.Error($"Error while creating item. retCode:{retCode} ", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
throw Marshal.GetExceptionForHR(retCode);
|
throw Marshal.GetExceptionForHR(retCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +117,7 @@ namespace Wox.Infrastructure.Image
|
|||||||
Height = height,
|
Height = height,
|
||||||
};
|
};
|
||||||
|
|
||||||
HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out IntPtr hBitmap);
|
HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out hBitmap);
|
||||||
|
|
||||||
// if extracting image thumbnail and failed, extract shell icon
|
// if extracting image thumbnail and failed, extract shell icon
|
||||||
if (options == ThumbnailOptions.ThumbnailOnly && hr == HResult.ExtractionFailed)
|
if (options == ThumbnailOptions.ThumbnailOnly && hr == HResult.ExtractionFailed)
|
||||||
@@ -119,14 +125,25 @@ namespace Wox.Infrastructure.Image
|
|||||||
hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, ThumbnailOptions.IconOnly, out hBitmap);
|
hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, ThumbnailOptions.IconOnly, out hBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Marshal.ReleaseComObject(nativeShellItem);
|
if (hr != HResult.Ok)
|
||||||
|
|
||||||
if (hr == HResult.Ok)
|
|
||||||
{
|
{
|
||||||
return hBitmap;
|
throw Marshal.GetExceptionForHR((int)hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidComObjectException($"Error while extracting thumbnail for {fileName}", Marshal.GetExceptionForHR((int)hr));
|
return hBitmap;
|
||||||
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
|
{
|
||||||
|
Log.Exception($"Error while extracting thumbnail for {fileName}", ex, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (nativeShellItem != null)
|
||||||
|
{
|
||||||
|
Marshal.ReleaseComObject(nativeShellItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool logReportedAdobeReaderDetected; // Keep track if Adobe Reader detection has been logged yet.
|
private static bool logReportedAdobeReaderDetected; // Keep track if Adobe Reader detection has been logged yet.
|
||||||
|
|||||||
Reference in New Issue
Block a user