Files
better-genshin-impact/BetterGenshinImpact/Helpers/DeviceIdHelper.cs
2025-06-01 00:18:52 +08:00

33 lines
1.0 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;
using DeviceId;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.Helpers;
public class DeviceIdHelper
{
private static readonly ILogger _logger = App.GetLogger<DeviceIdHelper>();
private static readonly Lazy<string> _lazyDeviceId = new(InitializeDeviceId);
public static string DeviceId => _lazyDeviceId.Value;
private static string InitializeDeviceId()
{
try
{
return new DeviceIdBuilder()
.OnWindows(windows => windows
.AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
.AddProcessorId()
.AddMotherboardSerialNumber()
)
.ToString();
}
catch (Exception e)
{
_logger.LogDebug("获取设备ID异常" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" +
Environment.NewLine + e.Message);
return string.Empty;
}
}
}