Small bug fix and added option to disable the invite feature

This commit is contained in:
EnderIce2 2020-10-25 18:15:11 +02:00
parent 5f6cc9fae6
commit 3ada6d3689
10 changed files with 113 additions and 92 deletions

4
.editorconfig Normal file
View File

@ -0,0 +1,4 @@
[*.cs]
# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EnderIce2.SDRSharpPlugin namespace EnderIce2.SDRSharpPlugin
{ {
@ -21,18 +17,14 @@ namespace EnderIce2.SDRSharpPlugin
string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\RPCLogs\\DiscordRPCLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".log"; string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\RPCLogs\\DiscordRPCLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".log";
if (!File.Exists(filepath)) if (!File.Exists(filepath))
{ {
using (StreamWriter sw = File.CreateText(filepath)) using StreamWriter sw = File.CreateText(filepath);
{
sw.WriteLine($"[{DateTime.Now}] {Message}"); sw.WriteLine($"[{DateTime.Now}] {Message}");
} }
}
else else
{ {
using (StreamWriter sw = File.AppendText(filepath)) using StreamWriter sw = File.AppendText(filepath);
{
sw.WriteLine($"[{DateTime.Now}] {Message}"); sw.WriteLine($"[{DateTime.Now}] {Message}");
} }
} }
} }
}
} }

View File

