Force save favicon icons & Fix svg save issue

This commit is contained in:
Jack251970 2025-04-09 17:05:29 +08:00
parent 4f246460c3
commit ba0205f471
2 changed files with 20 additions and 9 deletions

View file

@ -177,11 +177,9 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader
if (imageData is not { Length: > 0 })
continue;
var faviconPath = Path.Combine(_faviconCacheDir, $"{domain}_{iconId}.png");
if (!File.Exists(faviconPath))
{
SaveBitmapData(imageData, faviconPath);
}
var faviconPath = Path.Combine(_faviconCacheDir, $"chromium_{domain}_{iconId}.png");
SaveBitmapData(imageData, faviconPath);
bookmark.FaviconPath = faviconPath;
}
catch (Exception ex)

View file

@ -155,12 +155,16 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
if (imageData is not { Length: > 0 })
continue;
var faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.png");
if (!File.Exists(faviconPath))
string faviconPath;
if (IsSvgData(imageData))
{
SaveBitmapData(imageData, faviconPath);
faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.svg");
}
else
{
faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.png");
}
SaveBitmapData(imageData, faviconPath);
bookmark.FaviconPath = faviconPath;
}
@ -201,6 +205,15 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
Main._context.API.LogException(ClassName, $"Failed to save image: {outputPath}", ex);
}
}
private static bool IsSvgData(byte[] data)
{
if (data.Length < 5)
return false;
string start = System.Text.Encoding.ASCII.GetString(data, 0, Math.Min(100, data.Length));
return start.Contains("<svg") ||
(start.StartsWith("<?xml") && start.Contains("<svg"));
}
}
public class FirefoxBookmarkLoader : FirefoxBookmarkLoaderBase