# Conflicts: # .gitignore # App.xaml # App.xaml.cs # AudioWatcher.cs # Delcom/DeviceManagement.cs # Delcom/StoplightIndicator.cs # LICENSE.md # LightController.cs # Properties/AssemblyInfo.cs # Properties/Resources.Designer.cs # Properties/Resources.resx # Properties/Settings.Designer.cs # Properties/Settings.settings # README.md # UpdateCheck.cs # WorkIndicator.csproj # WorkIndicator.sln # WorkIndicator.sln.DotSettings
50 lines
1.0 KiB
C#
50 lines
1.0 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace WorkIndicator;
|
|
|
|
internal class UsbService : NativeWindow, IDisposable
|
|
{
|
|
public event Action DevicesChanged;
|
|
|
|
private const int WmDeviceChange = 0x0219;
|
|
private const int DbtDeviceArrival = 0x8000;
|
|
private const int DbtDeviceRemoveComplete = 0x8004;
|
|
private const int DbtDevNodesChanged = 0x0007;
|
|
|
|
private bool _isDisposed;
|
|
|
|
internal UsbService()
|
|
{
|
|
base.CreateHandle(new CreateParams());
|
|
}
|
|
|
|
protected override void WndProc(ref Message msg)
|
|
{
|
|
base.WndProc(ref msg);
|
|
|
|
if (msg.Msg != WmDeviceChange)
|
|
return;
|
|
|
|
switch (msg.WParam.ToInt32())
|
|
{
|
|
case DbtDevNodesChanged:
|
|
case DbtDeviceArrival:
|
|
case DbtDeviceRemoveComplete:
|
|
DevicesChanged?.Invoke();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_isDisposed)
|
|
return;
|
|
|
|
base.DestroyHandle();
|
|
|
|
_isDisposed = true;
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
} |