@ -1,18 +1,12 @@
using System; using DiscordRPC;
using System.Windows.Forms; using DiscordRPC.Logging;
using System.ComponentModel; using DiscordRPC.Message;
using SDRSharp.Common; using SDRSharp.Common;
using SDRSharp.Radio; using SDRSharp.Radio;
using SDRSharp.PanView; using System;
using DiscordRPC.Logging;
using DiscordRPC;
using System.Text;
using System.Threading.Tasks;
using DiscordRPC.Message;
using DiscordRPC.IO;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices.ComTypes; using System.Threading.Tasks;
using System.Windows.Forms;
namespace EnderIce2.SDRSharpPlugin namespace EnderIce2.SDRSharpPlugin
{ {
@ -20,14 +14,18 @@ namespace EnderIce2.SDRSharpPlugin
{ {
private const string _displayName = "Discord RPC"; private const string _displayName = "Discord RPC";
private SettingsPanel _controlPanel; private SettingsPanel _controlPanel;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
private static LogLevel logLevel = LogLevel.Trace; private static LogLevel logLevel = LogLevel.Trace;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
private static int discordPipe = -1; private static int discordPipe = -1;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
bool RPCalreadyLoaded = false; bool RPCalreadyLoaded = false;
private ISharpControl _control; private ISharpControl _control;
bool playedBefore = false; bool playedBefore = false;
private IConfigurationPanelProvider configurationPanelProvider; private IConfigurationPanelProvider configurationPanelProvider;
private SDRSharp.FrontEnds.SpyServer.ControllerPanel controllerPanel; private SDRSharp.FrontEnds.SpyServer.ControllerPanel controllerPanel;
public TopWindowMessages windowMessages; public TopWindowMessages windowMessages;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
private RichPresence presence = new RichPresence() private RichPresence presence = new RichPresence()
{ {
Details = "Loading...", Details = "Loading...",
@ -38,16 +36,6 @@ namespace EnderIce2.SDRSharpPlugin
LargeImageText = "SDRSharp", LargeImageText = "SDRSharp",
SmallImageKey = "image_small", SmallImageKey = "image_small",
SmallImageText = $"SDR# RPC plugin v{Assembly.GetEntryAssembly().GetName().Version} by EnderIce2" SmallImageText = $"SDR# RPC plugin v{Assembly.GetEntryAssembly().GetName().Version} by EnderIce2"
},
Secrets = new Secrets()
{
JoinSecret = "invalid_secret"
},
Party = new Party()
{
ID = Secrets.CreateFriendlySecret(new Random()),
Size = 1,
Max = 100
} }
}; };
private static DiscordRpcClient client; private static DiscordRpcClient client;
@ -69,16 +57,31 @@ namespace EnderIce2.SDRSharpPlugin
if (Utils.GetBooleanSetting("ShowWelcomePage", true)) if (Utils.GetBooleanSetting("ShowWelcomePage", true))
new WelcomeForm().ShowDialog(); new WelcomeForm().ShowDialog();
_controlPanel = new SettingsPanel(); _controlPanel = new SettingsPanel();
windowMessages = new TopWindowMessages(); windowMessages = new TopWindowMessages(); // TODO: do something when "EnableRPCInvite" is set to false
_control = control; _control = control;
try try
{ {
if (Utils.GetBooleanSetting("EnableRPCInvite", false))
_control.RegisterFrontControl(windowMessages, PluginPosition.Top); _control.RegisterFrontControl(windowMessages, PluginPosition.Top);
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.ToString()); MessageBox.Show(ex.ToString());
} }
if (Utils.GetBooleanSetting("EnableRPCInvite", false))
{
presence.Secrets = new Secrets()
{
JoinSecret = "invalid_secret"
};
presence.Party = new Party()
{
ID = Secrets.CreateFriendlySecret(new Random()),
Size = 1,
Max = 100
};
}
if (Utils.GetBooleanSetting("EnableRPCInvite", false))
windowMessages.Show(); windowMessages.Show();
if (Utils.GetBooleanSetting("EnableRPC", true)) if (Utils.GetBooleanSetting("EnableRPC", true))
{ {
@ -114,6 +117,7 @@ namespace EnderIce2.SDRSharpPlugin
{ {
Start = DateTime.UtcNow Start = DateTime.UtcNow
}; };
if (Utils.GetBooleanSetting("EnableRPCInvite", false))
client.SetSubscription(EventType.Join | EventType.JoinRequest); client.SetSubscription(EventType.Join | EventType.JoinRequest);
client.SetPresence(presence); client.SetPresence(presence);
client.Initialize(); client.Initialize();
@ -209,6 +213,8 @@ namespace EnderIce2.SDRSharpPlugin
isRunning = true; isRunning = true;
LogWriter.WriteToFile($"MainLoop called {isRunning} {client.IsInitialized}"); LogWriter.WriteToFile($"MainLoop called {isRunning} {client.IsInitialized}");
while (client != null && isRunning) while (client != null && isRunning)
{
if (Utils.GetBooleanSetting("EnableRPCInvite", false))
{ {
LogWriter.WriteToFile("Setting secret..."); LogWriter.WriteToFile("Setting secret...");
try try
@ -221,6 +227,7 @@ namespace EnderIce2.SDRSharpPlugin
{ {
LogWriter.WriteToFile(ex.ToString()); LogWriter.WriteToFile(ex.ToString());
} }
}
LogWriter.WriteToFile("Waiting 500ms in loop..."); LogWriter.WriteToFile("Waiting 500ms in loop...");
await Task.Delay(500); await Task.Delay(500);
if (_control.RdsRadioText != null) if (_control.RdsRadioText != null)
@ -262,7 +269,10 @@ namespace EnderIce2.SDRSharpPlugin
{ {
client.SetPresence(presence); client.SetPresence(presence);
} }
catch (ObjectDisposedException) {; } catch (ObjectDisposedException ex)
{
LogWriter.WriteToFile($"ObjectDisposedException exception for SetPresence\n{ex}");
}
LogWriter.WriteToFile("SetPresence"); LogWriter.WriteToFile("SetPresence");
_controlPanel.ChangeStatus = $"Presence Updated {DateTime.UtcNow}"; _controlPanel.ChangeStatus = $"Presence Updated {DateTime.UtcNow}";
} }

View File

@ -167,6 +167,7 @@
<Content Include="Resgister.txt" /> <Content Include="Resgister.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include=".editorconfig" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -5,6 +5,11 @@ VisualStudioVersion = 16.0.30517.126
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDRSharpPlugin.DiscordRPC", "SDRSharpPlugin.DiscordRPC.csproj", "{72E8628F-BA39-4915-BF3C-DD48BF477D30}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDRSharpPlugin.DiscordRPC", "SDRSharpPlugin.DiscordRPC.csproj", "{72E8628F-BA39-4915-BF3C-DD48BF477D30}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{446ABA84-7848-4219-AE53-4EE2132D0710}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

View File

@ -34,10 +34,13 @@
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.checkBox2 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// checkBox1 // checkBox1
// //
this.checkBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.checkBox1.Checked = true; this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Location = new System.Drawing.Point(3, 3); this.checkBox1.Location = new System.Drawing.Point(3, 3);
@ -55,9 +58,9 @@
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoEllipsis = true; this.label1.AutoEllipsis = true;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Location = new System.Drawing.Point(0, 49); this.label1.Location = new System.Drawing.Point(0, 67);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(196, 88); this.label1.Size = new System.Drawing.Size(196, 70);
this.label1.TabIndex = 1; this.label1.TabIndex = 1;
this.label1.Text = "Loading status..."; this.label1.Text = "Loading status...";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@ -71,8 +74,8 @@
this.textBox1.Name = "textBox1"; this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(134, 13); this.textBox1.Size = new System.Drawing.Size(134, 13);
this.textBox1.TabIndex = 2; this.textBox1.TabIndex = 2;
this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown); this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBox1_KeyDown);
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress); this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox1_KeyPress);
// //
// label2 // label2
// //
@ -93,10 +96,12 @@
this.button1.TabIndex = 4; this.button1.TabIndex = 4;
this.button1.Text = "Help"; this.button1.Text = "Help";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); this.button1.Click += new System.EventHandler(this.Button1_Click);
// //
// checkBox2 // checkBox2
// //
this.checkBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.checkBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F); this.checkBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F);
this.checkBox2.Location = new System.Drawing.Point(3, 25); this.checkBox2.Location = new System.Drawing.Point(3, 25);
this.checkBox2.Name = "checkBox2"; this.checkBox2.Name = "checkBox2";
@ -104,12 +109,26 @@
this.checkBox2.TabIndex = 5; this.checkBox2.TabIndex = 5;
this.checkBox2.Text = "Log RPC (for debugging)"; this.checkBox2.Text = "Log RPC (for debugging)";
this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); this.checkBox2.CheckedChanged += new System.EventHandler(this.CheckBox2_CheckedChanged);
//
// checkBox3
//
this.checkBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.checkBox3.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F);
this.checkBox3.Location = new System.Drawing.Point(3, 43);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(193, 21);
this.checkBox3.TabIndex = 6;
this.checkBox3.Text = "Enable Invite Feature (not tested)";
this.checkBox3.UseVisualStyleBackColor = true;
this.checkBox3.CheckedChanged += new System.EventHandler(this.CheckBox3_CheckedChanged);
// //
// SettingsPanel // SettingsPanel
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkBox3);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.checkBox2); this.Controls.Add(this.checkBox2);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
@ -131,5 +150,6 @@
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
} }
} }

