diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs index ea2480918c..7567a592fc 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs @@ -2,11 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.CmdPal.Ext.WindowWalker.Components; using Microsoft.CmdPal.Ext.WindowWalker.Properties; using Microsoft.CommandPalette.Extensions; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs index 993429d305..1005625b96 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs @@ -3,10 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.CmdPal.Ext.WindowWalker.Components; using Microsoft.CmdPal.Ext.WindowWalker.Helpers; using Microsoft.CmdPal.Ext.WindowWalker.Properties; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/ExplorerInfoResultCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/ExplorerInfoResultCommand.cs index 86038960cf..fc3bbe3624 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/ExplorerInfoResultCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/ExplorerInfoResultCommand.cs @@ -2,15 +2,8 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Microsoft.CmdPal.Ext.WindowWalker.Components; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -18,10 +11,6 @@ namespace Microsoft.CmdPal.Ext.WindowWalker.Commands; internal sealed partial class ExplorerInfoResultCommand : InvokableCommand { - public ExplorerInfoResultCommand() - { - } - public static bool OpenInShell(string path, string? arguments = null, string? workingDir = null, ShellRunAsType runAs = ShellRunAsType.None, bool runWithHiddenWindow = false) { using var process = new Process(); diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs index c215d0f300..6f08e33c4a 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics; -using System.Drawing; using System.IO; using Microsoft.CmdPal.Ext.WindowWalker.Components; using Microsoft.CmdPal.Ext.WindowWalker.Helpers; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs index cf2625c3a7..929c3b1bf2 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using Microsoft.CmdPal.Ext.WindowWalker.Commands; using Microsoft.CmdPal.Ext.WindowWalker.Helpers; +using Microsoft.CmdPal.Ext.WindowWalker.Pages; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.System; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs index f2428fd6c4..fe50ab370b 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.CmdPal.Ext.WindowWalker.Commands; using Microsoft.CmdPal.Ext.WindowWalker.Helpers; +using Microsoft.CmdPal.Ext.WindowWalker.Pages; using Microsoft.CmdPal.Ext.WindowWalker.Properties; using Microsoft.CommandPalette.Extensions.Toolkit; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/NativeMethods.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/NativeMethods.cs index 57d65a305e..8a0a64f73b 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/NativeMethods.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/NativeMethods.cs @@ -97,14 +97,6 @@ public static partial class NativeMethods [DllImport("user32.dll")] public static extern IntPtr GetShellWindow(); - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool EnumThreadWindows(uint threadId, ShellCommand.EnumThreadDelegate lpfn, IntPtr lParam); - - [DllImport("kernel32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool GetFirmwareType(ref FirmwareType FirmwareType); - [DllImport("advapi32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool OpenProcessToken(SafeProcessHandle processHandle, TokenAccess desiredAccess, out SafeAccessTokenHandle tokenHandle); @@ -265,113 +257,8 @@ public enum HRESULT : uint E_CANCELLED = 0x800704C7, } -/// -/// see learn.microsoft.com -/// -public enum FirmwareType -{ - Unknown = 0, - Bios = 1, - Uefi = 2, - Max = 3, -} - -/// -/// see all STGM values -/// -[Flags] -public enum STGM : long -{ - READ = 0x00000000L, - WRITE = 0x00000001L, - READWRITE = 0x00000002L, - CREATE = 0x00001000L, -} - public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam); -/// -/// Some flags for interop calls to SetWindowPosition -/// -[Flags] -public enum SetWindowPosFlags : uint -{ - /// - /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request. - /// - SWP_ASYNCWINDOWPOS = 0x4000, - - /// - /// Prevents generation of the WM_SYNCPAINT message. - /// - SWP_DEFERERASE = 0x2000, - - /// - /// Draws a frame (defined in the window's class description) around the window. - /// - SWP_DRAWFRAME = 0x0020, - - /// - /// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed. - /// - SWP_FRAMECHANGED = 0x0020, - - /// - /// Hides the window. - /// - SWP_HIDEWINDOW = 0x0080, - - /// - /// Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter). - /// - SWP_NOACTIVATE = 0x0010, - - /// - /// Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned. - /// - SWP_NOCOPYBITS = 0x0100, - - /// - /// Retains the current position (ignores X and Y parameters). - /// - SWP_NOMOVE = 0x0002, - - /// - /// Does not change the owner window's position in the Z order. - /// - SWP_NOOWNERZORDER = 0x0200, - - /// - /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing. - /// - SWP_NOREDRAW = 0x0008, - - /// - /// Same as the SWP_NOOWNERZORDER flag. - /// - SWP_NOREPOSITION = 0x0200, - - /// - /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message. - /// - SWP_NOSENDCHANGING = 0x0400, - - /// - /// Retains the current size (ignores the cx and cy parameters). - /// - SWP_NOSIZE = 0x0001, - - /// - /// Retains the current Z order (ignores the hWndInsertAfter parameter). - /// - SWP_NOZORDER = 0x0004, - - /// - /// Displays the window. - /// - SWP_SHOWWINDOW = 0x0040, -} - /// /// Options for DwmpActivateLivePreview /// @@ -655,16 +542,6 @@ public enum ProcessAccessFlags AllAccess = StandardRightsRequired | Synchronize | 0xFFFF, } -[StructLayout(LayoutKind.Sequential)] -public struct GUIDDATA -{ - public int Data1; - public short Data2; - public short Data3; - [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 8)] - public byte[] Data4; -} - /// /// Contains information about the placement of a window on the screen. /// @@ -920,7 +797,7 @@ public struct POINT : IEquatable { if (obj is POINT pt) { - return this.X == pt.X && this.Y == pt.X; + return X == pt.X && Y == pt.X; } return false; @@ -1145,22 +1022,6 @@ public enum ExtendedWindowStyles : uint WS_EX_NOACTIVATE = 0x8000000, } -/// -/// The following are ShellItem DisplayName types. -/// -[Flags] -public enum SIGDN : uint -{ - NORMALDISPLAY = 0, - PARENTRELATIVEPARSING = 0x80018001, - PARENTRELATIVEFORADDRESSBAR = 0x8001c001, - DESKTOPABSOLUTEPARSING = 0x80028000, - PARENTRELATIVEEDITING = 0x80031001, - DESKTOPABSOLUTEEDITING = 0x8004c000, - FILESYSPATH = 0x80058000, - URL = 0x80068000, -} - internal enum TOKEN_INFORMATION_CLASS { TokenIsAppContainer = 29, diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/OSVersionHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/OSVersionHelper.cs index dc6c9afbae..3e06b78f2e 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/OSVersionHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/OSVersionHelper.cs @@ -12,9 +12,4 @@ public static class OSVersionHelper { return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 22000; } - - public static bool IsGreaterThanWindows11_21H2() - { - return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build > 22000; - } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ProcessPackagingInspector.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ProcessPackagingInspector.cs index 43d77d1aba..33453ccf72 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ProcessPackagingInspector.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ProcessPackagingInspector.cs @@ -2,7 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32.SafeHandles; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs index 1b223fea9b..ce1b5f56d8 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs @@ -123,7 +123,7 @@ public class SettingsManager : JsonSettingsManager, ISettingsInterface // Load settings from file upon initialization LoadSettings(); - Settings.SettingsChanged += (s, a) => this.SaveSettings(); + Settings.SettingsChanged += (_, _) => SaveSettings(); } internal static SettingsManager Instance diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ShellCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ShellCommand.cs deleted file mode 100644 index a09dc78648..0000000000 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ShellCommand.cs +++ /dev/null @@ -1,83 +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 System; -using System.Diagnostics; -using System.Text; -using System.Threading; - -namespace Microsoft.CmdPal.Ext.WindowWalker.Helpers; - -public static class ShellCommand -{ - public delegate bool EnumThreadDelegate(IntPtr hwnd, IntPtr lParam); - - private static bool containsSecurityWindow; - - public static Process? RunAsDifferentUser(ProcessStartInfo processStartInfo) - { - ArgumentNullException.ThrowIfNull(processStartInfo); - - processStartInfo.Verb = "RunAsUser"; - var process = Process.Start(processStartInfo); - - containsSecurityWindow = false; - - // wait for windows to bring up the "Windows Security" dialog - while (!containsSecurityWindow) - { - CheckSecurityWindow(); - Thread.Sleep(25); - } - - // while this process contains a "Windows Security" dialog, stay open - while (containsSecurityWindow) - { - containsSecurityWindow = false; - CheckSecurityWindow(); - Thread.Sleep(50); - } - - return process; - } - - private static void CheckSecurityWindow() - { - ProcessThreadCollection ptc = Process.GetCurrentProcess().Threads; - for (var i = 0; i < ptc.Count; i++) - { - NativeMethods.EnumThreadWindows((uint)ptc[i].Id, CheckSecurityThread, IntPtr.Zero); - } - } - - private static bool CheckSecurityThread(IntPtr hwnd, IntPtr lParam) - { - if (GetWindowTitle(hwnd) == "Windows Security") - { - containsSecurityWindow = true; - } - - return true; - } - - private static string GetWindowTitle(IntPtr hwnd) - { - StringBuilder sb = new StringBuilder(NativeMethods.GetWindowTextLength(hwnd) + 1); - _ = NativeMethods.GetWindowText(hwnd, sb, sb.Capacity); - return sb.ToString(); - } - - public static ProcessStartInfo SetProcessStartInfo(this string fileName, string workingDirectory = "", string arguments = "", string verb = "") - { - var info = new ProcessStartInfo - { - FileName = fileName, - WorkingDirectory = workingDirectory, - Arguments = arguments, - Verb = verb, - }; - - return info; - } -} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/VirtualDesktopHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/VirtualDesktopHelper.cs index 131ec7ae82..886c376749 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/VirtualDesktopHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/VirtualDesktopHelper.cs @@ -55,7 +55,7 @@ public class VirtualDesktopHelper /// private Guid _currentDesktop; - private static readonly CompositeFormat VirtualDesktopHelperDesktop = System.Text.CompositeFormat.Parse(Properties.Resources.VirtualDesktopHelper_Desktop); + private static readonly CompositeFormat VirtualDesktopHelperDesktop = CompositeFormat.Parse(Resources.VirtualDesktopHelper_Desktop); /// /// Initializes a new instance of the class. diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/Win32Helpers.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/Win32Helpers.cs index 682c7fdfc4..ae6d02c184 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/Win32Helpers.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/Win32Helpers.cs @@ -9,17 +9,6 @@ namespace Microsoft.CmdPal.Ext.WindowWalker.Helpers; public static class Win32Helpers { - /// - /// Detects the type of system firmware which is equal to the boot type by calling the method . - /// - /// Firmware type like Uefi or Bios. - public static FirmwareType GetSystemFirmwareType() - { - FirmwareType firmwareType = default; - _ = NativeMethods.GetFirmwareType(ref firmwareType); - return firmwareType; - } - /// /// Returns the last Win32 Error code thrown by a native method if enabled for this method. /// @@ -44,14 +33,4 @@ public static class Win32Helpers return NativeMethods.CloseHandle(handle); } - - /// - /// Gets the description for an HRESULT error code. - /// - /// The HRESULT number - /// A string containing the description. - public static string MessageFromHResult(int hr) - { - return Marshal.GetExceptionForHR(hr)?.Message ?? string.Empty; - } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/WindowWalkerListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListItem.cs similarity index 79% rename from src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/WindowWalkerListItem.cs rename to src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListItem.cs index 72e648387e..47037bf1b4 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/WindowWalkerListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListItem.cs @@ -2,16 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.CmdPal.Ext.WindowWalker.Commands; using Microsoft.CmdPal.Ext.WindowWalker.Components; using Microsoft.CommandPalette.Extensions.Toolkit; -namespace Microsoft.CmdPal.Ext.WindowWalker; +namespace Microsoft.CmdPal.Ext.WindowWalker.Pages; internal sealed partial class WindowWalkerListItem : ListItem {