Use the official JSON parser (#1151)
This remove Utf8son and JsonPrettyPrinter dependencies. NOTE: the standard JSON parser doesn't support configurable indentation, as a result, all the pretty printed JSON are indented with 2 spaces.
This commit is contained in:
parent
7ab3fccd4d
commit
886e42fb19
19 changed files with 388 additions and 396 deletions
|
@ -1,8 +1,5 @@
|
|||
using Gdk;
|
||||
using System;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System.IO;
|
||||
using Utf8Json;
|
||||
using Utf8Json.Resolvers;
|
||||
|
||||
namespace Ryujinx.Debugger.Profiler
|
||||
{
|
||||
|
@ -21,48 +18,12 @@ namespace Ryujinx.Debugger.Profiler
|
|||
/// <param name="path">The path to the JSON configuration file</param>
|
||||
public static ProfilerConfiguration Load(string path)
|
||||
{
|
||||
var resolver = CompositeResolver.Create(
|
||||
new[] { new ConfigurationEnumFormatter<Key>() },
|
||||
new[] { StandardResolver.AllowPrivateSnakeCase }
|
||||
);
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException($"Profiler configuration file {path} not found");
|
||||
}
|
||||
|
||||
using (Stream stream = File.OpenRead(path))
|
||||
{
|
||||
return JsonSerializer.Deserialize<ProfilerConfiguration>(stream, resolver);
|
||||
}
|
||||
}
|
||||
|
||||
private class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
|
||||
where T : struct
|
||||
{
|
||||
public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
|
||||
{
|
||||
formatterResolver.GetFormatterWithVerify<string>()
|
||||
.Serialize(ref writer, value.ToString(), formatterResolver);
|
||||
}
|
||||
|
||||
public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
|
||||
{
|
||||
if (reader.ReadIsNull())
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
string enumName = formatterResolver.GetFormatterWithVerify<string>()
|
||||
.Deserialize(ref reader, formatterResolver);
|
||||
|
||||
if (Enum.TryParse<T>(enumName, out T result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
return JsonHelper.DeserializeFromFile<ProfilerConfiguration>(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue