Skip to content

Commit c7673b6

Browse files
committed
明确不存在的记录减少异常内容
1 parent fd13a00 commit c7673b6

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/MediaConverters/MediaConverters.Lib/Imaging/Optimizations/EnhancedGraphicsMetafileOptimization.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.Drawing;
45
using System.Drawing.Imaging;
@@ -204,7 +205,18 @@ private static ImageFileOptimizationResult ConvertWithInkscape(ImageFileOptimiza
204205
catch (Exception e)
205206
{
206207
// 失败了,继续调用 libwmf 进行转换
207-
context.LogMessage($"Convert emf or wmf to svg by Inkscape failed. We will continue use libwmf to convert the image. File='{file}' Exception: {e}");
208+
const int NoSuchFileErrorCode = 2;
209+
if (e is Win32Exception win32Exception && win32Exception.NativeErrorCode == NoSuchFileErrorCode)
210+
{
211+
// 明确不存在,那就不记录错误信息了
212+
// 大概耗时 17 毫秒
213+
context.LogMessage($"Convert emf or wmf to svg by Inkscape failed. Because not found Inkscape application. Please make sure Inkscape be installed. We will continue use libwmf to convert the image.");
214+
}
215+
else
216+
{
217+
context.LogMessage($"Convert emf or wmf to svg by Inkscape failed. We will continue use libwmf to convert the image. File='{file}' Exception: {e}");
218+
}
219+
208220
return ImageFileOptimizationResult.FailException(e);
209221
}
210222

0 commit comments

Comments
 (0)