From 8b79da5d49aaa2f5fb63d731bb8881b8d34ba673 Mon Sep 17 00:00:00 2001 From: leileizhang Date: Tue, 13 Jan 2026 12:36:14 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Image=20Resizer=20doesn=E2=80=99t=20work?= =?UTF-8?q?=20when=20using=20the=20UI.=20(#44687)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary of the Pull Request 1. Update the CLI Log Folder 2. Fixes an `ArgumentOutOfRangeException` that occurs in ImageResizer when the `CustomSize` or `AiSize` properties change. image Changed the collection changed notification from `Replace` to `Reset` for both `CustomSize` and `AiSize` property changes. While `Reset` is less efficient (it forces a full UI refresh rather than updating a single item), it avoids the index validation issue since it doesn't require specifying an index. ## PR Checklist - [x] Closes: #44686 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- .../imageresizer/ImageResizerCLI/Program.cs | 2 +- .../tests/Properties/SettingsTests.cs | 11 ++++------- .../imageresizer/ui/Properties/Settings.cs | 16 ++-------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/modules/imageresizer/ImageResizerCLI/Program.cs b/src/modules/imageresizer/ImageResizerCLI/Program.cs index 4716730995..d24ab93bde 100644 --- a/src/modules/imageresizer/ImageResizerCLI/Program.cs +++ b/src/modules/imageresizer/ImageResizerCLI/Program.cs @@ -31,7 +31,7 @@ internal static class Program Console.InputEncoding = Encoding.Unicode; // Initialize logger to file (same as other modules) - CliLogger.Initialize("\\ImageResizer\\Logs"); + CliLogger.Initialize("\\Image Resizer\\CLI"); CliLogger.Info($"ImageResizerCLI started with {args.Length} argument(s)"); try diff --git a/src/modules/imageresizer/tests/Properties/SettingsTests.cs b/src/modules/imageresizer/tests/Properties/SettingsTests.cs index ed182556a3..16cbceae6e 100644 --- a/src/modules/imageresizer/tests/Properties/SettingsTests.cs +++ b/src/modules/imageresizer/tests/Properties/SettingsTests.cs @@ -126,13 +126,10 @@ namespace ImageResizer.Properties h => ncc.CollectionChanged -= h, () => settings.CustomSize = new CustomSize()); - Assert.AreEqual(NotifyCollectionChangedAction.Replace, result.Arguments.Action); - Assert.AreEqual(1, result.Arguments.NewItems.Count); - Assert.AreEqual(settings.CustomSize, result.Arguments.NewItems[0]); - Assert.AreEqual(0, result.Arguments.NewStartingIndex); - Assert.AreEqual(1, result.Arguments.OldItems.Count); - Assert.AreEqual(originalCustomSize, result.Arguments.OldItems[0]); - Assert.AreEqual(0, result.Arguments.OldStartingIndex); + // Reset is used instead of Replace to avoid ArgumentOutOfRangeException + // when notifying changes for virtual items (CustomSize/AiSize) that exist + // outside the bounds of the underlying _sizes collection. + Assert.AreEqual(NotifyCollectionChangedAction.Reset, result.Arguments.Action); } [TestMethod] diff --git a/src/modules/imageresizer/ui/Properties/Settings.cs b/src/modules/imageresizer/ui/Properties/Settings.cs index 542f82e0a8..a6b535a782 100644 --- a/src/modules/imageresizer/ui/Properties/Settings.cs +++ b/src/modules/imageresizer/ui/Properties/Settings.cs @@ -216,27 +216,15 @@ namespace ImageResizer.Properties { if (e.PropertyName == nameof(Models.CustomSize)) { - var oldCustomSize = _customSize; _customSize = settings.CustomSize; - OnCollectionChanged( - new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Replace, - _customSize, - oldCustomSize, - _sizes.Count)); + OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } else if (e.PropertyName == nameof(Models.AiSize)) { - var oldAiSize = _aiSize; _aiSize = settings.AiSize; - OnCollectionChanged( - new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Replace, - _aiSize, - oldAiSize, - _sizes.Count + 1)); + OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } else if (e.PropertyName == nameof(Sizes)) {