From 4c1c2c3e6a1d4f4faf9f542ab337a0de83ab903f Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 20 Sep 2026 19:35:16 +0200 Subject: [PATCH] add bilder cache --- CSharpGhostImporter/ImageManager.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CSharpGhostImporter/ImageManager.cs b/CSharpGhostImporter/ImageManager.cs index b610d7b..6dcabf3 100644 --- a/CSharpGhostImporter/ImageManager.cs +++ b/CSharpGhostImporter/ImageManager.cs @@ -11,6 +11,7 @@ namespace wp2ghost { private static readonly HttpClient httpClient = new(); private static Dictionary Cache = new(); + private static Dictionary WordpressToGhostImageName = new(); private static List<(string RelativePath, string LocalPath)> FilesToZip = new(); private static string LocalImageDir = ""; private static string CachePath = ""; @@ -96,6 +97,19 @@ namespace wp2ghost if (string.IsNullOrEmpty(imageUrl) || !Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute)) return null; + string wpImageName = Path.GetFileNameWithoutExtension(new Uri(imageUrl).AbsolutePath); + + if (WordpressToGhostImageName.TryGetValue(wpImageName, out string? ghostRelativePath) && !string.IsNullOrEmpty(ghostRelativePath)) + { + string localPath = Path.Combine(LocalImageDir, ghostRelativePath); + if (File.Exists(localPath)) + { + Console.WriteLine($" [Bild] Bereits heruntergeladen (Wörterbuch): {wpImageName} → {ghostRelativePath}"); + return (ghostRelativePath, localPath); + } + WordpressToGhostImageName.Remove(wpImageName); + } + if (Cache.TryGetValue(imageUrl, out var cachedFile)) { if (File.Exists(cachedFile.LocalPath)) @@ -144,6 +158,7 @@ namespace wp2ghost var fileResult = (relativePath, localPath); Cache[imageUrl] = fileResult; + WordpressToGhostImageName[wpImageName] = relativePath; FilesToZip.Add(fileResult); return fileResult; }