View File

@ -1,15 +1,7 @@
using System; using SDRSharp.Radio;
using System.Collections.Generic; using System;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using SDRSharp.Radio;
using System.Security.Policy;
using System.Media;
namespace EnderIce2.SDRSharpPlugin namespace EnderIce2.SDRSharpPlugin
{ {
@ -41,6 +33,10 @@ namespace EnderIce2.SDRSharpPlugin
checkBox2.Checked = true; checkBox2.Checked = true;
else else
checkBox2.Checked = false; checkBox2.Checked = false;
if (Utils.GetBooleanSetting("EnableRPCInvite", false))
checkBox3.Checked = true;
else
checkBox3.Checked = false;
LogWriter.WriteToFile("SettingsPanel loaded"); LogWriter.WriteToFile("SettingsPanel loaded");
} }
@ -52,17 +48,17 @@ namespace EnderIce2.SDRSharpPlugin
//Utils.GetBooleanSetting("EnableRPC"); //Utils.GetBooleanSetting("EnableRPC");
} }
private void button1_Click(object sender, EventArgs e) private void Button1_Click(object sender, EventArgs e)
{ {
System.Diagnostics.Process.Start("https://github.com/EnderIce2/SDRSharpRPC"); System.Diagnostics.Process.Start("https://github.com/EnderIce2/SDR-RPC");
} }
private void checkBox2_CheckedChanged(object sender, EventArgs e) private void CheckBox2_CheckedChanged(object sender, EventArgs e)
{ {
Utils.SaveSetting("LogRPC", checkBox2.Checked); Utils.SaveSetting("LogRPC", checkBox2.Checked);
} }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{ {
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
e.Handled = true; e.Handled = true;
@ -70,7 +66,7 @@ namespace EnderIce2.SDRSharpPlugin
e.Handled = true; e.Handled = true;
} }
private async void textBox1_KeyDown(object sender, KeyEventArgs e) private async void TextBox1_KeyDown(object sender, KeyEventArgs e)
{ {
if (e.KeyCode == Keys.Enter && textBox1.Text.Replace(" ", "").Length == 18) if (e.KeyCode == Keys.Enter && textBox1.Text.Replace(" ", "").Length == 18)
{ {
@ -82,5 +78,12 @@ namespace EnderIce2.SDRSharpPlugin
label1.Text = "Saved."; label1.Text = "Saved.";
} }
} }
private void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
Utils.SaveSetting("EnableRPCInvite", checkBox3.Checked);
label1.Text = "Restart required";
LogWriter.WriteToFile($"checkbox on SettingsPanel clicked {checkBox3.Checked}");
}
} }
} }

