You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System.Text.Json;
|
|
using Lagrange.Core.Common;
|
|
using RoBot.Start.ConstValue;
|
|
|
|
namespace RoBot.Start.Device
|
|
{
|
|
public class DeviceConfig
|
|
{
|
|
/// <summary>
|
|
/// 获取设备信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static async Task<BotDeviceInfo> GetDeviceInfo()
|
|
{
|
|
return File.Exists(Consts.DeviceConfig)
|
|
? JsonSerializer.Deserialize<BotDeviceInfo>(await File.ReadAllTextAsync(Consts.DeviceConfig))
|
|
?? GenerateNewDeviceInfo()
|
|
: GenerateNewDeviceInfo();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成新的设备信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static BotDeviceInfo GenerateNewDeviceInfo()
|
|
{
|
|
var random = new Random();
|
|
return new()
|
|
{
|
|
Guid = Guid.NewGuid(),
|
|
MacAddress = [
|
|
(byte)random.Next(0, 255),
|
|
(byte)random.Next(0, 255),
|
|
(byte)random.Next(0, 255),
|
|
(byte)random.Next(0, 255),
|
|
(byte)random.Next(0, 255),
|
|
(byte)random.Next(0, 255),
|
|
],
|
|
DeviceName = $"My ubuntu PC",
|
|
SystemKernel = "Ubuntu 22.04.5 LTS",
|
|
KernelVersion = "5.15.0-113-generic"
|
|
};
|
|
}
|
|
}
|
|
}
|