mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
[PT Run] Refactoring: combined all NativeMethods.cs files for plugins… (#15807)
* [PT Run] Refactoring: combined all NativeMethods.cs files for plugins into Wox.Plugin/Common/Win32/ * Fixed spell check * [PT Run] Changed NativeMethods.Helpers to Win32Helpers (seperate class) to not conflict with Microsoft.PowerToys.Settings.UI.Library.Helpers * [PT Run] Renamed Constants.cs to ConstantsAndStructs.cs and moved all of them from NativeMethods.cs * [PT Run] Merged ConstantsAndStructs.cs into NativeMethods.cs and renamed Constants to Win32Constants to avoid conflicting * [PT Run] Added missing summaries + fixed missed refactored method * [PT Run] Use using directive instead of alias + updated method call for .Net 6 * [PT Run] Fixed missed using alias + spell check
This commit is contained in:
@@ -8,14 +8,13 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Run.Plugin.System.Properties;
|
||||
using Microsoft.PowerToys.Run.Plugin.System.Win32;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Common.Win32;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
{
|
||||
@@ -36,8 +35,6 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
|
||||
public bool IsBootedInUefiMode { get; set; }
|
||||
|
||||
public ICommand Command { get; set; }
|
||||
|
||||
public string Name => Resources.Microsoft_plugin_sys_plugin_name;
|
||||
|
||||
public string Description => Resources.Microsoft_plugin_sys_plugin_description;
|
||||
@@ -66,13 +63,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
_context = context;
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconTheme(_context.API.GetCurrentTheme());
|
||||
IsBootedInUefiMode = NativeMethods.GetSystemFirmwareType() == NativeMethods.FirmwareTypes.Uefi;
|
||||
IsBootedInUefiMode = Win32Helpers.GetSystemFirmwareType() == FirmwareType.Uefi;
|
||||
|
||||
// Log info if the system hasn't boot in uefi mode.
|
||||
// (Because this is only going into the log we can ignore the fact that normally UEFI and BIOS are written upper case. No need to convert the enumeration value to upper case.)
|
||||
if (!IsBootedInUefiMode)
|
||||
{
|
||||
Wox.Plugin.Logger.Log.Info($"The UEFI command will not show to the user. The system has not booted in UEFI mode or the system does not have an UEFI firmware! (Detected type: {NativeMethods.GetSystemFirmwareType()})", typeof(Main));
|
||||
Wox.Plugin.Logger.Log.Info($"The UEFI command will not show to the user. The system has not booted in UEFI mode or the system does not have an UEFI firmware! (Detected type: {Win32Helpers.GetSystemFirmwareType()})", typeof(Main));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +180,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
// FYI, couldn't find documentation for this but if the recycle bin is already empty, it will return -2147418113 (0x8000FFFF (E_UNEXPECTED))
|
||||
// 0 for nothing
|
||||
var result = NativeMethods.SHEmptyRecycleBin(new WindowInteropHelper(Application.Current.MainWindow).Handle, 0);
|
||||
if (result != (uint)NativeMethods.HRESULT.S_OK && result != 0x8000FFFF)
|
||||
if (result != (uint)HRESULT.S_OK && result != 0x8000FFFF)
|
||||
{
|
||||
var name = "Plugin: " + Resources.Microsoft_plugin_sys_plugin_name;
|
||||
var message = $"Error emptying recycle bin, error code: {result}\n" +
|
||||
|
||||
@@ -1,54 +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.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.System.Win32
|
||||
{
|
||||
internal class NativeMethods
|
||||
{
|
||||
[DllImport("user32")]
|
||||
internal static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern void LockWorkStation();
|
||||
|
||||
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
|
||||
internal static extern uint SHEmptyRecycleBin(IntPtr hWnd, uint dwFlags);
|
||||
|
||||
[DllImport("Powrprof.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
|
||||
internal static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
internal static extern bool GetFirmwareType(ref uint FirmwareType);
|
||||
|
||||
// http://www.pinvoke.net/default.aspx/Enums/HRESULT.html
|
||||
public enum HRESULT : uint
|
||||
{
|
||||
S_FALSE = 0x0001,
|
||||
S_OK = 0x0000,
|
||||
}
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-firmware_type
|
||||
public enum FirmwareTypes
|
||||
{
|
||||
Unknown = 0,
|
||||
Bios,
|
||||
Uefi,
|
||||
Max,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the type of system firmware which is equal to the boot type by calling the method <see cref="NativeMethods.GetFirmwareType(ref uint)"/>.
|
||||
/// </summary>
|
||||
/// <returns>Firmware type like Uefi or Bios.</returns>
|
||||
internal static FirmwareTypes GetSystemFirmwareType()
|
||||
{
|
||||
uint firmwareType = 0;
|
||||
_ = GetFirmwareType(ref firmwareType);
|
||||
return (FirmwareTypes)firmwareType;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user