public override bool Execute() { var splash = MauiSplashScreen[0]; var info = ResizeImageInfo.Parse(splash); var outputFileName = info.OutputName; var image = outputFileName + ".png"; var color = info.Color ?? SKColors.White; float r = color.Red / (float)byte.MaxValue; float g = color.Green / (float)byte.MaxValue; float b = color.Blue / (float)byte.MaxValue; float a = color.Alpha / (float)byte.MaxValue; var rStr = r.ToString(CultureInfo.InvariantCulture); var gStr = g.ToString(CultureInfo.InvariantCulture); var bStr = b.ToString(CultureInfo.InvariantCulture); var aStr = a.ToString(CultureInfo.InvariantCulture); var dir = Path.GetDirectoryName(OutputFile); Directory.CreateDirectory(dir); using (var writer = File.CreateText(OutputFile)) { SubstituteStoryboard(writer, image, rStr, gStr, bStr, aStr); } return(!Log.HasLoggedErrors); }
public override bool Execute() { var splash = MauiSplashScreen[0]; var img = ResizeImageInfo.Parse(splash); Directory.CreateDirectory(IntermediateOutputPath); var appTool = new SkiaSharpAppIconTools(img, this); Log.LogMessage(MessageImportance.Low, $"Splash Screen: Intermediate Path " + IntermediateOutputPath); foreach (var dpi in DpiPath.Windows.SplashScreen) { Log.LogMessage(MessageImportance.Low, $"Splash Screen: " + dpi); var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath); Log.LogMessage(MessageImportance.Low, $"Splash Screen Destination: " + destination); appTool.Resize(dpi, Path.ChangeExtension(destination, ".png")); } return(!Log.HasLoggedErrors); }
public AndroidAdaptiveIconGenerator(ResizeImageInfo info, string appIconName, string intermediateOutputPath, ILogger logger) { Info = info; Logger = logger; IntermediateOutputPath = intermediateOutputPath; AppIconName = appIconName; }
public AppleIconAssetsGenerator(ResizeImageInfo info, string appIconName, string intermediateOutputPath, DpiPath[] dpis, ILogger logger) { Info = info; Logger = logger; IntermediateOutputPath = intermediateOutputPath; AppIconName = appIconName; Dpis = dpis; }
void UpdateSharedResources(XNamespace xmlns, XElement manifestElement) { var uiApplicationElement = manifestElement.Element(xmlns + UiApplicationName); var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null; if (appIconInfo != null) { var xiconName = xmlns + IconName; var iconElements = uiApplicationElement.Elements(xiconName); var iconPlaceholderElements = iconElements.Where(d => d.Value == AppIconPlaceholder); foreach (var icon in iconPlaceholderElements) { if (icon.Attribute(DpiName) == null) { var defaultDpi = DpiPath.Tizen.AppIcon.Where(n => n.Path.EndsWith(IconDefaultDpiType)).FirstOrDefault(); icon.Value = IconDefaultDpiType + "/" + appIconInfo.OutputName + defaultDpi.FileSuffix + IconImageExtension; } else { string dpiValue = icon.Attribute(DpiName).Value; string fileSuffix = dpiValue == IconDefaultDpiType ? "xhigh" : "high"; icon.Value = dpiValue + "/" + appIconInfo.OutputName + fileSuffix + IconImageExtension; } } } var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null; if (splashInfo != null) { var splashscreensElement = uiApplicationElement.Element(xmlns + SplashScreensName); if (splashscreensElement == null) { splashscreensElement = new XElement(xmlns + SplashScreensName); uiApplicationElement.Add(splashscreensElement); } foreach (var image in TizenSplashUpdater.splashDpiMap) { var splashElements = splashscreensElement.Elements(xmlns + SplashScreenName).Where( d => d.Attribute("type")?.Value == "img" && d.Attribute(DpiName)?.Value == image.Key.Resolution && d.Attribute("orientation")?.Value == image.Key.Orientation && d.Attribute("indicator-display")?.Value == "false"); if (splashElements.Count() == 0) { var splashscreenElement = new XElement(xmlns + SplashScreenName); splashscreenElement.SetAttributeValue("src", image.Value); splashscreenElement.SetAttributeValue("type", "img"); splashscreenElement.SetAttributeValue(DpiName, image.Key.Resolution); splashscreenElement.SetAttributeValue("orientation", image.Key.Orientation); splashscreenElement.SetAttributeValue("indicator-display", "false"); splashscreensElement.Add(splashscreenElement); } } } }
void ProcessAppIcon(ResizeImageInfo img, ConcurrentBag <ResizedImageInfo> resizedImages) { var appIconName = img.OutputName; // Generate the actual bitmap app icons themselves var appIconDpis = DpiPath.GetAppIconDpis(PlatformType, appIconName); LogDebugMessage($"App Icon"); // Apple and Android have special additional files to generate for app icons if (PlatformType == "android") { LogDebugMessage($"Android Adaptive Icon Generator"); appIconName = appIconName.ToLowerInvariant(); var adaptiveIconGen = new AndroidAdaptiveIconGenerator(img, appIconName, IntermediateOutputPath, this); var iconsGenerated = adaptiveIconGen.Generate(); foreach (var iconGenerated in iconsGenerated) { resizedImages.Add(iconGenerated); } } else if (PlatformType == "ios") { LogDebugMessage($"iOS Icon Assets Generator"); var appleAssetGen = new AppleIconAssetsGenerator(img, appIconName, IntermediateOutputPath, appIconDpis, this); var assetsGenerated = appleAssetGen.Generate(); foreach (var assetGenerated in assetsGenerated) { resizedImages.Add(assetGenerated); } } LogDebugMessage($"Generating App Icon Bitmaps for DPIs"); var appTool = new SkiaSharpAppIconTools(img, this); LogDebugMessage($"App Icon: Intermediate Path " + IntermediateOutputPath); foreach (var dpi in appIconDpis) { LogDebugMessage($"App Icon: " + dpi); var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath) .Replace("{name}", appIconName); LogDebugMessage($"App Icon Destination: " + destination); appTool.Resize(dpi, Path.ChangeExtension(destination, ".png")); } }
public AppleIconAssetsGenerator(ResizeImageInfo info, string appIconName, string intermediateOutputPath, DpiPath[] dpis, ILogger logger) { Info = info; Logger = logger; IntermediateOutputPath = intermediateOutputPath; AppIconName = appIconName; Dpis = dpis; options = new JsonSerializerOptions { WriteIndented = true }; }
public override bool Execute() { var splash = MauiSplashScreen[0]; var info = ResizeImageInfo.Parse(splash); WriteColors(info); WriteDrawable(info); return(!Log.HasLoggedErrors); }
void ProcessImageCopy(ResizeImageInfo img, DpiPath originalScaleDpi, ConcurrentBag <ResizedImageInfo> resizedImages) { var resizer = new Resizer(img, IntermediateOutputPath, this); LogDebugMessage($"Copying {img.Filename}"); var r = resizer.CopyFile(originalScaleDpi, InputsFile, PlatformType.ToLower().Equals("android")); resizedImages.Add(r); LogDebugMessage($"Copied {img.Filename}"); }
void ProcessImageResize(ResizeImageInfo img, DpiPath[] dpis, ConcurrentBag <ResizedImageInfo> resizedImages) { var resizer = new Resizer(img, IntermediateOutputPath, this); foreach (var dpi in dpis) { LogDebugMessage($"Resizing {img.Filename}"); var r = resizer.Resize(dpi, InputsFile); resizedImages.Add(r); LogDebugMessage($"Resized {img.Filename}"); } }
void WriteDrawable(ResizeImageInfo splash) { Directory.CreateDirectory(Path.GetDirectoryName(DrawableFile)); using var writer = XmlWriter.Create(DrawableFile, Settings); writer.WriteComment(Comment); writer.WriteStartElement("layer-list"); writer.WriteAttributeString("xmlns", "android", ns: null, value: Namespace); writer.WriteStartElement("item"); writer.WriteAttributeString("android", "drawable", Namespace, "@drawable/" + splash.OutputName); writer.WriteEndDocument(); }
public static string GetFileDestination(ResizeImageInfo info, DpiPath dpi, string intermediateOutputPath) { var fullIntermediateOutputPath = new DirectoryInfo(intermediateOutputPath); var destination = Path.Combine(fullIntermediateOutputPath.FullName, dpi.Path, info.OutputName + dpi.FileSuffix + info.OutputExtension); var fileInfo = new FileInfo(destination); if (!fileInfo.Directory.Exists) { fileInfo.Directory.Create(); } return(destination); }
void WriteColors(ResizeImageInfo splash) { Directory.CreateDirectory(Path.GetDirectoryName(ColorsFile)); using var writer = XmlWriter.Create(ColorsFile, Settings); writer.WriteComment(Comment); writer.WriteStartElement("resources"); if (splash.Color is not null) { writer.WriteStartElement("color"); writer.WriteAttributeString("name", "maui_splash_color"); writer.WriteString(splash.Color.ToString()); writer.WriteEndElement(); } writer.WriteEndDocument(); }
public override bool Execute() { var splash = MauiSplashScreen[0]; var colorMetadata = splash.GetMetadata("Color"); var color = Utils.ParseColorString(colorMetadata); if (color == null && !string.IsNullOrEmpty(colorMetadata)) { Log.LogWarning($"Unable to parse color value '{colorMetadata}' for '{splash.ItemSpec}'."); } var fileInfo = new FileInfo(splash.GetMetadata("FullPath")); if (!fileInfo.Exists) { throw new FileNotFoundException("Unable to find background file: " + fileInfo.FullName, fileInfo.FullName); } var img = new ResizeImageInfo { Filename = fileInfo.FullName, Color = color ?? SKColors.Transparent, }; Directory.CreateDirectory(IntermediateOutputPath); var appTool = new SkiaSharpAppIconTools(img, this); Log.LogMessage(MessageImportance.Low, $"Splash Screen: Intermediate Path " + IntermediateOutputPath); foreach (var dpi in DpiPath.Windows.SplashScreen) { Log.LogMessage(MessageImportance.Low, $"Splash Screen: " + dpi); var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath); Log.LogMessage(MessageImportance.Low, $"Splash Screen Destination: " + destination); appTool.Resize(dpi, Path.ChangeExtension(destination, ".png")); } return(!Log.HasLoggedErrors); }
public SkiaSharpAppIconTools(ResizeImageInfo info, ILogger logger) { Info = info; Logger = logger; AppIconName = info.OutputName; hasForeground = File.Exists(info.ForegroundFilename); if (hasForeground) { foregroundTools = SkiaSharpTools.Create(info.ForegroundIsVector, info.ForegroundFilename, null, info.TintColor, logger); } backgroundTools = SkiaSharpTools.Create(info.IsVector, info.Filename, null, null, logger); backgroundOriginalSize = backgroundTools.GetOriginalSize(); if (hasForeground) { foregroundOriginalSize = foregroundTools.GetOriginalSize(); } }
public SkiaSharpAppIconTools(ResizeImageInfo info, ILogger?logger) { Info = info; Logger = logger; AppIconName = info.OutputName; var hasBackground = !string.IsNullOrWhiteSpace(info.Filename) && File.Exists(info.Filename); var hasForeground = !string.IsNullOrWhiteSpace(info.ForegroundFilename) && File.Exists(info.ForegroundFilename); if (!hasBackground && !hasForeground) { throw new InvalidOperationException("An app icon needs at least one image."); } if (hasBackground) { backgroundTools = SkiaSharpTools.Create(info.IsVector, info.Filename, null, null, null, logger); } if (hasForeground) { foregroundTools = SkiaSharpTools.Create(info.ForegroundIsVector, info.ForegroundFilename, null, null, info.TintColor, logger); } }
List <ResizeImageInfo> ParseImageTaskItems(ITaskItem[] images) { var r = new List <ResizeImageInfo>(); if (images == null) { return(r); } foreach (var image in images) { var info = new ResizeImageInfo(); var fileInfo = new FileInfo(image.GetMetadata("FullPath")); if (!fileInfo.Exists) { throw new FileNotFoundException("Unable to find background file: " + fileInfo.FullName, fileInfo.FullName); } info.Filename = fileInfo.FullName; info.Alias = image.GetMetadata("Link"); info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize")); if (bool.TryParse(image.GetMetadata("Resize"), out var rz)) { info.Resize = rz; } info.TintColor = Utils.ParseColorString(image.GetMetadata("TintColor")); if (bool.TryParse(image.GetMetadata("IsAppIcon"), out var iai)) { info.IsAppIcon = iai; } if (float.TryParse(image.GetMetadata("ForegroundScale"), out var fsc)) { info.ForegroundScale = fsc; } var fgFile = image.GetMetadata("ForegroundFile"); if (!string.IsNullOrEmpty(fgFile)) { var fgFileInfo = new FileInfo(fgFile); if (!fgFileInfo.Exists) { throw new FileNotFoundException("Unable to find foreground file: " + fgFileInfo.FullName, fgFileInfo.FullName); } info.ForegroundFilename = fgFileInfo.FullName; } // TODO: // - Parse out custom DPI's r.Add(info); } return(r); }
public WindowsIconGenerator(ResizeImageInfo info, string intermediateOutputPath, ILogger logger) { Info = info; Logger = logger; IntermediateOutputPath = intermediateOutputPath; }
void UpdateManifest(XDocument appx) { var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null; var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null; var imageExtension = ".png"; var xmlns = appx.Root !.GetDefaultNamespace(); // <Identity Name="" Version="" /> if (!string.IsNullOrEmpty(ApplicationId) || !string.IsNullOrEmpty(ApplicationDisplayVersion) || !string.IsNullOrEmpty(ApplicationVersion)) { // <Identity> var xidentity = xmlns + "Identity"; var identity = appx.Root.Element(xidentity); if (identity == null) { identity = new XElement(xidentity); appx.Root.Add(identity); } // Name="" if (!string.IsNullOrEmpty(ApplicationId)) { var xname = "Name"; var attr = identity.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PackageNamePlaceholder) { if (!Guid.TryParse(ApplicationId, out _)) { Log.LogError(ErrorInvalidApplicationId, ApplicationId); return; } identity.SetAttributeValue(xname, ApplicationId); } } // Version="" if (!string.IsNullOrEmpty(ApplicationDisplayVersion) || !string.IsNullOrEmpty(ApplicationVersion)) { var xname = "Version"; var attr = identity.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PackageVersionPlaceholder) { if (!TryMergeVersionNumbers(ApplicationDisplayVersion, ApplicationVersion, out var finalVersion)) { Log.LogError(ErrorVersionNumberCombination, ApplicationDisplayVersion, ApplicationVersion); return; } identity.SetAttributeValue(xname, finalVersion); } } } // <Properties> // <DisplayName /> // <Logo /> // </Properties> if (!string.IsNullOrEmpty(ApplicationTitle) || appIconInfo != null) { // <Properties> var xproperties = xmlns + "Properties"; var properties = appx.Root.Element(xproperties); if (properties == null) { properties = new XElement(xproperties); appx.Root.Add(properties); } // <DisplayName> if (!string.IsNullOrEmpty(ApplicationTitle)) { var xname = xmlns + "DisplayName"; var xelem = properties.Element(xname); if (xelem == null || string.IsNullOrEmpty(xelem.Value) || xelem.Value == DefaultPlaceholder) { properties.SetElementValue(xname, ApplicationTitle); } } // <Logo> if (appIconInfo != null) { var xname = xmlns + "Logo"; var xelem = properties.Element(xname); if (xelem == null || string.IsNullOrEmpty(xelem.Value) || xelem.Value == PngPlaceholder) { var dpi = DpiPath.Windows.StoreLogo[0]; var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension); properties.SetElementValue(xname, path); } } } // <Applications> // <Application> // <uap:VisualElements DisplayName="" Description="" BackgroundColor="" Square150x150Logo="" Square44x44Logo=""> // <uap:DefaultTile Wide310x150Logo="" Square71x71Logo="" Square310x310Logo="" ShortName=""> // <uap:ShowNameOnTiles> // <uap:ShowOn /> // </uap:ShowNameOnTiles> // </uap:DefaultTile> // <uap:SplashScreen Image="" /> // </uap:VisualElements> // </Application> // </Applications> if (!string.IsNullOrEmpty(ApplicationTitle) || appIconInfo != null || splashInfo != null) { // <Applications> var xapplications = xmlns + "Applications"; var applications = appx.Root.Element(xapplications); if (applications == null) { applications = new XElement(xapplications); appx.Root.Add(applications); } // <Application> var xapplication = xmlns + "Application"; var application = applications.Element(xapplication); if (application == null) { application = new XElement(xapplication); applications.Add(application); } // <uap:VisualElements> var xvisual = xmlnsUap + "VisualElements"; var visual = application.Element(xvisual); if (visual == null) { visual = new XElement(xvisual); application.Add(visual); } if (!string.IsNullOrEmpty(ApplicationTitle)) { // DisplayName="" { var xname = "DisplayName"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == DefaultPlaceholder) { visual.SetAttributeValue(xname, ApplicationTitle); } } // Description="" { var xname = "Description"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == DefaultPlaceholder) { visual.SetAttributeValue(xname, ApplicationTitle); } } } // BackgroundColor="" { var xname = "BackgroundColor"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value)) { visual.SetAttributeValue(xname, "transparent"); } } if (appIconInfo != null) { // Square150x150Logo="" { var xname = "Square150x150Logo"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder) { var dpi = DpiPath.Windows.MediumTile[0]; var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension); visual.SetAttributeValue(xname, path); } } // Square44x44Logo="" { var xname = "Square44x44Logo"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder) { var dpi = DpiPath.Windows.Logo[0]; var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension); visual.SetAttributeValue(xname, path); } } } // <uap:DefaultTile> var xtile = xmlnsUap + "DefaultTile"; var tile = visual.Element(xtile); if (tile == null) { tile = new XElement(xtile); visual.Add(tile); } if (appIconInfo != null) { // Wide310x150Logo="" { var xname = "Wide310x150Logo"; var attr = tile.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder) { var dpi = DpiPath.Windows.WideTile[0]; var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension); tile.SetAttributeValue(xname, path); } } // Square71x71Logo="" { var xname = "Square71x71Logo"; var attr = tile.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder) { var dpi = DpiPath.Windows.SmallTile[0]; var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension); tile.SetAttributeValue(xname, path); } } // Square310x310Logo="" { var xname = "Square310x310Logo"; var attr = tile.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder) { var dpi = DpiPath.Windows.LargeTile[0]; var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension); tile.SetAttributeValue(xname, path); } } } // ShortName="" if (!string.IsNullOrEmpty(ApplicationTitle)) { var xname = "ShortName"; var attr = tile.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value)) { tile.SetAttributeValue(xname, ApplicationTitle); } } // <uap:ShowNameOnTiles> var xshowname = xmlnsUap + "ShowNameOnTiles"; var showname = tile.Element(xshowname); if (showname == null) { showname = new XElement(xshowname); tile.Add(showname); } // <ShowOn> var xshowon = xmlnsUap + "ShowOn"; var showons = showname.Elements(xshowon).ToArray(); if (showons.All(x => x.Attribute("Tile")?.Value != "square150x150Logo")) { showname.Add(new XElement(xshowon, new XAttribute("Tile", "square150x150Logo"))); } if (showons.All(x => x.Attribute("Tile")?.Value != "wide310x150Logo")) { showname.Add(new XElement(xshowon, new XAttribute("Tile", "wide310x150Logo"))); } if (splashInfo != null) { // <uap:SplashScreen> var xsplash = xmlnsUap + "SplashScreen"; var splash = visual.Element(xsplash); if (splash == null) { splash = new XElement(xsplash); visual.Add(splash); } // Image="" { var xname = "Image"; var attr = splash.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder) { var dpi = DpiPath.Windows.SplashScreen[0]; var path = Path.Combine(dpi.Path, splashInfo.OutputName + dpi.NameSuffix + imageExtension); splash.SetAttributeValue(xname, path); } } } } }
public SkiaSharpImaginaryTools(ResizeImageInfo info, ILogger logger) : this(info.Color, logger) { }
public Resizer(ResizeImageInfo info, string intermediateOutputPath, ILogger logger) { Info = info; Logger = logger; IntermediateOutputPath = intermediateOutputPath; }
public override System.Threading.Tasks.Task ExecuteAsync() { Svg.SvgDocument.SkipGdiPlusCapabilityCheck = true; var images = ResizeImageInfo.Parse(Images); var dpis = DpiPath.GetDpis(PlatformType); if (dpis == null || dpis.Length <= 0) { return(System.Threading.Tasks.Task.CompletedTask); } var originalScaleDpi = DpiPath.GetOriginal(PlatformType); var resizedImages = new ConcurrentBag <ResizedImageInfo>(); this.ParallelForEach(images, img => { try { var opStopwatch = new Stopwatch(); opStopwatch.Start(); string op; if (img.IsAppIcon) { // App icons are special ProcessAppIcon(img, resizedImages); op = "App Icon"; } else { // By default we resize, but let's make sure if (img.Resize) { ProcessImageResize(img, dpis, resizedImages); op = "Resize"; } else { // Otherwise just copy the thing over to the 1.0 scale ProcessImageCopy(img, originalScaleDpi, resizedImages); op = "Copy"; } } opStopwatch.Stop(); LogDebugMessage($"{op} took {opStopwatch.ElapsedMilliseconds}ms"); } catch (Exception ex) { LogWarning("MAUI0000", ex.ToString()); throw; } }); var copiedResources = new List <TaskItem>(); foreach (var img in resizedImages) { var attr = new Dictionary <string, string>(); string itemSpec = Path.GetFullPath(img.Filename); // Fix the item spec to be relative for mac if (bool.TryParse(IsMacEnabled, out bool isMac) && isMac) { itemSpec = img.Filename; } // Add DPI info to the itemspec so we can use it in the targets attr.Add("_ResizetizerDpiPath", img.Dpi.Path); attr.Add("_ResizetizerDpiScale", img.Dpi.Scale.ToString("0.0", CultureInfo.InvariantCulture)); copiedResources.Add(new TaskItem(itemSpec, attr)); } CopiedResources = copiedResources.ToArray(); return(System.Threading.Tasks.Task.CompletedTask); }
public SkiaSharpBitmapTools(ResizeImageInfo info, ILogger logger) : this(info.Filename, info.BaseSize, info.TintColor, logger) { }
public static List <ResizeImageInfo> Parse(IEnumerable <ITaskItem> images) { var r = new List <ResizeImageInfo>(); if (images == null) { return(r); } foreach (var image in images) { var info = new ResizeImageInfo(); var fileInfo = new FileInfo(image.GetMetadata("FullPath")); if (!fileInfo.Exists) { throw new FileNotFoundException("Unable to find background file: " + fileInfo.FullName, fileInfo.FullName); } info.Filename = fileInfo.FullName; info.Alias = image.GetMetadata("Link"); info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize")); if (bool.TryParse(image.GetMetadata("Resize"), out var rz)) { info.Resize = rz; } else if (info.BaseSize == null && !info.IsVector) { // By default do not resize non-vector images info.Resize = false; } var tintColor = image.GetMetadata("TintColor"); info.TintColor = Utils.ParseColorString(tintColor); if (info.TintColor is null && !string.IsNullOrEmpty(tintColor)) { throw new InvalidDataException($"Unable to parse color value '{tintColor}' for '{info.Filename}'."); } var color = image.GetMetadata("Color"); info.Color = Utils.ParseColorString(color); if (info.Color is null && !string.IsNullOrEmpty(color)) { throw new InvalidDataException($"Unable to parse color value '{color}' for '{info.Filename}'."); } if (bool.TryParse(image.GetMetadata("IsAppIcon"), out var iai)) { info.IsAppIcon = iai; } if (float.TryParse(image.GetMetadata("ForegroundScale"), out var fsc)) { info.ForegroundScale = fsc; } var fgFile = image.GetMetadata("ForegroundFile"); if (!string.IsNullOrEmpty(fgFile)) { var fgFileInfo = new FileInfo(fgFile); if (!fgFileInfo.Exists) { throw new FileNotFoundException("Unable to find foreground file: " + fgFileInfo.FullName, fgFileInfo.FullName); } info.ForegroundFilename = fgFileInfo.FullName; } // make sure the image is a foreground if this is an icon if (info.IsAppIcon && string.IsNullOrEmpty(info.ForegroundFilename)) { info.ForegroundFilename = info.Filename; info.Filename = null; } // TODO: // - Parse out custom DPI's r.Add(info); } return(r); }