Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion to System.Text.Json #1209

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/XIVLauncher.Common.Unix/UnixDalamudRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text.Json;
using Serilog;
using XIVLauncher.Common.Dalamud;
using XIVLauncher.Common.PlatformAbstractions;
Expand Down Expand Up @@ -94,7 +94,7 @@ public UnixDalamudRunner(CompatibilityTools compatibility, DirectoryInfo dotnetR

try
{
var dalamudConsoleOutput = JsonConvert.DeserializeObject<DalamudConsoleOutput>(output);
var dalamudConsoleOutput = JsonSerializer.Deserialize<DalamudConsoleOutput>(output);
var unixPid = compatibility.GetUnixProcessId(dalamudConsoleOutput.Pid);

if (unixPid == 0)
Expand All @@ -107,7 +107,7 @@ public UnixDalamudRunner(CompatibilityTools compatibility, DirectoryInfo dotnetR
Log.Verbose($"Got game process handle {gameProcess.Handle} with Unix pid {gameProcess.Id} and Wine pid {dalamudConsoleOutput.Pid}");
return gameProcess;
}
catch (JsonReaderException ex)
catch (JsonException ex)
{
Log.Error(ex, $"Couldn't parse Dalamud output: {output}");
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/XIVLauncher.Common.Windows/WindowsDalamudRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.Text.Json;
using Serilog;
using XIVLauncher.Common.Dalamud;
using XIVLauncher.Common.PlatformAbstractions;
Expand Down Expand Up @@ -72,7 +72,7 @@ public class WindowsDalamudRunner : IDalamudRunner

try
{
var dalamudConsoleOutput = JsonConvert.DeserializeObject<DalamudConsoleOutput>(output);
var dalamudConsoleOutput = JsonSerializer.Deserialize<DalamudConsoleOutput>(output);
Process gameProcess;

if (dalamudConsoleOutput.Handle == 0)
Expand Down Expand Up @@ -101,7 +101,7 @@ public class WindowsDalamudRunner : IDalamudRunner

return gameProcess;
}
catch (JsonReaderException ex)
catch (JsonException ex)
{
Log.Error(ex, $"Couldn't parse Dalamud output: {output}");
return null;
Expand Down
11 changes: 5 additions & 6 deletions src/XIVLauncher.Common/CommonUniqueIdCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using XIVLauncher.Common.PlatformAbstractions;

namespace XIVLauncher.PlatformAbstractions
Expand All @@ -24,10 +25,8 @@ public CommonUniqueIdCache(FileInfo saveFile)

private readonly FileInfo configFile;

public void Save()
{
File.WriteAllText(configFile.FullName, JsonConvert.SerializeObject(_cache, Formatting.Indented));
}
public void Save() =>
File.WriteAllText(configFile.FullName, JsonSerializer.Serialize(_cache, new JsonSerializerOptions { WriteIndented = true }));

public void Load()
{
Expand All @@ -37,7 +36,7 @@ public void Load()
return;
}

_cache = JsonConvert.DeserializeObject<List<UniqueIdCacheEntry>>(File.ReadAllText(configFile.FullName)) ?? new List<UniqueIdCacheEntry>();
_cache = JsonSerializer.Deserialize<List<UniqueIdCacheEntry>>(File.ReadAllText(configFile.FullName)) ?? new List<UniqueIdCacheEntry>();
}

public void Reset()
Expand Down
6 changes: 3 additions & 3 deletions src/XIVLauncher.Common/Dalamud/DalamudConsoleOutput.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace XIVLauncher.Common.Dalamud
{
public sealed class DalamudConsoleOutput
{
[JsonProperty("pid")]
[JsonPropertyName("pid")]
public int Pid { get; set; }

[JsonProperty("handle")]
[JsonPropertyName("handle")]
public long Handle { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/XIVLauncher.Common/Dalamud/DalamudLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Net;
using System.Threading;
using Newtonsoft.Json;
using System.Text.Json;
using Serilog;
using XIVLauncher.Common.PlatformAbstractions;

Expand Down Expand Up @@ -152,7 +152,7 @@ public static bool CanRunDalamud(DirectoryInfo gamePath)
using var client = new WebClient();

var versionInfoJson = client.DownloadString(REMOTE_BASE + "release");
var remoteVersionInfo = JsonConvert.DeserializeObject<DalamudVersionInfo>(versionInfoJson);
var remoteVersionInfo = JsonSerializer.Deserialize<DalamudVersionInfo>(versionInfoJson);

if (Repository.Ffxiv.GetVer(gamePath) != remoteVersionInfo.SupportedGameVer)
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Common/Dalamud/DalamudSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.IO;
using Newtonsoft.Json;
using System.Text.Json;
using Serilog;

namespace XIVLauncher.Common.Dalamud
Expand All @@ -20,7 +20,7 @@ public static DalamudSettings GetSettings(DirectoryInfo configFolder)

try
{
deserialized = File.Exists(configPath) ? JsonConvert.DeserializeObject<DalamudSettings>(File.ReadAllText(configPath)) : new DalamudSettings();
deserialized = File.Exists(configPath) ? JsonSerializer.Deserialize<DalamudSettings>(File.ReadAllText(configPath)) : new DalamudSettings();
}
catch (Exception ex)
{
Expand Down
10 changes: 5 additions & 5 deletions src/XIVLauncher.Common/Dalamud/DalamudUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text.Json;
using Serilog;
using XIVLauncher.Common.PlatformAbstractions;
using XIVLauncher.Common.Util;
Expand Down Expand Up @@ -149,7 +149,7 @@ private static string GetBetaTrackName(DalamudSettings settings) =>

var versionInfoJsonRelease = await client.GetStringAsync(DalamudLauncher.REMOTE_BASE + $"release&bucket={this.RolloutBucket}").ConfigureAwait(false);

DalamudVersionInfo versionInfoRelease = JsonConvert.DeserializeObject<DalamudVersionInfo>(versionInfoJsonRelease);
DalamudVersionInfo versionInfoRelease = JsonSerializer.Deserialize<DalamudVersionInfo>(versionInfoJsonRelease);

DalamudVersionInfo? versionInfoStaging = null;

Expand All @@ -158,7 +158,7 @@ private static string GetBetaTrackName(DalamudSettings settings) =>
var versionInfoJsonStaging = await client.GetAsync(DalamudLauncher.REMOTE_BASE + GetBetaTrackName(settings)).ConfigureAwait(false);

if (versionInfoJsonStaging.StatusCode != HttpStatusCode.BadRequest)
versionInfoStaging = JsonConvert.DeserializeObject<DalamudVersionInfo>(await versionInfoJsonStaging.Content.ReadAsStringAsync().ConfigureAwait(false));
versionInfoStaging = JsonSerializer.Deserialize<DalamudVersionInfo>(await versionInfoJsonStaging.Content.ReadAsStringAsync().ConfigureAwait(false));
}

return (versionInfoRelease, versionInfoStaging);
Expand Down Expand Up @@ -186,7 +186,7 @@ private async Task UpdateDalamud()
Log.Information("[DUPDATE] Using release version ({Hash})", remoteVersionInfo.AssemblyVersion);
}

var versionInfoJson = JsonConvert.SerializeObject(remoteVersionInfo);
var versionInfoJson = JsonSerializer.Serialize(remoteVersionInfo);

var addonPath = new DirectoryInfo(Path.Combine(this.addonDirectory.FullName, "Hooks"));
var currentVersionPath = new DirectoryInfo(Path.Combine(addonPath.FullName, remoteVersionInfo.AssemblyVersion));
Expand Down Expand Up @@ -332,7 +332,7 @@ private static bool CheckIntegrity(DirectoryInfo directory, string hashesJson)
{
Log.Verbose("[DUPDATE] Checking integrity of {Directory}", directory.FullName);

var hashes = JsonConvert.DeserializeObject<Dictionary<string, string>>(hashesJson);
var hashes = JsonSerializer.Deserialize<Dictionary<string, string>>(hashesJson);

foreach (var hash in hashes)
{
Expand Down
16 changes: 14 additions & 2 deletions src/XIVLauncher.Common/Dalamud/DalamudVersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
using System.IO;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace XIVLauncher.Common.Dalamud
{
internal class DalamudVersionInfo
{
[JsonPropertyName("assemblyVersion")]
public string AssemblyVersion { get; set; }

[JsonPropertyName("supportedGameVer")]
public string SupportedGameVer { get; set; }

[JsonPropertyName("runtimeVersion")]
public string RuntimeVersion { get; set; }

[JsonPropertyName("runtimeRequired")]
public bool RuntimeRequired { get; set; }

[JsonPropertyName("key")]
public string Key { get; set; }

[JsonPropertyName("downloadUrl")]
public string DownloadUrl { get; set; }

public static DalamudVersionInfo Load(FileInfo file) =>
JsonConvert.DeserializeObject<DalamudVersionInfo>(File.ReadAllText(file.FullName));
JsonSerializer.Deserialize<DalamudVersionInfo>(File.ReadAllText(file.FullName));
}
}
8 changes: 4 additions & 4 deletions src/XIVLauncher.Common/Game/GateStatus.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace XIVLauncher.Common.Game;

public class GateStatus
{
[JsonProperty("status")]
[JsonPropertyName("status")]
public bool Status { get; set; }

[JsonProperty("message")]
[JsonPropertyName("message")]
public List<string> Message { get; set; }

[JsonProperty("news")]
[JsonPropertyName("news")]
public List<string> News { get; set; }
}
42 changes: 15 additions & 27 deletions src/XIVLauncher.Common/Game/Headlines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,52 @@
using System.Globalization;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json;
using System.Text.Json.Serialization;
using XIVLauncher.Common.Util;

namespace XIVLauncher.Common.Game
{
public partial class Headlines
{
[JsonProperty("news")]
[JsonPropertyName("news")]
public News[] News { get; set; }

[JsonProperty("topics")]
[JsonPropertyName("topics")]
public News[] Topics { get; set; }

[JsonProperty("pinned")]
[JsonPropertyName("pinned")]
public News[] Pinned { get; set; }

[JsonProperty("banner")]
[JsonPropertyName("banner")]
public Banner[] Banner { get; set; }
}

public class Banner
{
[JsonProperty("lsb_banner")]
[JsonPropertyName("lsb_banner")]
public Uri LsbBanner { get; set; }

[JsonProperty("link")]
[JsonPropertyName("link")]
public Uri Link { get; set; }
}

public class News
{
[JsonProperty("date")]
[JsonPropertyName("date")]
public DateTimeOffset Date { get; set; }

[JsonProperty("title")]
[JsonPropertyName("title")]
public string Title { get; set; }

[JsonProperty("url")]
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonProperty("id")]
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonProperty("tag", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("tag")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Tag { get; set; }
}

Expand All @@ -60,20 +61,7 @@ public static async Task<Headlines> Get(Launcher game, ClientLanguage language,

var json = Encoding.UTF8.GetString(await game.DownloadAsLauncher(url, language, "application/json, text/plain, */*").ConfigureAwait(false));

return JsonConvert.DeserializeObject<Headlines>(json, Converter.SETTINGS);
return JsonSerializer.Deserialize<Headlines>(json);
}
}

internal static class Converter
{
public static readonly JsonSerializerSettings SETTINGS = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
}
};
}
}
4 changes: 2 additions & 2 deletions src/XIVLauncher.Common/Game/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text.Json;
using Serilog;
using XIVLauncher.Common.Game.Patch.PatchList;
using XIVLauncher.Common.Encryption;
Expand Down Expand Up @@ -617,7 +617,7 @@ public async Task<GateStatus> GetGateStatus(ClientLanguage language)
await DownloadAsLauncher(
$"https://frontier.ffxiv.com/worldStatus/gate_status.json?lang={language.GetLangCode()}&_={ApiHelpers.GetUnixMillis()}", language).ConfigureAwait(true));

return JsonConvert.DeserializeObject<GateStatus>(reply);
return JsonSerializer.Deserialize<GateStatus>(reply);
}
catch (Exception exc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
*/

using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace AriaNet.Attributes
{
public class AriaFile
{
[JsonProperty("index")]
[JsonPropertyName("index")]
public string Index { get; set; }

[JsonProperty("length")]
[JsonPropertyName("length")]
public string Length { get; set; }

[JsonProperty("completedLength")]
[JsonPropertyName("completedLength")]
public string CompletedLength { get; set; }

[JsonProperty("path")]
[JsonPropertyName("path")]
public string Path { get; set; }

[JsonProperty("selected")]
[JsonPropertyName("selected")]
public string Selected { get; set; }

[JsonProperty("uris")]
[JsonPropertyName("uris")]
public List<AriaUri> Uris { get; set; }
}
}
Loading