mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +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:
1094
src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs
Normal file
1094
src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs
Normal file
File diff suppressed because it is too large
Load Diff
48
src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs
Normal file
48
src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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 Wox.Plugin.Common.Win32
|
||||
{
|
||||
public static class Win32Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Detects the type of system firmware which is equal to the boot type by calling the method <see cref="NativeMethods.GetFirmwareType"/>.
|
||||
/// </summary>
|
||||
/// <returns>Firmware type like Uefi or Bios.</returns>
|
||||
public static FirmwareType GetSystemFirmwareType()
|
||||
{
|
||||
FirmwareType firmwareType = default;
|
||||
_ = NativeMethods.GetFirmwareType(ref firmwareType);
|
||||
return firmwareType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the last Win32 Error code thrown by a native method if enabled for this method.
|
||||
/// </summary>
|
||||
/// <returns>The error code as int value.</returns>
|
||||
public static int GetLastError()
|
||||
{
|
||||
return Marshal.GetLastPInvokeError();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate that the handle is not null and close it.
|
||||
/// </summary>
|
||||
/// <param name="handle">Handle to close.</param>
|
||||
/// <returns>Zero if native method fails and nonzero if the native method succeeds.</returns>
|
||||
public static bool CloseHandleIfNotNull(IntPtr handle)
|
||||
{
|
||||
if (handle == IntPtr.Zero)
|
||||
{
|
||||
// Return true if there is nothing to close.
|
||||
return true;
|
||||
}
|
||||
|
||||
return NativeMethods.CloseHandle(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user