[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:
cyberrex5
2022-02-10 23:44:19 +02:00
committed by GitHub
parent 57a8d505c0
commit 416419ffde
19 changed files with 1198 additions and 1182 deletions

View File

@@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using static Microsoft.Plugin.Program.Programs.UWP;
using Wox.Plugin.Common.Win32;
namespace Microsoft.Plugin.Program.Programs
{
@@ -33,9 +33,9 @@ namespace Microsoft.Plugin.Program.Programs
}
}
public static T CheckHRAndReturnOrThrow<T>(Hresult hr, T result)
public static T CheckHRAndReturnOrThrow<T>(HRESULT hr, T result)
{
if (hr != Hresult.Ok)
if (hr != HRESULT.S_OK)
{
Marshal.ThrowExceptionForHR((int)hr);
}

View File

@@ -4,7 +4,7 @@
using System;
using System.Runtime.InteropServices;
using static Microsoft.Plugin.Program.Programs.UWP;
using Wox.Plugin.Common.Win32;
namespace Microsoft.Plugin.Program.Programs
{
@@ -13,9 +13,9 @@ namespace Microsoft.Plugin.Program.Programs
public interface IAppxManifestApplication
{
[PreserveSig]
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
HRESULT GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
[PreserveSig]
Hresult GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string value);
HRESULT GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string value);
}
}

View File

@@ -4,7 +4,7 @@
using System;
using System.Runtime.InteropServices;
using static Microsoft.Plugin.Program.Programs.UWP;
using Wox.Plugin.Common.Win32;
namespace Microsoft.Plugin.Program.Programs
{
@@ -13,9 +13,9 @@ namespace Microsoft.Plugin.Program.Programs
public interface IAppxManifestProperties
{
[PreserveSig]
Hresult GetBoolValue([MarshalAs(UnmanagedType.LPWStr)] string name, out bool value);
HRESULT GetBoolValue([MarshalAs(UnmanagedType.LPWStr)] string name, out bool value);
[PreserveSig]
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
HRESULT GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
}
}

View File

@@ -11,7 +11,7 @@ using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Linq;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32;
using Wox.Plugin.Common.Win32;
using Wox.Plugin.Logger;
namespace Microsoft.Plugin.Program.Programs
@@ -63,10 +63,10 @@ namespace Microsoft.Plugin.Program.Programs
InitPackageVersion(namespaces);
const uint noAttribute = 0x80;
const Stgm exclusiveRead = Stgm.Read;
const STGM exclusiveRead = STGM.READ;
var hResult = NativeMethods.SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out IStream stream);
if (hResult == Hresult.Ok)
if (hResult == HRESULT.S_OK)
{
Apps = AppxPackageHelper.GetAppsFromManifest(stream).Select(appInManifest => new UWPApplication(appInManifest, this)).Where(a =>
{
@@ -214,17 +214,5 @@ namespace Microsoft.Plugin.Program.Programs
Windows8,
Unknown,
}
[Flags]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1714:Flags enums should have plural names", Justification = "This name is consistent with the corresponding win32 flags: https://docs.microsoft.com/en-us/windows/win32/stg/stgm-constants ")]
public enum Stgm : long
{
Read = 0x00000000L,
}
public enum Hresult : int
{
Ok = 0x0,
}
}
}

View File

@@ -20,13 +20,13 @@ using System.Windows.Media.Imaging;
using System.Xml;
using ManagedCommon;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32;
using Wox.Infrastructure;
using Wox.Infrastructure.Image;
using Wox.Plugin;
using Wox.Plugin.Common;
using Wox.Plugin.Common.Win32;
using Wox.Plugin.Logger;
using static Microsoft.Plugin.Program.Programs.UWP;
using PackageVersion = Microsoft.Plugin.Program.Programs.UWP.PackageVersion;
namespace Microsoft.Plugin.Program.Programs
{
@@ -331,7 +331,7 @@ namespace Microsoft.Plugin.Program.Programs
string source = $"@{{{packageFullName}? {parsed}}}";
var capacity = (uint)outBuffer.Capacity;
var hResult = NativeMethods.SHLoadIndirectString(source, outBuffer, capacity, IntPtr.Zero);
if (hResult == Hresult.Ok)
if (hResult == HRESULT.S_OK)
{
var loaded = outBuffer.ToString();
if (!string.IsNullOrEmpty(loaded))

View File

@@ -1,21 +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;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using static Microsoft.Plugin.Program.Programs.UWP;
namespace Microsoft.Plugin.Program.Win32
{
internal class NativeMethods
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
internal static extern Hresult SHCreateStreamOnFileEx(string fileName, Stgm grfMode, uint attributes, bool create, IStream reserved, out IStream stream);
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
internal static extern Hresult SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved);
}
}