Skip to content

Commit

Permalink
fix: fix empty Device Info
Browse files Browse the repository at this point in the history
  • Loading branch information
nidbCN committed Nov 22, 2024
1 parent 99c66f0 commit 8f8c194
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CameraCaptureBot.Core/CameraCaptureBot.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AssemblyVersion>8.1.4.4</AssemblyVersion>
<FileVersion>8.1.4.4</FileVersion>
<AssemblyVersion>8.1.4.5</AssemblyVersion>
<FileVersion>8.1.4.5</FileVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace CameraCaptureBot.Core.Extensions.DependencyInjection;

public static class ServiceCollectionExtension
{
private static readonly Random RandomGen = new();

public static void AddIsoStorages(this IServiceCollection services)
{
services.AddSingleton(IsolatedStorageFile.GetStore(
Expand All @@ -22,19 +24,35 @@ public static void AddBots(this IServiceCollection services, Func<BotOption> con
using var isoStore = IsolatedStorageFile.GetStore(
IsolatedStorageScope.User | IsolatedStorageScope.Application, null, null);

var deviceInfo = ReadAsJsonOrDelete<BotDeviceInfo>(isoStore, botOption.DeviceInfoFile);
deviceInfo.DeviceName = "linux-capture";
var deviceInfo = ReadAsJsonOrDelete<BotDeviceInfo>(isoStore, botOption.DeviceInfoFile)
?? GenerateInfo();

var keyStore = ReadAsJsonOrDelete<BotKeystore>(isoStore, botOption.KeyStoreFile);
var keyStore = ReadAsJsonOrDelete<BotKeystore>(isoStore, botOption.KeyStoreFile)
?? new BotKeystore();
services.AddSingleton(BotFactory.Create(botOption.FrameworkConfig, deviceInfo, keyStore));

isoStore.Close();
}

private static T ReadAsJsonOrDelete<T>(IsolatedStorageFile handler, string filename) where T : new()
private static BotDeviceInfo GenerateInfo()
{
var macAddress = new byte[6];
RandomGen.NextBytes(macAddress);

return new()
{
Guid = Guid.NewGuid(),
MacAddress = macAddress,
DeviceName = "linux-capture",
SystemKernel = "Ubuntu 24.04.1 LTS",
KernelVersion = "6.8.0-48-generic"
};
}

private static T? ReadAsJsonOrDelete<T>(IsolatedStorageFile handler, string filename) where T : new()
{
if (!handler.FileExists(filename))
return new();
return default;

try
{
Expand All @@ -45,7 +63,7 @@ public static void AddBots(this IServiceCollection services, Func<BotOption> con
{
Console.WriteLine(e);
handler.DeleteFile(filename);
return new();
return default;
}
}
}

0 comments on commit 8f8c194

Please sign in to comment.