[PTRun] Refactor GetHBitmap to handle external DLL failures in a separate task.
This commit is contained in:
Родитель
93d80f542c
Коммит
159c5744b8
|
@ -6,6 +6,7 @@ using System;
|
|||
using System.IO.Abstractions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
@ -117,20 +118,30 @@ namespace Wox.Infrastructure.Image
|
|||
Height = height,
|
||||
};
|
||||
|
||||
HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out hBitmap);
|
||||
|
||||
// if extracting image thumbnail and failed, extract shell icon
|
||||
if (options == ThumbnailOptions.ThumbnailOnly && hr == HResult.ExtractionFailed)
|
||||
// Initialize a Task to run GetImage separately
|
||||
Task.Run(() =>
|
||||
{
|
||||
hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, ThumbnailOptions.IconOnly, out hBitmap);
|
||||
}
|
||||
try
|
||||
{
|
||||
HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out hBitmap);
|
||||
|
||||
if (hr != HResult.Ok)
|
||||
{
|
||||
throw Marshal.GetExceptionForHR((int)hr);
|
||||
}
|
||||
// if extracting image thumbnail and failed, extract shell icon
|
||||
if (options == ThumbnailOptions.ThumbnailOnly && hr == HResult.ExtractionFailed)
|
||||
{
|
||||
hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, ThumbnailOptions.IconOnly, out hBitmap);
|
||||
}
|
||||
|
||||
return hBitmap;
|
||||
if (hr != HResult.Ok)
|
||||
{
|
||||
throw Marshal.GetExceptionForHR((int)hr);
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Exception($"Exception in GetImage: {ex.Message}", ex, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
|
@ -144,6 +155,8 @@ namespace Wox.Infrastructure.Image
|
|||
Marshal.ReleaseComObject(nativeShellItem);
|
||||
}
|
||||
}
|
||||
|
||||
return hBitmap;
|
||||
}
|
||||
|
||||
private static bool logReportedAdobeReaderDetected; // Keep track if Adobe Reader detection has been logged yet.
|
||||
|
|
Загрузка…
Ссылка в новой задаче