/// <summary> /// Gets the full path to a bar icon in the assets directory, based on its name (with or without the extension). /// </summary> /// <param name="name">Name of the icon.</param> /// <returns></returns> public static string?GetBarIconFile(string name) { string safe = new Regex(@"\.\.|[^-a-zA-Z0-9./]+", RegexOptions.Compiled) .Replace(name, "_") .Trim('/') .Replace('/', Path.DirectorySeparatorChar); string assetFile = AppPaths.GetAssetFile("bar-icons\\" + safe); string[] extensions = { "", ".svg", ".png", ".ico", ".jpg", ".jpeg", ".gif" }; string?foundFile = extensions.Select(extension => assetFile + extension) .FirstOrDefault(File.Exists); return(foundFile); }
/// <summary> /// Gets the full path to a bar icon in the assets directory, based on its name (with or without the extension). /// </summary> /// <param name="name">Name of the icon.</param> /// <returns></returns> public static string? GetBarIconFile(string name) { var translatedName = BarImages.TranslateImageUrlToFileName(name); if (translatedName is not null) { name = translatedName; } string safe = new Regex(@"\.\.|[^-a-zA-Z0-9./]+", RegexOptions.Compiled) .Replace(name, "_") .Trim('/') .Replace('/', Path.DirectorySeparatorChar); string assetFile = AppPaths.GetAssetFile("bar-icons\\" + safe); string[] extensions = { "", ".xaml", ".png", ".ico", ".jpg", ".jpeg", ".gif" }; string? foundFile = extensions.Select(extension => assetFile + extension) .FirstOrDefault(File.Exists); return foundFile; }