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); }
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); } } } }
public override bool Execute() { var splash = MauiSplashScreen[0]; var info = ResizeImageInfo.Parse(splash); WriteColors(info); WriteDrawable(info); return(!Log.HasLoggedErrors); }
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 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); }