Skip to content

Commit

Permalink
Less throwing, more catching
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaltin committed Jul 16, 2024
1 parent bb6acc4 commit 5da74ab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions MDRP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,35 +1178,54 @@ private static void LoadSettings()
iterator++;
if (!line.StartsWith("#") && !string.IsNullOrWhiteSpace(line))
{
try
string[] explodedLine = Regex.Split(line, @"==");
if (explodedLine.Length != 6)
{
Functions.SendToDebugServer("Invalid formatting on line " + iterator + ". Please follow the format 'executable name==display name==enabled==discord application id==console color==asset link'");
}
else
{
string[] explodedLine = Regex.Split(line, @"==");
if (bool.Parse(explodedLine[2]))
try
{
if (bool.Parse(explodedLine[2]))
{
//Format: executable name==display name==enabled==discord application id==console color==asset link
string execName = explodedLine[0];
string displayName = explodedLine[1];
string appid = explodedLine[3];
ConsoleColor color;
if (Enum.IsDefined(typeof(ConsoleColor), explodedLine[4]))
{
color =
(ConsoleColor)Enum.Parse(typeof(ConsoleColor), explodedLine[4], true);
}
else
{
Functions.SendToDebugServer("The color '" + explodedLine[4] + "' is not a valid ConsoleColor in C#. Defaulting to ConsoleColor.Gray");
color = ConsoleColor.Gray;
}

string assetLink = explodedLine[5];

DefaultClients.Add(execName, new DiscordRpcClient(appid, autoEvents: false));
PlayerColors.Add(execName, color);
Aliases.Add(execName, displayName);
BigAssets.Add(execName, assetLink);
LittleAssets.Add(execName, assetLink);
Whatpeoplecallthisplayer.Add(execName, displayName);
if (!InverseWhatpeoplecallthisplayer.ContainsKey(displayName))
InverseWhatpeoplecallthisplayer.Add(displayName, execName);
ValidPlayers.Add(execName);
}
}

catch (Exception e)
{
//Format: executable name==display name==enabled==discord application id==console color==asset link
string execName = explodedLine[0];
string displayName = explodedLine[1];
string appid = explodedLine[3];
ConsoleColor color =
(ConsoleColor)Enum.Parse(typeof(ConsoleColor), explodedLine[4], true);
string assetLink = explodedLine[5];

DefaultClients.Add(execName, new DiscordRpcClient(appid, autoEvents: false));
PlayerColors.Add(execName, color);
Aliases.Add(execName, displayName);
BigAssets.Add(execName, assetLink);
LittleAssets.Add(execName, assetLink);
Whatpeoplecallthisplayer.Add(execName, displayName);
if (!InverseWhatpeoplecallthisplayer.ContainsKey(displayName))
InverseWhatpeoplecallthisplayer.Add(displayName, execName);
ValidPlayers.Add(execName);
Functions.SendToDebugServer(e);
Functions.SendToDebugServer("Invalid formatting on line " + iterator +
". Please follow the format 'executable name==display name==enabled==discord application id==console color==asset link'");
}
}
catch (Exception e)
{
Functions.SendToDebugServer(e);
Functions.SendToDebugServer("Invalid formatting on line " + iterator + ". Please follow the format 'executable name==display name==enabled==discord application id==console color==asset link'");
}
}
}
}
Expand Down
Binary file modified MDRP/bin/Release/MDRP.exe
Binary file not shown.

0 comments on commit 5da74ab

Please sign in to comment.