Skip to content

Commit

Permalink
Merge pull request #829 from dlamkins/remove-conti-dep
Browse files Browse the repository at this point in the history
Remove conti dep
  • Loading branch information
dlamkins authored Jan 9, 2023
2 parents f1b6b0d + b016a5d commit 5d130cb
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 54 deletions.
1 change: 0 additions & 1 deletion Blish HUD/Blish HUD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@
<PackageReference Include="NAudio.Wasapi" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="[13.0.1]" />
<PackageReference Include="NLog" Version="4.6.7" PrivateAssets="all" />
<PackageReference Include="Ookii.Dialogs.WinForms" Version="4.0.0" PrivateAssets="all" />
<PackageReference Include="SemanticVersioning" Version="1.2.2" PrivateAssets="all" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.14.1" PrivateAssets="all" />
<PackageReference Include="System.Resources.Extensions" Version="6.0.0" />
Expand Down
20 changes: 12 additions & 8 deletions Blish HUD/GameServices/ArcDps/SocketListener/SocketListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void ReleaseSocket(Socket socket) {

this.Running = false;
} catch (Exception reason) {
Logger.Error(reason, "Failed to disconnect socket:");
Logger.Warn(reason, "Failed to disconnect socket:");
}
}

Expand All @@ -95,7 +95,7 @@ private void StartConnect(Socket client, EndPoint endPoint) {
_ = client.BeginConnect(endPoint, this.ConnectCallback, client);
Logger.Debug("Connected.");
} catch (Exception ex) {
Logger.Error(ex, "Failed to connect socket.");
Logger.Warn(ex, "Failed to connect socket.");

this.Stop();
}
Expand All @@ -114,15 +114,19 @@ private void ConnectCallback(IAsyncResult ar) {
socket.EndConnect(ar);

Logger.Debug("Socket connected to {0}",
socket.RemoteEndPoint.ToString());
socket.RemoteEndPoint.ToString());

this.Running = true;

this.StartReceive(socket);
} catch (SocketException ex) {
Logger.Warn(ex.SocketErrorCode.ToString());
} catch (Exception ex) {
Logger.Error(ex, "Failed to connect socket:");

this.Stop();
// If ArcDPS bridge isn't installed, then this error is almost certain to happen, so we ignore ConnectionRefused
if (!(ex is SocketException { SocketErrorCode: SocketError.ConnectionRefused })) {
Logger.Error(ex, "Failed to connect socket:");
this.Stop();
}
}
}

