Skip to content

Commit

Permalink
Add setting to disable hotkey system
Browse files Browse the repository at this point in the history
Implement basic unhandled exception logging to help with debugging
  • Loading branch information
tremwil committed Aug 10, 2021
1 parent 41d0a29 commit d1ca941
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# IDE0011: Add braces
csharp_prefer_braces = when_multiline
3 changes: 3 additions & 0 deletions DS3ConnectionInfo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{85B98847-BA2D-4A75-9DEE-AFABC317CC5E}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DS3ConnectionInfo", "DS3ConnectionInfo\DS3ConnectionInfo.csproj", "{A4512F87-F19E-4CD4-9FA1-EBB6C514BE77}"
EndProject
Expand Down
3 changes: 3 additions & 0 deletions DS3ConnectionInfo/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<setting name="SpamRedEyeOrb" serializeAs="String">
<value>False</value>
</setting>
<setting name="UseHotkeys" serializeAs="String">
<value>True</value>
</setting>
</DS3ConnectionInfo.Settings>
</userSettings>
<applicationSettings>
Expand Down
3 changes: 3 additions & 0 deletions DS3ConnectionInfo/DS3ConnectionInfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="..\.editorconfig">
<Link>.editorconfig</Link>
</None>
<None Include="app.manifest" />
<None Include="ilrepack.targets" />
<None Include="packages.config" />
Expand Down
16 changes: 11 additions & 5 deletions DS3ConnectionInfo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
Expand All @@ -173,8 +175,12 @@
<Label Content="REO Hotkey Effect" Grid.Row="0" Grid.Column="0"></Label>
<mah:ToggleSwitch Grid.Row="0" Margin="10 0" Grid.Column="1" IsOn="{Binding Source={x:Static local:Settings.Default}, Path=SpamRedEyeOrb}"
OnContent="Spam" OffContent="Normal"></mah:ToggleSwitch>
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" FontWeight="Bold">Show/Hide Session Info Columns:</Label>
<ComboBox Grid.Row="3" Grid.Column="0" SelectedIndex="0" Name="cbColName" SelectionChanged="cbColName_SelectionChanged">
<Label Content="Enable Hotkeys" Grid.Row="2" Grid.Column="0"></Label>
<mah:ToggleSwitch Grid.Row="2" Margin="10 0" Grid.Column="1" IsOn="{Binding Source={x:Static local:Settings.Default}, Path=UseHotkeys}" Name="swToggleHotkeys"
OnContent="Yes" OffContent="No" ToolTip="Enable/disable the hotkey system." Toggled="swToggleHotkeys_Toggled"></mah:ToggleSwitch>

<Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" FontWeight="Bold">Show/Hide Session Info Columns:</Label>
<ComboBox Grid.Row="5" Grid.Column="0" SelectedIndex="0" Name="cbColName" SelectionChanged="cbColName_SelectionChanged">
<ComboBoxItem>Slot</ComboBoxItem>
<ComboBoxItem>Char. Name</ComboBoxItem>
<ComboBoxItem>Team</ComboBoxItem>
Expand All @@ -187,11 +193,11 @@
<ComboBoxItem>Late Packet %</ComboBoxItem>
<ComboBoxItem>Location</ComboBoxItem>
</ComboBox>
<mah:ToggleSwitch Margin="10 0" Grid.Row="3" Grid.Column="1" IsOn="True" OnContent="Shown" OffContent="Hidden" Name="swColVisible" Toggled="swColVisible_Toggled"></mah:ToggleSwitch>
<Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Width="{Binding ElementName=gridSessInfoSettings, Path=ActualWidth}">
<mah:ToggleSwitch Margin="10 0" Grid.Row="5" Grid.Column="1" IsOn="True" OnContent="Shown" OffContent="Hidden" Name="swColVisible" Toggled="swColVisible_Toggled"></mah:ToggleSwitch>
<Label Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Width="{Binding ElementName=gridSessInfoSettings, Path=ActualWidth}">
<TextBlock TextWrapping="Wrap" Name="textColDesc" FontStyle="Italic">DESC</TextBlock>
</Label>
<DockPanel Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="False" Margin="0 5" HorizontalAlignment="Left">
<DockPanel Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="False" Margin="0 5" HorizontalAlignment="Left">
<Button DockPanel.Dock="Bottom" Name="btnResetSettings" Click="btnResetSettings_Click" Height="40" FontSize="14" Width="200">Reset All Settings</Button>
</DockPanel>
</Grid>
Expand Down
35 changes: 28 additions & 7 deletions DS3ConnectionInfo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.IO;
using Steamworks;
using System.Security.Permissions;
using System.Media;

namespace DS3ConnectionInfo
{
Expand All @@ -40,8 +41,9 @@ public partial class MainWindow

public MainWindow()
{
//logWriter = new StreamWriter("log.txt");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += (s, e) => ShowUnhandledException((Exception)e.ExceptionObject, "CurrentDomain", e.IsTerminating);
TaskScheduler.UnobservedTaskException += (s, e) => ShowUnhandledException(e.Exception, "TaskScheduler", false);
Dispatcher.UnhandledException += (s, e) => { if (!Debugger.IsAttached) ShowUnhandledException(e.Exception, "Dispatcher", true); };

InitializeComponent();
overlay = new OverlayWindow();
Expand Down Expand Up @@ -89,10 +91,21 @@ public MainWindow()
});
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
private void ShowUnhandledException(Exception err, string type, bool fatal)
{
Exception ex = (Exception)e.ExceptionObject;
MessageBox.Show($"[ERROR] {ex.GetType().Name}: {ex.Message} at {ex.StackTrace}");
MetroDialogSettings diagSettings = new MetroDialogSettings()
{
ColorScheme = MetroDialogColorScheme.Accented,
AffirmativeButtonText = "Copy",
NegativeButtonText = "Close"
};

SystemSounds.Exclamation.Play();
var result = this.ShowModalMessageExternal($"Unhandled Exception: {err.GetType().Name}", $"{err.Message}\n{err.StackTrace}", MessageDialogStyle.AffirmativeAndNegative, diagSettings);
if (result == MessageDialogResult.Affirmative)
Clipboard.SetText($"{err.GetType().Name}: {err.Message}\n{err.StackTrace}");

Close();
}

private void UpdateColVisibility()
Expand Down Expand Up @@ -225,11 +238,11 @@ private void GameStartTimer_Tick(object sender, EventArgs e)
Close();
}

if (!HotkeyManager.Enable())
if (Settings.Default.UseHotkeys && !HotkeyManager.Enable())
MessageBox.Show("Could not initialize keyboard hook for hotkeys", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);

if (!overlay.InstallMsgHook())
MessageBox.Show("Could not overlay message hook", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("Could not setup overlay message hook", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);

overlay.UpdateVisibility();
if (swBorderless.IsOn ^ DS3Interop.Borderless)
Expand Down Expand Up @@ -324,6 +337,14 @@ private void swBorderless_Toggled(object sender, RoutedEventArgs e)
DS3Interop.MakeBorderless(swBorderless.IsOn);
}

private void swToggleHotkeys_Toggled(object sender, RoutedEventArgs e)
{
if (Settings.Default.UseHotkeys && !HotkeyManager.Enable())
MessageBox.Show("Could not initialize keyboard hook for hotkeys", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);

if (!Settings.Default.UseHotkeys) HotkeyManager.Disable();
}

private void btnResetSettings_Click(object sender, RoutedEventArgs e)
{
Settings.Default.Reset();
Expand Down
14 changes: 13 additions & 1 deletion DS3ConnectionInfo/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions DS3ConnectionInfo/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,8 @@
<Setting Name="SpamRedEyeOrb" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="UseHotkeys" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion DS3ConnectionInfo/VersionCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DS3ConnectionInfo
{
static class VersionCheck
{
public static readonly string CurrentVersion = "V4.1";
public static readonly string CurrentVersion = "V4.2";
public static JObject LatestRelease { get; private set; }

public static bool FetchLatest()
Expand Down

0 comments on commit d1ca941

Please sign in to comment.