diff --git a/src/SingleProject/Resizetizer/src/ResizetizeImages.cs b/src/SingleProject/Resizetizer/src/ResizetizeImages.cs index 51670cbb0f98..746501e2bc2c 100644 --- a/src/SingleProject/Resizetizer/src/ResizetizeImages.cs +++ b/src/SingleProject/Resizetizer/src/ResizetizeImages.cs @@ -90,7 +90,9 @@ public override System.Threading.Tasks.Task ExecuteAsync() if (PlatformType == "tizen") { var tizenResourceXmlGenerator = new TizenResourceXmlGenerator(IntermediateOutputPath, Logger); - tizenResourceXmlGenerator.Generate(); + var r = tizenResourceXmlGenerator.Generate(); + if (r is not null) + resizedImages.Add(r); } var copiedResources = new List(); @@ -178,10 +180,13 @@ void ProcessAppIcon(ResizeImageInfo img, ConcurrentBag resized if (destinationModified > sourceModified) { Logger.Log($"Skipping `{img.Filename}` => `{destination}` file is up to date."); + resizedImages.Add(new ResizedImageInfo() { Dpi = dpi, Filename = destination }); continue; } appTool.Resize(dpi, destination); + var r = appTool.Resize(dpi, destination); + resizedImages.Add(r); } } diff --git a/src/SingleProject/Resizetizer/src/TizenResourceXmlGenerator.cs b/src/SingleProject/Resizetizer/src/TizenResourceXmlGenerator.cs index ebb2e2f3cef4..ff04a4efc68a 100644 --- a/src/SingleProject/Resizetizer/src/TizenResourceXmlGenerator.cs +++ b/src/SingleProject/Resizetizer/src/TizenResourceXmlGenerator.cs @@ -27,7 +27,7 @@ public TizenResourceXmlGenerator(string intermediateOutputPath, ILogger logger) public ILogger Logger { get; private set; } - public void Generate() + public ResizedImageInfo Generate() { XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); @@ -54,12 +54,13 @@ public void Generate() string outputResourceDir = Path.Combine(IntermediateOutputPath, "res"); string outputContentsDir = Path.Combine(outputResourceDir, "contents"); + string destination = Path.Combine(outputResourceDir, "res.xml"); var contentsDirInfo = new DirectoryInfo(outputContentsDir); if (!contentsDirInfo.Exists) { Logger.Log("No 'res/contents/' directory to generate res.xml."); - return; + return null; } foreach (DirectoryInfo subDir in contentsDirInfo.GetDirectories()) { @@ -80,8 +81,9 @@ public void Generate() } } } - doc.Save(Path.Combine(outputResourceDir, "res.xml")); + doc.Save(destination); Logger.Log($"res.xml file has been saved in {outputResourceDir}"); + return new ResizedImageInfo() { Dpi = DpiPath.Tizen.Original, Filename = destination }; } } } diff --git a/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets b/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets index e3f1972e7c44..214c830bfb6d 100644 --- a/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets +++ b/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets @@ -386,6 +386,7 @@ MauiSplashScreen="@(MauiSplashScreen)" InputsFile="$(_MauiSplashInputsFile)" /> + <_MauiSplashAssets Include="$(_MauiIntermediateSplashScreen)**\*" /> @@ -579,15 +580,25 @@ IntermediateOutputPath="$(_MauiIntermediateImages)" InputsFile="$(_ResizetizerInputsFile)" Images="@(MauiImage->Distinct())"> + - <_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" /> - <_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(_MauiIntermediateImages)**\*" /> + <_ResizetizerCollectedImages Condition="'@(_CopiedResources->Count())' != '0'" Include="@(_CopiedResources)" /> + <_ResizetizerExistingImages Include="$(_MauiIntermediateImages)\**\*" /> + <_ResizetizerImagesToDelete Include="@(_ResizetizerExistingImages->'%(FullPath)')" /> + <_ResizetizerCollectedImages Condition="'@(_CopiedResources)' == ''" Include="@(_ResizetizerExistingImages->'%(FullPath)')" /> + <_ResizetizerImagesToDelete Remove="@(_ResizetizerCollectedImages)" /> + + + diff --git a/src/SingleProject/Resizetizer/test/UnitTests/ResizetizeImagesTests.cs b/src/SingleProject/Resizetizer/test/UnitTests/ResizetizeImagesTests.cs index 8bfe2acecac8..ada01f9e1899 100644 --- a/src/SingleProject/Resizetizer/test/UnitTests/ResizetizeImagesTests.cs +++ b/src/SingleProject/Resizetizer/test/UnitTests/ResizetizeImagesTests.cs @@ -676,6 +676,43 @@ public void DiffPropoprtionAppIconWithoutBaseUseBackgroundSize(double fgScale, s AssertFileMatches($"mipmap-xhdpi/{Path.GetFileNameWithoutExtension(bg)}_foreground.png", new object[] { fgScale, bg, fg, "xh", "f" }); } + [Fact] + public void NonExistantFilesAreDeleted() + { + var items = new[] + { + new TaskItem("images/camera.svg", new Dictionary + { + ["Link"] = "dog", + }), + }; + + var task = GetNewTask(items); + var success = task.Execute(); + Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message); + + AssertFileNotExists("drawable-hdpi/cat.png"); + AssertFileExists("drawable-hdpi/dog.png"); + + LogErrorEvents.Clear(); + LogMessageEvents.Clear(); + + items = new[] + { + new TaskItem("images/camera.svg", new Dictionary + { + ["Link"] = "cat", + }), + }; + + task = GetNewTask(items); + success = task.Execute(); + Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message); + + AssertFileNotExists("drawable-hdpi/dot.png"); + AssertFileExists("drawable-hdpi/cat.png"); + } + //[Theory] //[InlineData(1, 1, "dotnet_background.svg", "tall_image.png", 300, 300)] //[InlineData(1, 1, "dotnet_background.svg", "wide_image.png", 300, 300)] @@ -1015,6 +1052,43 @@ public void SingleVectorAppIconWithOnlyPathSucceedsWithVectors(string name, stri $"\"filename\": \"{outputName}20x20@2x.png\"", $"\"size\": \"20x20\","); } + + [Fact] + public void NonExistantFilesAreDeleted() + { + var items = new[] + { + new TaskItem("images/camera.svg", new Dictionary + { + ["Link"] = "dog", + }), + }; + + var task = GetNewTask(items); + var success = task.Execute(); + Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message); + + AssertFileNotExists("cat.png"); + AssertFileExists("dog.png"); + + LogErrorEvents.Clear(); + LogMessageEvents.Clear(); + + items = new[] + { + new TaskItem("images/camera.svg", new Dictionary + { + ["Link"] = "cat", + }), + }; + + task = GetNewTask(items); + success = task.Execute(); + Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message); + + AssertFileNotExists("dot.png"); + AssertFileExists("cat.png"); + } } public class ExecuteForWindows : ExecuteForApp @@ -1335,6 +1409,43 @@ public void ColorsInCssCanBeUsed() AssertFileContains("not_working.scale-100.png", 0xFF71559B, 2, 6); } + + [Fact] + public void NonExistantFilesAreDeleted() + { + var items = new[] + { + new TaskItem("images/camera.svg", new Dictionary + { + ["Link"] = "dog", + }), + }; + + var task = GetNewTask(items); + var success = task.Execute(); + Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message); + + AssertFileNotExists("cat.scale-150.png"); + AssertFileExists("dog.scale-150.png"); + + LogErrorEvents.Clear(); + LogMessageEvents.Clear(); + + items = new[] + { + new TaskItem("images/camera.svg", new Dictionary + { + ["Link"] = "cat", + }), + }; + + task = GetNewTask(items); + success = task.Execute(); + Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message); + + AssertFileNotExists("dot.scale-150.png"); + AssertFileExists("cat.scale-150.png"); + } } public class ExecuteForAny : ExecuteForApp