Skip to content

Commit fc989c4

Browse files
committed
如果找不到工具则加上缓存,避免重复调用
1 parent 2cffc61 commit fc989c4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/MediaConverters/SkiaWmfRenderer/src/SkiaWmfRenderer/Optimizations/EnhancedGraphicsMetafileOptimization.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ private static EnhancedGraphicsMetafileOptimizationResult ConvertWithLibWmf(in E
291291
return EnhancedGraphicsMetafileOptimizationResult.NotSupported();
292292
}
293293

294+
/// <summary>
295+
/// 是否 Inkscape 应用程序未安装
296+
/// </summary>
297+
/// 先不考虑后续 Inkscape 可能安装的问题。可在业务端设置为 false 继续尝试
298+
public static bool IsInkscapeNotBeInstalled { get; set; }
299+
294300
[SupportedOSPlatform("linux")]
295301
private static EnhancedGraphicsMetafileOptimizationResult ConvertWithInkscape(EnhancedGraphicsMetafileOptimizationContext context)
296302
{
@@ -301,6 +307,13 @@ private static EnhancedGraphicsMetafileOptimizationResult ConvertWithInkscape(En
301307

302308
context.LogMessage($"Start convert emf or wmf to png by Inkscape. File:'{file}'");
303309

310+
if (IsInkscapeNotBeInstalled)
311+
{
312+
// 转换失败,因为缓存的属性明确表示 Inkscape 应用程序不存在
313+
context.LogMessage($"Convert emf or wmf to svg by Inkscape failed. Because cache property indicate Inkscape application not be installed. {nameof(IsInkscapeNotBeInstalled)}=true. We will continue use libwmf to convert the image.");
314+
return EnhancedGraphicsMetafileOptimizationResult.NotSupported();
315+
}
316+
304317
var processStartInfo = new ProcessStartInfo("inkscape")
305318
{
306319
ArgumentList =
@@ -336,6 +349,9 @@ private static EnhancedGraphicsMetafileOptimizationResult ConvertWithInkscape(En
336349
// 明确不存在,那就不记录错误信息了
337350
// 大概耗时 17 毫秒
338351
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.");
352+
353+
// 设置为 true 缓存,避免下次继续尝试
354+
IsInkscapeNotBeInstalled = true;
339355
}
340356
else
341357
{

0 commit comments

Comments
 (0)