Expand Down Expand Up @@ -216,7 +220,7 @@ private void ReceiveCallback(IAsyncResult ar) {
this.StartReceive(socket);
}
} catch (Exception ex) {
Logger.Error(ex, "Failed to receive from socket:");
Logger.Warn(ex, "Failed to receive from socket:");
this.OnSocketError?.Invoke(this, SocketError.SocketError);

this.Stop();
Expand Down Expand Up @@ -314,7 +318,7 @@ private void ProcessMessage(byte[] messageData, AsyncUserToken token) {
try {
this.ReceivedMessage?.Invoke(this, new MessageData { Message = messageData, Token = token });
} catch (Exception ex) {
Logger.Error(ex, "Failed processing received message:");
Logger.Warn(ex, "Failed processing received message:");
}
}
}
Expand Down
50 changes: 8 additions & 42 deletions Blish HUD/GameServices/Debug/Contingency.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Ookii.Dialogs.WinForms;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
Expand All @@ -8,21 +7,19 @@
namespace Blish_HUD.Debug {
public static class Contingency {

private const string DISCORD_JOIN_URL = "http://link.blishhud.com/discordhelp";
private static readonly Logger Logger = Logger.GetLogger(typeof(Contingency));

private static readonly HashSet<string> _contingency = new HashSet<string>();

private static void NotifyContingency(string key, string title, string description, string url, params (TaskDialogButton Button, Func<Task> OnClick)[] extraActions) {
NotifyContingency(key, title, description, null, url, extraActions);
}

private static void NotifyContingency(string key, string title, string description, string expandedDescription, string url, params (TaskDialogButton Button, Func<Task> OnClick)[] extraActions) {
private static void NotifyContingency(string key, string title, string description, string url, params ContingencyPopup.PopupButton[] extraActions) {
if (_contingency.Contains(key)) {
return;
}

_contingency.Add(key);

Logger.Warn($"Contingency '{key}' was triggered!");

if (BlishHud.Instance != null) {
if (BlishHud.Instance.Form.InvokeRequired) {
BlishHud.Instance.Form.Invoke(new Action(() => BlishHud.Instance.Form.Hide()));
Expand All @@ -31,47 +28,17 @@ private static void NotifyContingency(string key, string title, string descripti
}
}

var notifDiag = new TaskDialog() {
WindowTitle = title,
MainIcon = TaskDialogIcon.Warning,
MainInstruction = description,
Content = expandedDescription,
FooterIcon = TaskDialogIcon.Information,
EnableHyperlinks = true,
Footer = string.Format(Strings.GameServices.Debug.ContingencyMessages.GenericUrl_Footer, url, DISCORD_JOIN_URL),
};

notifDiag.HyperlinkClicked += NotifDiag_HyperlinkClicked;

notifDiag.Buttons.Add(new TaskDialogButton(ButtonType.Ok));

foreach (var actions in extraActions) {
notifDiag.Buttons.Add(actions.Button);
}

notifDiag.ButtonClicked += async (sender, e) => {
foreach (var action in extraActions) {
if (e.Item == action.Button) {
await action.OnClick.Invoke();
}
}
};
var notifDiag = new ContingencyPopup(title, description, url, extraActions);

notifDiag.ShowDialog();
}

private static Task OpenNvidaControlPanel() {
private static void OpenNvidaControlPanel() {
try {
Process.Start(Environment.ExpandEnvironmentVariables("%programfiles%\\NVIDIA Corporation\\Control Panel Client\\nvcplui.exe"));
} catch (Win32Exception) {
Process.Start("explorer.exe", "shell:AppsFolder\\NVIDIACorp.NVIDIAControlPanel_56jybvy8sckqj!NVIDIACorp.NVIDIAControlPanel");
}

return Task.CompletedTask;
}

private static void NotifDiag_HyperlinkClicked(object sender, HyperlinkClickedEventArgs e) {
Process.Start(e.Href);
}

internal static void NotifyWin32AccessDenied() {
Expand Down Expand Up @@ -105,10 +72,9 @@ internal static void NotifyCfaBlocking(string path) {
internal static void NotifyNvidiaSettings(string description) {
NotifyContingency(nameof(NotifyNvidiaSettings),
Strings.GameServices.Debug.ContingencyMessages.NvidiaSettings_Title,
Strings.GameServices.Debug.ContingencyMessages.NvidiaSettings_Description,
description,
string.Format(Strings.GameServices.Debug.ContingencyMessages.NvidiaSettings_Description, description),
"https://link.blishhud.com/nvidiasettings",
(new TaskDialogButton(Strings.GameServices.Debug.ContingencyMessages.NvidiaSettings_OpenControlPanelAction), OpenNvidaControlPanel));
new ContingencyPopup.PopupButton(Strings.GameServices.Debug.ContingencyMessages.NvidiaSettings_OpenControlPanelAction, OpenNvidaControlPanel));
}

internal static void NotifyConflictingFullscreenSettings() {
Expand Down
2 changes: 1 addition & 1 deletion Blish HUD/GameServices/Debug/ContingencyChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static void CheckNvidiaControlPanelSettings() {
SettingValue<uint> settingValue = settingMeta.DwordValues.FirstOrDefault(val => val.Value == value);
string val = settingValue?.ValueName ?? value.ToString();

errors.Add($"'{settingMeta.SettingName}' = '{val}'");
errors.Add($"'{settingMeta.SettingName}' is '{val}'");
}
}

Expand Down
209 changes: 209 additions & 0 deletions Blish HUD/GameServices/Debug/ContingencyPopup.Designer.cs

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

Loading

0 comments on commit 5d130cb

Please sign in to comment.