Skip to content

Commit

Permalink
Fixed crash on startup by implementing check to see if a given regist…
Browse files Browse the repository at this point in the history
…ry value exists.
  • Loading branch information
BuildTools committed Oct 3, 2018
1 parent f543490 commit 87be2d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion DisableNvidiaTelemetry/Controller/NvidiaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public static IEnumerable<NvidiaControllerResult<TelemetryRegistryKey>> Enumerat
error = ex;
}

yield return new NvidiaControllerResult<TelemetryRegistryKey>(telemetryRegistryKey, error) {Name = key.Name};
if (key.exists())
yield return new NvidiaControllerResult<TelemetryRegistryKey>(telemetryRegistryKey, error) { Name = key.Name };
else
yield return new NvidiaControllerResult<TelemetryRegistryKey>(null, new RegistryKeyNotFoundException($"Failed to find registry key: {key.Name}"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion DisableNvidiaTelemetry/Model/TaskNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DisableNvidiaTelemetry.Model
{
/// <summary>
/// Represents an exception where a secheduled task could not be found.
/// Represents an exception where a scheduled task could not be found.
/// </summary>
public class TaskNotFoundException : Exception
{
Expand Down
21 changes: 21 additions & 0 deletions DisableNvidiaTelemetry/Model/TelemetryRegistryKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ public Replacement(Regex regex, string replacment)
public string Replacment { get; }
}

/// <summary>Check to see if the value exists.</summary>
/// <returns>True if it exists, false if not.</returns>
public bool exists()
{
var subKey = SubKey;

try
{
if (_useRegex)
ValueExpressions.Select(vd => vd.Value.Match.IsMatch(subKey.GetValue(vd.Key).ToString())).FirstOrDefault();
else
ValueStrings.Any(vd => subKey.GetValue(vd.Key).ToString() == vd.Value.Enabled);
}
catch (System.NullReferenceException)
{
return false;
}

return true;
}

#region Implementation of ITelemetry

public bool IsActive()
Expand Down

0 comments on commit 87be2d1

Please sign in to comment.