Skip to content

Commit e2807e7

Browse files
authored
Merge pull request #3 from TheNathannator/patch-2
Prevent VigemBusNotFoundException and add missing app.config file required for compile
2 parents f51b4c3 + fa4ae0b commit e2807e7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

WiitarThing/Windows/MainWindow.xaml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Shared;
1616
using Shared.Windows;
1717
using System.Diagnostics;
18+
using Nefarius.ViGEm.Client;
1819

1920
namespace WiinUSoft
2021
{
@@ -39,6 +40,20 @@ public static bool ApplicationIsActivated()
3940
return activeProcId == procId;
4041
}
4142

43+
/// <summary>Returns true if ViGEmBus is installed, false otherwise</summary>
44+
public static bool ViGEmBusIsInstalled()
45+
{
46+
try
47+
{
48+
var client = new ViGEmClient();
49+
client.Dispose();
50+
return true;
51+
}
52+
catch (Nefarius.ViGEm.Client.Exceptions.VigemBusNotFoundException)
53+
{
54+
return false;
55+
}
56+
}
4257

4358
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
4459
private static extern IntPtr GetForegroundWindow();
@@ -309,6 +324,12 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
309324

310325
Refresh();
311326
AutoRefresh(menu_AutoRefresh.IsChecked && ApplicationIsActivated());
327+
if (!ViGEmBusIsInstalled())
328+
{
329+
MessageBox.Show("This program requires the ViGEmBus driver to function.",
330+
"ViGEmBus Not Found", MessageBoxButton.OK, MessageBoxImage.Error);
331+
Application.Current.Shutdown();
332+
}
312333
}
313334

314335
private void DeviceControl_OnConnectStateChange(DeviceControl sender, DeviceState oldState, DeviceState newState)

WiitarThing/app.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>

0 commit comments

Comments
 (0)