diff --git a/Bheithir.csproj b/Bheithir.csproj index e17ff2f..031f4d9 100644 --- a/Bheithir.csproj +++ b/Bheithir.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 diff --git a/Program.cs b/Program.cs index b52e04a..ab491a1 100644 --- a/Program.cs +++ b/Program.cs @@ -11,6 +11,7 @@ class Program private static readonly Dictionary emulators = new Dictionary() { { "dosbox", new DosBox() }, + { "dosbox-x", new DosBox_X() }, { "fceux", new Fceux() }, { "snes9x", new Snes9x() }, { "fusion", new Fusion() }, @@ -22,31 +23,62 @@ private static void Main(string[] args) { bool success = false; string emulator = ""; - while(!success) + + if (args.Length > 0) { - Console.WriteLine("What emulator are you using?"); - Console.ForegroundColor = ConsoleColor.Cyan; - emulator = Console.ReadLine().ToLower(); - if(emulators.ContainsKey(emulator)) - break; - Console.ResetColor(); - Console.WriteLine("You misspelled the emulator name or that emulator is not supported!\n"); + for (int i = 0; i < args.Length; i++) + { + if (args[i].StartsWith("-")) + { + string flag = args[i].Substring(1).ToLower(); + if (emulators.ContainsKey(flag)) + { + emulator = flag; + success = true; + break; + } + else + { + Console.WriteLine("The specified emulator is not supported!"); + return; + } + } + } + } + + if (!success) + { + while (!success) + { + Console.WriteLine("What emulator are you using?"); + Console.ForegroundColor = ConsoleColor.Cyan; + emulator = Console.ReadLine().ToLower(); + Console.ResetColor(); + + if (emulators.ContainsKey(emulator)) + { + success = true; + } + else + { + Console.WriteLine("You misspelled the emulator name or that emulator is not supported!\n"); + } + } } - Console.ResetColor(); Presence presence = emulators[emulator]; - if (!Process.GetProcesses().Where(x => x.ProcessName.StartsWith(presence.ProcessName)).Any()) + if (!Process.GetProcesses().Any(x => x.ProcessName.StartsWith(presence.ProcessName))) { Console.WriteLine("The specified emulator was not found! Is it open?"); return; } presence.Initialize(); - while(true) + while (true) { presence.Update(); - if(!Process.GetProcesses().Where(x => x.ProcessName.StartsWith(presence.ProcessName)).Any()) + if (!Process.GetProcesses().Any(x => x.ProcessName.StartsWith(presence.ProcessName))) { presence.Deinitialize(); Console.WriteLine("Thanks for using Bheithir!"); diff --git a/assets/dosbox-x-rpc-512.png b/assets/dosbox-x-rpc-512.png new file mode 100644 index 0000000..4ee13b2 Binary files /dev/null and b/assets/dosbox-x-rpc-512.png differ diff --git a/assets/dosbox-x-rpc.png b/assets/dosbox-x-rpc.png new file mode 100644 index 0000000..73fa69e Binary files /dev/null and b/assets/dosbox-x-rpc.png differ diff --git a/emulators/DosBox_X.cs b/emulators/DosBox_X.cs new file mode 100644 index 0000000..aea6e5a --- /dev/null +++ b/emulators/DosBox_X.cs @@ -0,0 +1,138 @@ +using DiscordRPC; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace Bheithir.Emulators +{ + class DosBox_X : Presence + { + public DosBox_X() + { + DiscordAppId = "1138396799669895248"; + ProcessName = "dosbox-x"; + WindowPattern = new Regex("(,\\s)+", RegexOptions.Compiled); + } + + public override void Initialize() + { + Client = new DiscordRpcClient(DiscordAppId); + + Process = Process.GetProcesses().Where(x => x.ProcessName.StartsWith(ProcessName)).ToList()[0]; + WindowTitle = Process.MainWindowTitle; + + Client.OnReady += (sender, e) => { }; + Client.OnPresenceUpdate += (sender, e) => { }; + + try + { + Client.Initialize(); + Console.WriteLine("Successfully connected to client!"); + } + catch (Exception e) + { + Console.WriteLine($"Connection to client was not successful!\nERROR: {e.Message}"); + return; + } + + try { SetNewPresence(); } + catch (Exception e) + { + Console.WriteLine($"Setting presence was not successful!\nERROR: {e.Message}"); + return; + } + } + public override void Update() + { + Client.OnPresenceUpdate += (sender, e) => { }; + Client.Invoke(); + OnUpdate(); + } + public override void Deinitialize() + { + Client.ClearPresence(); + Client.Dispose(); + } + + public override void OnUpdate() + { + Process process; + try + { + process = Process.GetProcesses().Where(x => x.ProcessName.StartsWith(ProcessName)).ToList()[0]; + } + catch (Exception) { return; } + + if (process.MainWindowTitle != WindowTitle) + { + Process = process; + WindowTitle = Process.MainWindowTitle; + SetNewPresence(); + } + } + public override void SetNewPresence() + { + char[] delimiters = { ':', '[', ']' }; + string[] titleParts = WindowTitle.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); + + if (titleParts.Length >= 2) + { + string part1 = titleParts[0].Trim(); + string[] part2Parts = titleParts[1].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); + string part2 = part2Parts.Length > 0 ? part2Parts[0].Trim() : ""; + string part3 = part2Parts.Length > 1 ? part2Parts[1].Trim() : ""; + + string details; + try + { + if (titleParts[1].Contains("COMMAND")) + details = "Idling in the Command Line"; + else + details = part2; + } + catch (Exception c) + { + Console.WriteLine(c); + return; + } + + + string status; + try + { + status = part3; + } + catch (Exception c) + { + Console.WriteLine(c); + return; + } + + try + { + Client.SetPresence(new RichPresence + { + Details = details, + State = status, + Timestamps = new Timestamps(DateTime.UtcNow), + Assets = new Assets() + { + LargeImageKey = "dos", + LargeImageText = "DOSBox-X" + } + }); + Console.WriteLine("Presence successfully set!"); + } + catch (Exception) + { + Console.WriteLine("Presence was not set successfully!"); + return; + } + } + } + } +} diff --git a/readme.md b/readme.md index b12d259..05a2a7d 100644 --- a/readme.md +++ b/readme.md @@ -6,6 +6,8 @@ Bheithir is a program that sets Discord Rich Presence (RPC) status for various e ## What emulators are supported right now? - [DOSBox](https://www.dosbox.com/) - [MS-DOS](https://en.wikipedia.org/wiki/MS-DOS) emulator primarilly designed for playing games +- [DOSBox-X](https://dosbox-x.com/) + - Fork of [DOSBox](https://www.dosbox.com/) an [MS-DOS](https://en.wikipedia.org/wiki/MS-DOS) emulator primarilly designed for playing games - [FCEUX](http://www.fceux.com/web/home.html) - [NES](https://en.wikipedia.org/wiki/Nintendo_Entertainment_System) - [SNES9X](http://www.snes9x.com/)