|
|
@ -4,15 +4,18 @@ using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace hass_workstation_service.Domain.Sensors
|
|
|
|
namespace hass_workstation_service.Domain.Sensors
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class WebcamProcessSensor : AbstractSensor
|
|
|
|
public class WebcamProcessSensor : AbstractSensor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private List<string> processes = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public WebcamProcessSensor(MqttPublisher publisher, int? updateInterval = null, string name = "WebcamProcess", Guid id = default) : base(publisher, name ?? "WebcamProcess", updateInterval ?? 10, id)
|
|
|
|
public WebcamProcessSensor(MqttPublisher publisher, int? updateInterval = null, string name = "WebcamProcess", Guid id = default) : base(publisher, name ?? "WebcamProcess", updateInterval ?? 10, id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string GetState()
|
|
|
|
public override string GetState()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
@ -38,92 +41,52 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
private string IsWebCamInUseRegistry()
|
|
|
|
private void CheckLastUsed(RegistryKey key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"))
|
|
|
|
foreach (var subKeyName in key.GetSubKeyNames())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var subKeyName in key.GetSubKeyNames())
|
|
|
|
// NonPackaged has multiple subkeys
|
|
|
|
|
|
|
|
if (subKeyName == "NonPackaged")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// NonPackaged has multiple subkeys
|
|
|
|
using (var nonpackagedkey = key.OpenSubKey(subKeyName))
|
|
|
|
if (subKeyName == "NonPackaged")
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var nonpackagedkey = key.OpenSubKey(subKeyName))
|
|
|
|
CheckLastUsed(nonpackagedkey);
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var nonpackagedSubKeyName in nonpackagedkey.GetSubKeyNames())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var subKey = nonpackagedkey.OpenSubKey(nonpackagedSubKeyName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return nonpackagedSubKeyName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var subKey = key.OpenSubKey(subKeyName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var subKey = key.OpenSubKey(subKeyName))
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
this.processes.Add(subKeyName);
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return subKeyName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
|
|
|
|
private string IsWebCamInUseRegistry()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CheckLastUsed(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"))
|
|
|
|
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var subKeyName in key.GetSubKeyNames())
|
|
|
|
CheckLastUsed(key);
|
|
|
|
{
|
|
|
|
|
|
|
|
// NonPackaged has multiple subkeys
|
|
|
|
|
|
|
|
if (subKeyName == "NonPackaged")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var nonpackagedkey = key.OpenSubKey(subKeyName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var nonpackagedSubKeyName in nonpackagedkey.GetSubKeyNames())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var subKey = nonpackagedkey.OpenSubKey(nonpackagedSubKeyName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return nonpackagedSubKeyName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var subKey = key.OpenSubKey(subKeyName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return subKeyName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.processes.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return String.Join(",", this.processes.ToArray());
|
|
|
|
|
|
|
|
}
|
|
|
|
return "off";
|
|
|
|
return "off";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|