Compare commits

..

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
326eeacfdf Fix: Prevent backup directory creation during dry runs
Co-authored-by: yeelam-gordon <73506701+yeelam-gordon@users.noreply.github.com>
2025-08-29 05:54:09 +00:00
copilot-swe-agent[bot]
46b81144c5 Initial plan 2025-08-29 05:44:56 +00:00
3 changed files with 11 additions and 49 deletions

View File

@@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows;
namespace ColorPicker.Helpers
{
[TestClass]
public class ZoomWindowHelperTest
{
[TestMethod]
public void ZoomWindowHelper_ShouldHandleBasicOperations()
{
// Note: Full testing of ZoomWindowHelper requires WPF application context
// This test documents that the UI hiding fix is in the SetZoomImage method
// which temporarily sets Application.Current.MainWindow.Opacity = 0 during screen capture
// to prevent the Color Picker UI from appearing in the zoomed image.
// The fix addresses the issue where CopyFromScreen was capturing the visible UI elements
// By temporarily hiding the main window (opacity = 0) before screen capture,
// then restoring the original opacity, the zoom feature now shows clean images
// without Color Picker UI artifacts.
Assert.IsTrue(true, "ZoomWindowHelper UI hiding fix implemented in SetZoomImage method");
}
}
}

View File

@@ -82,19 +82,7 @@ namespace ColorPicker.Helpers
var x = (int)point.X - (BaseZoomImageSize / 2);
var y = (int)point.Y - (BaseZoomImageSize / 2);
// Temporarily hide the color picker UI to avoid capturing it in the zoom
var originalOpacity = System.Windows.Application.Current.MainWindow.Opacity;
System.Windows.Application.Current.MainWindow.Opacity = 0;
try
{
_graphics.CopyFromScreen(x, y, 0, 0, _bmp.Size, CopyPixelOperation.SourceCopy);
}
finally
{
// Restore the original opacity
System.Windows.Application.Current.MainWindow.Opacity = originalOpacity;
}
_graphics.CopyFromScreen(x, y, 0, 0, _bmp.Size, CopyPixelOperation.SourceCopy);
_zoomViewModel.ZoomArea = BitmapToImageSource(_bmp);
}

View File

@@ -653,11 +653,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library
return (false, "General_SettingsBackupAndRestore_InvalidBackupLocation", "Error", lastBackupExists, "\n" + appBasePath);
}
var dirExists = TryCreateDirectory(settingsBackupAndRestoreDir);
if (!dirExists)
// Only create the backup directory if this is not a dry run
if (!dryRun)
{
Logger.LogError($"Failed to create dir {settingsBackupAndRestoreDir}");
return (false, $"General_SettingsBackupAndRestore_BackupError", "Error", lastBackupExists, "\n" + settingsBackupAndRestoreDir);
var dirExists = TryCreateDirectory(settingsBackupAndRestoreDir);
if (!dirExists)
{
Logger.LogError($"Failed to create dir {settingsBackupAndRestoreDir}");
return (false, $"General_SettingsBackupAndRestore_BackupError", "Error", lastBackupExists, "\n" + settingsBackupAndRestoreDir);
}
}
// get data needed for process
@@ -717,12 +721,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
var relativePath = currentFile.Value.Substring(appBasePath.Length + 1);
var backupFullPath = Path.Combine(fullBackupDir, relativePath);
TryCreateDirectory(fullBackupDir);
TryCreateDirectory(Path.GetDirectoryName(backupFullPath));
Logger.LogInfo($"BackupSettings writing, {backupFullPath}, dryRun:{dryRun}.");
if (!dryRun)
{
TryCreateDirectory(fullBackupDir);
TryCreateDirectory(Path.GetDirectoryName(backupFullPath));
File.WriteAllText(backupFullPath, currentSettingsFileToBackup);
}
}