Преглед изворни кода

misc: chore: Change Analyzer AddSpec logic to log the non-hexadecimal value and ignore the added entry instead of throwing an exception

Evan Husted пре 1 година
родитељ
комит
395bbd144a
1 измењених фајлова са 38 додато и 15 уклоњено
  1. 38 15
      src/Ryujinx/Utilities/PlayReport/Analyzer.cs

+ 38 - 15
src/Ryujinx/Utilities/PlayReport/Analyzer.cs

@@ -1,5 +1,6 @@
 using Gommon;
 using Ryujinx.Ava.Utilities.AppLibrary;
+using Ryujinx.Common.Logging;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -27,10 +28,12 @@ namespace Ryujinx.Ava.Utilities.PlayReport
         /// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
         public Analyzer AddSpec(string titleId, Func<GameSpec, GameSpec> transform)
         {
-            Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _),
-                $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
+            if (ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _))
+                return AddSpec(transform(GameSpec.Create(titleId)));
 
-            return AddSpec(transform(GameSpec.Create(titleId)));
+            Logger.Notice.PrintMsg(LogClass.Application,
+                $"Tried to add a {nameof(GameSpec)} with a non-hexadecimal title ID value. Input: '{titleId}'");
+            return this;
         }
 
         /// <summary>
@@ -41,10 +44,12 @@ namespace Ryujinx.Ava.Utilities.PlayReport
         /// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
         public Analyzer AddSpec(string titleId, Action<GameSpec> transform)
         {
-            Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _),
-                $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
+            if (ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _))
+                return AddSpec(GameSpec.Create(titleId).Apply(transform));
 
-            return AddSpec(GameSpec.Create(titleId).Apply(transform));
+            Logger.Notice.PrintMsg(LogClass.Application,
+                $"Tried to add a {nameof(GameSpec)} with a non-hexadecimal title ID value. Input: '{titleId}'");
+            return this;
         }
 
         /// <summary>
@@ -57,10 +62,19 @@ namespace Ryujinx.Ava.Utilities.PlayReport
             Func<GameSpec, GameSpec> transform)
         {
             string[] tids = titleIds.ToArray();
-            Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)),
-                $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
-
-            return AddSpec(transform(GameSpec.Create(tids)));
+            if (tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _) && !string.IsNullOrEmpty(x)))
+                return AddSpec(transform(GameSpec.Create(tids)));
+
+            Logger.Notice.PrintMsg(LogClass.Application,
+                $"Tried to add a {nameof(GameSpec)} with a non-hexadecimal title ID value. Input: '{
+                    tids.FormatCollection(
+                        x => x,
+                        separator: ", ",
+                        prefix: "[",
+                        suffix: "]"
+                    )
+                }'");
+            return this;
         }
 
         /// <summary>
@@ -72,12 +86,21 @@ namespace Ryujinx.Ava.Utilities.PlayReport
         public Analyzer AddSpec(IEnumerable<string> titleIds, Action<GameSpec> transform)
         {
             string[] tids = titleIds.ToArray();
-            Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)),
-                $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
-
-            return AddSpec(GameSpec.Create(tids).Apply(transform));
+            if (tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _) && !string.IsNullOrEmpty(x)))
+                return AddSpec(GameSpec.Create(tids).Apply(transform));
+
+            Logger.Notice.PrintMsg(LogClass.Application,
+                $"Tried to add a {nameof(GameSpec)} with a non-hexadecimal title ID value. Input: '{
+                    tids.FormatCollection(
+                        x => x,
+                        separator: ", ",
+                        prefix: "[",
+                        suffix: "]"
+                    )
+                }'");
+            return this;
         }
-        
+
         /// <summary>
         /// Add an analysis spec matching a specific game by title ID, with the provided pre-configured spec.
         /// </summary>