Improve exception handling for X360 controller

This commit is contained in:
Kamil Trzciński 2022-12-16 11:00:37 +01:00
parent 147ef53a7f
commit 9f1288cfb0

View file

@ -45,6 +45,7 @@ namespace SteamController.Devices
}
catch (VigemBusNotFoundException)
{
// ViGem is not installed
return false;
}
}
@ -54,6 +55,7 @@ namespace SteamController.Devices
var client = this.client;
// unset current device
this.isConnected = false;
this.client = null;
this.device = null;
@ -91,6 +93,13 @@ namespace SteamController.Devices
device?.Connect();
TraceLine("Connected X360 Controller.");
}
catch (System.ComponentModel.Win32Exception e)
{
// This is expected exception (as sometimes device will fail to connect)
TraceException("X360", "ConnectExpected", e);
Fail();
return;
}
catch (Exception e)
{
TraceException("X360", "Connect", e);
@ -105,6 +114,10 @@ namespace SteamController.Devices
device?.Disconnect();
TraceLine("Disconnected X360 Controller.");
}
catch (VigemTargetNotPluggedInException)
{
// everything fine
}
catch (Exception e)
{
TraceException("X360", "Disconnect", e);
@ -149,11 +162,14 @@ namespace SteamController.Devices
{
device?.SubmitReport();
}
catch (VigemInvalidTargetException e)
catch (VigemInvalidTargetException)
{
// Device was lost
lock (this) { Fail(); }
}
catch (Exception e)
{
TraceException("X360", "SubmitReport", e);
device?.Disconnect();
isConnected = false;
}
}