Files
LanMountainDesktop/LanMountainDesktop.Platform.Windows/WindowsPackageIdentity.cs
lincube 9b7a35ddd3 refactor: 新建 Platform 平台差异层,主工程 P/Invoke 全部迁出
- 新增 Platform.Abstractions(接口+NoOp+PlatformLog 日志桥)、
  Platform.Windows、Platform.MacOS、Platform.Android 四个项目
- 迁移电源管理、原生对话框、桌面层嵌入、窗口置底/区域穿透、
  DWM 互操作、图标服务、包标识查询等全部 Windows P/Invoke 实现
- 主工程保留静态工厂门面,调用点不变;DllImport 扫描为零
- 更新 WindowPassthroughServiceTests 指向新位置(20/20 通过)
2026-07-26 22:14:46 +09:00

44 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Runtime.InteropServices;
using System.Text;
namespace LanMountainDesktop.Platform.Windows;
/// <summary>
/// Windows 包标识查询MSIX/UWP 打包检测)。
/// </summary>
public static class WindowsPackageIdentity
{
private const int AppmodelErrorNoPackage = 15700;
/// <summary>
/// 检测当前进程是否具有包标识(以 MSIX 打包运行)。
/// 非 Windows 平台返回 false。
/// </summary>
public static bool HasPackageIdentity()
{
if (!OperatingSystem.IsWindows())
{
return false;
}
var length = 0;
var hr = GetCurrentPackageFullName(ref length, null);
if (hr == AppmodelErrorNoPackage)
{
return false;
}
if (length <= 0)
{
return hr == 0;
}
var builder = new StringBuilder(length);
hr = GetCurrentPackageFullName(ref length, builder);
return hr == 0;
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder? packageFullName);
}