Skip to content

Commit

Permalink
Merge pull request #3 from itsho/patch-1
Browse files Browse the repository at this point in the history
avoid few nulls while iterating SmartAttributes
  • Loading branch information
krugertech authored Jan 19, 2022
2 parents 82ca049 + fc85341 commit 55660ae
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Smart.Net/WmiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ public static DriveCollection GetSmartInformation()
if (id == 0) continue;

var attr = drive.SmartAttributes.GetAttribute(id);
attr.Current = value;
attr.Worst = worst;
attr.Data = vendordata;
attr.IsOK = failureImminent == false;
if (attr != null)
{
attr.Current = value;
attr.Worst = worst;
attr.Data = vendordata;
attr.IsOK = failureImminent == false;
}
}
catch(Exception ex)
{
Expand All @@ -126,10 +129,13 @@ public static DriveCollection GetSmartInformation()
if (id == 0) continue;

var attr = drive.SmartAttributes.GetAttribute(id);
attr.Threshold = thresh;
if (attr != null)
{
attr.Threshold = thresh;

// Debug
// Console.WriteLine("{0}\t {1}\t {2}\t {3}\t " + attr.Data + " " + ((attr.IsOK) ? "OK" : ""), attr.Name, attr.Current, attr.Worst, attr.Threshold);
// Debug
// Console.WriteLine("{0}\t {1}\t {2}\t {3}\t " + attr.Data + " " + ((attr.IsOK) ? "OK" : ""), attr.Name, attr.Current, attr.Worst, attr.Threshold);
}
}
catch(Exception ex)
{
Expand Down

0 comments on commit 55660ae

Please sign in to comment.