Skip to content

Commit

Permalink
Fix service crash if EC date parsing fails
Browse files Browse the repository at this point in the history
This is a workaround for issue #61, where certain EC firmware dates appear to be causing FormatExceptions which crashes the YAMDCC service.
  • Loading branch information
Sparronator9999 committed Feb 15, 2025
1 parent 6082b92 commit 619b9e8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions YAMDCC.Service/FanControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ protected override void OnStart(string[] args)
}
if (_EC.ReadString(0xAC, 0x10, out string ecDate) && ecDate.Length == 0x10)
{
string temp = $"{ecDate.Substring(4, 4)}-{ecDate.Substring(0, 2)}-{ecDate.Substring(2, 2)}" +
try
{
string temp = $"{ecDate.Substring(4, 4)}-{ecDate.Substring(0, 2)}-{ecDate.Substring(2, 2)}" +
$"T{ecDate.Substring(8, 2)}:{ecDate.Substring(11, 2)}:{ecDate.Substring(14, 2)}";
EcInfo.Date = DateTime.ParseExact(temp, "s", CultureInfo.InvariantCulture);
Log.Debug($"EC firmware date: {EcInfo.Date:G}");
EcInfo.Date = DateTime.ParseExact(temp, "s", CultureInfo.InvariantCulture);
Log.Debug($"EC firmware date: {EcInfo.Date:G}");
}
catch (FormatException ex)
{
Log.Error($"Failed to parse EC firmware date: {ex.Message}");
Log.Debug($"EC firmware date (raw): {ecDate}");
}
}
}

Expand Down

0 comments on commit 619b9e8

Please sign in to comment.