View File

@ -1,14 +1,7 @@
using System; using DiscordRPC;
using System.Collections.Generic; using DiscordRPC.Message;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using DiscordRPC.Message;
using DiscordRPC;
namespace EnderIce2.SDRSharpPlugin namespace EnderIce2.SDRSharpPlugin
{ {

View File

@ -55,7 +55,7 @@
this.button1.TabIndex = 1; this.button1.TabIndex = 1;
this.button1.Text = "&OK"; this.button1.Text = "&OK";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); this.button1.Click += new System.EventHandler(this.Button1_Click);
// //
// checkBox1 // checkBox1
// //
@ -66,7 +66,7 @@
this.checkBox1.TabIndex = 2; this.checkBox1.TabIndex = 2;
this.checkBox1.Text = "Don\'t show me this next time"; this.checkBox1.Text = "Don\'t show me this next time";
this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); this.checkBox1.CheckedChanged += new System.EventHandler(this.CheckBox1_CheckedChanged);
// //
// label1 // label1
// //
@ -95,7 +95,7 @@
this.button2.TabIndex = 5; this.button2.TabIndex = 5;
this.button2.Text = "Support Me"; this.button2.Text = "Support Me";
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.Click += new System.EventHandler(this.Button2_Click);
// //
// WelcomeForm // WelcomeForm
// //

View File

@ -1,12 +1,5 @@
using SDRSharp.Radio; using SDRSharp.Radio;
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace EnderIce2.SDRSharpPlugin namespace EnderIce2.SDRSharpPlugin
@ -18,17 +11,17 @@ namespace EnderIce2.SDRSharpPlugin
InitializeComponent(); InitializeComponent();
} }
private void button2_Click(object sender, EventArgs e) private void Button2_Click(object sender, EventArgs e)
{ {
System.Diagnostics.Process.Start("https://ko-fi.com/enderice2"); System.Diagnostics.Process.Start("https://ko-fi.com/enderice2");
} }
private void button1_Click(object sender, EventArgs e) private void Button1_Click(object sender, EventArgs e)
{ {
Close(); Close();
} }
private void checkBox1_CheckedChanged(object sender, EventArgs e) private void CheckBox1_CheckedChanged(object sender, EventArgs e)
{ {
Utils.SaveSetting("ShowWelcomePage", !checkBox1.Checked); Utils.SaveSetting("ShowWelcomePage", !checkBox1.Checked);
} }