Skip to content

Commit

Permalink
Fix lack of error handling when process isn't open
Browse files Browse the repository at this point in the history
  • Loading branch information
MechaDragonX committed Mar 28, 2020
1 parent f5d0880 commit eb7ac7a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class Program
private static void Main(string[] args)
{
Initialize();
while(true)
if (Process.GetProcesses().Where(x => x.ProcessName.StartsWith("DOSBox")).Count() == 0)
return;

while (true)
{
Update();
if(Process.GetProcesses().Where(x => x.ProcessName.StartsWith("DOSBox")).Count() == 0)
Expand Down Expand Up @@ -89,9 +92,16 @@ private static void Deinitialize()

private static void OnUpdate()
{
if(Process.GetProcesses().Where(x => x.ProcessName.StartsWith("DOSBox")).ToList()[0].MainWindowTitle != windowTitle)
Process process;
try
{
dos = Process.GetProcesses().Where(x => x.ProcessName.StartsWith("DOSBox")).ToList()[0];
process = Process.GetProcesses().Where(x => x.ProcessName.StartsWith("DOSBox")).ToList()[0];
}
catch(IndexOutOfRangeException) { return; }

if(process.MainWindowTitle != windowTitle)
{
dos = process;
windowTitle = dos.MainWindowTitle;
setNewPresence();
}
Expand All @@ -107,7 +117,12 @@ private static void setNewPresence()
i--;
}
}
string status = new StringBuilder($"v{titleParts[0].Split(' ')[1]}").AppendFormat(", {0}, {1}", titleParts[1], titleParts[2]).ToString();
string status;
try
{
status = new StringBuilder($"v{titleParts[0].Split(' ')[1]}").AppendFormat(", {0}, {1}", titleParts[1], titleParts[2]).ToString();
}
catch(IndexOutOfRangeException) { return; }

client.SetPresence(new RichPresence
{
Expand Down

0 comments on commit eb7ac7a

Please sign in to comment.