diff options
author | sr55 <[email protected]> | 2020-12-01 21:49:55 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2020-12-01 21:50:19 +0000 |
commit | cfdf6a9be140726b01b65b212d55eae63d2f86c0 (patch) | |
tree | 3448c4ce5f0c8785e300ed2013655afb8426e4f5 /win/CS/HandBrake.Interop | |
parent | 223cfcd18aef673dfad8564093e4fc37cbcb5441 (diff) |
WinGui: Removing the dependency on Newtonsoft.Json library in HandBrake.Interop and HandBrake.worker. Using System.Text.Json instead. UI will be updated seperately.
Diffstat (limited to 'win/CS/HandBrake.Interop')
10 files changed, 51 insertions, 39 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrake.Interop.csproj b/win/CS/HandBrake.Interop/HandBrake.Interop.csproj index 9663551f1..546241e59 100644 --- a/win/CS/HandBrake.Interop/HandBrake.Interop.csproj +++ b/win/CS/HandBrake.Interop/HandBrake.Interop.csproj @@ -17,8 +17,4 @@ <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> </PropertyGroup> - <ItemGroup> - <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> - </ItemGroup> - </Project> diff --git a/win/CS/HandBrake.Interop/HandBrake.Interop.nuspec b/win/CS/HandBrake.Interop/HandBrake.Interop.nuspec index cb6d167f5..c45d86a05 100644 --- a/win/CS/HandBrake.Interop/HandBrake.Interop.nuspec +++ b/win/CS/HandBrake.Interop/HandBrake.Interop.nuspec @@ -13,10 +13,6 @@ <description>$description$</description> <copyright>Copyright © 2003-2020 HandBrake Team</copyright> <tags>Open-Source Video Transcoder</tags> - - <dependencies> - <dependency id="Newtonsoft.Json" version="12.0.2" /> - </dependencies> </metadata> <files> diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeFilterHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeFilterHelpers.cs index 878b56512..92c792df0 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeFilterHelpers.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeFilterHelpers.cs @@ -13,13 +13,13 @@ namespace HandBrake.Interop.Interop using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; + using System.Text.Json; using HandBrake.Interop.Interop.HbLib; using HandBrake.Interop.Interop.Helpers; using HandBrake.Interop.Interop.Json.Filters; using HandBrake.Interop.Interop.Model.Encoding; - - using Newtonsoft.Json; + using HandBrake.Interop.Json; /// <summary> /// The hand brake filter helpers. @@ -39,7 +39,7 @@ namespace HandBrake.Interop.Interop { IntPtr ptr = HBFunctions.hb_filter_get_presets_json(filter); string result = Marshal.PtrToStringAnsi(ptr); - List<PresetTune> list = JsonConvert.DeserializeObject<List<PresetTune>>(result); + List<PresetTune> list = JsonSerializer.Deserialize<List<PresetTune>>(result, JsonSettings.Options); return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList(); } @@ -57,7 +57,7 @@ namespace HandBrake.Interop.Interop { IntPtr ptr = HBFunctions.hb_filter_get_tunes_json(filter); string result = Marshal.PtrToStringAnsi(ptr); - List<PresetTune> list = JsonConvert.DeserializeObject<List<PresetTune>>(result); + List<PresetTune> list = JsonSerializer.Deserialize<List<PresetTune>>(result, JsonSettings.Options); return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList(); } @@ -98,7 +98,7 @@ namespace HandBrake.Interop.Interop IntPtr ptr = HBFunctions.hb_generate_filter_settings_json(filter, presetName, null, null); string result = Marshal.PtrToStringAnsi(ptr); - return JsonConvert.DeserializeObject<Dictionary<string, string>>(result); + return JsonSerializer.Deserialize<Dictionary<string, string>>(result, JsonSettings.Options); } public static string GenerateFilterSettingJson(int filterId, string preset, string tune, string custom) diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs index c9ee15cb8..f08ae1407 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs @@ -15,7 +15,9 @@ namespace HandBrake.Interop.Interop using System.Linq; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; + using System.Text.Json; using System.Timers; + using System.Xml; using HandBrake.Interop.Interop.EventArgs; using HandBrake.Interop.Interop.Factories; @@ -27,8 +29,7 @@ namespace HandBrake.Interop.Interop using HandBrake.Interop.Interop.Json.State; using HandBrake.Interop.Interop.Model.Encoding; using HandBrake.Interop.Interop.Model.Preview; - - using Newtonsoft.Json; + using HandBrake.Interop.Json; public class HandBrakeInstance : IHandBrakeInstance, IDisposable { @@ -260,12 +261,7 @@ namespace HandBrake.Interop.Interop [HandleProcessCorruptedStateExceptions] public void StartEncode(JsonEncodeObject encodeObject) { - JsonSerializerSettings settings = new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore, - }; - - string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings); + string encode = JsonSerializer.Serialize(encodeObject, JsonSettings.Options); this.StartEncode(encode); } @@ -349,7 +345,7 @@ namespace HandBrake.Interop.Interop IntPtr json = HBFunctions.hb_get_state_json(this.Handle); string statusJson = Marshal.PtrToStringAnsi(json); - JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson); + JsonState state = JsonSerializer.Deserialize<JsonState>(statusJson, JsonSettings.Options); return state; } @@ -411,7 +407,7 @@ namespace HandBrake.Interop.Interop JsonState state = null; if (!string.IsNullOrEmpty(statusJson)) { - state = JsonConvert.DeserializeObject<JsonState>(statusJson); + state = JsonSerializer.Deserialize<JsonState>(statusJson, JsonSettings.Options); } TaskState taskState = state != null ? TaskState.FromRepositoryValue(state.State) : null; @@ -432,7 +428,7 @@ namespace HandBrake.Interop.Interop if (!string.IsNullOrEmpty(this.TitlesJson)) { - this.Titles = JsonConvert.DeserializeObject<JsonScanObject>(this.TitlesJson); + this.Titles = JsonSerializer.Deserialize<JsonScanObject>(this.TitlesJson, JsonSettings.Options); if (this.Titles != null) { this.FeatureTitle = this.Titles.MainFeature; @@ -455,7 +451,7 @@ namespace HandBrake.Interop.Interop IntPtr json = HBFunctions.hb_get_state_json(this.Handle); string statusJson = Marshal.PtrToStringAnsi(json); - JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson); + JsonState state = JsonSerializer.Deserialize<JsonState>(statusJson, JsonSettings.Options); TaskState taskState = state != null ? TaskState.FromRepositoryValue(state.State) : null; diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs b/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs index c16cf9a59..ab928f723 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs @@ -13,13 +13,13 @@ namespace HandBrake.Interop.Interop using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; + using System.Text.Json; using HandBrake.Interop.Interop.HbLib; using HandBrake.Interop.Interop.Helpers; using HandBrake.Interop.Interop.Json.Presets; using HandBrake.Interop.Interop.Model; - - using Newtonsoft.Json; + using HandBrake.Interop.Json; /// <summary> /// The hand brake preset service. @@ -37,7 +37,7 @@ namespace HandBrake.Interop.Interop { IntPtr presets = HBFunctions.hb_presets_builtin_get_json(); string presetJson = Marshal.PtrToStringAnsi(presets); - IList<HBPresetCategory> presetList = JsonConvert.DeserializeObject<IList<HBPresetCategory>>(presetJson); + IList<HBPresetCategory> presetList = JsonSerializer.Deserialize<IList<HBPresetCategory>>(presetJson, JsonSettings.Options); return presetList; } @@ -64,7 +64,7 @@ namespace HandBrake.Interop.Interop presetJson = "{ \"PresetList\":" + presetJson + " } "; } - PresetTransportContainer preset = JsonConvert.DeserializeObject<PresetTransportContainer>(presetJson); + PresetTransportContainer preset = JsonSerializer.Deserialize<PresetTransportContainer>(presetJson, JsonSettings.Options); return preset; } @@ -83,7 +83,7 @@ namespace HandBrake.Interop.Interop /// </param> public static void ExportPreset(string filename, PresetTransportContainer container) { - string preset = JsonConvert.SerializeObject(container, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + string preset = JsonSerializer.Serialize(container, JsonSettings.Options); using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(preset); diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs index df58e197f..e2f1fd868 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs @@ -13,13 +13,14 @@ namespace HandBrake.Interop.Interop using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; + using System.Text.Json; + using System.Xml; using HandBrake.Interop.Interop.EventArgs; using HandBrake.Interop.Interop.HbLib; using HandBrake.Interop.Interop.Json.Anamorphic; using HandBrake.Interop.Interop.Json.Shared; - - using Newtonsoft.Json; + using HandBrake.Interop.Json; /// <summary> /// HandBrake Interop Utilities @@ -294,10 +295,10 @@ namespace HandBrake.Interop.Interop /// <returns>The final size and PAR of the video.</returns> public static Geometry GetAnamorphicSize(AnamorphicGeometry anamorphicGeometry) { - string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + string encode = JsonSerializer.Serialize(anamorphicGeometry, JsonSettings.Options); IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode)); string result = Marshal.PtrToStringAnsi(json); - return JsonConvert.DeserializeObject<Geometry>(result); + return JsonSerializer.Deserialize<Geometry>(result, JsonSettings.Options); } public static void Reduce(long den, long num, out long x, out long y) diff --git a/win/CS/HandBrake.Interop/Interop/Json/Encode/Filter.cs b/win/CS/HandBrake.Interop/Interop/Json/Encode/Filter.cs index ae73a8ebd..477ff28bf 100644 --- a/win/CS/HandBrake.Interop/Interop/Json/Encode/Filter.cs +++ b/win/CS/HandBrake.Interop/Interop/Json/Encode/Filter.cs @@ -9,7 +9,7 @@ namespace HandBrake.Interop.Interop.Json.Encode { - using Newtonsoft.Json.Linq; + using System.Text.Json; /// <summary> /// The filter list. @@ -24,6 +24,6 @@ namespace HandBrake.Interop.Interop.Json.Encode /// <summary> /// Gets or sets the settings. /// </summary> - public JToken Settings { get; set; } + public JsonDocument Settings { get; set; } } }
\ No newline at end of file diff --git a/win/CS/HandBrake.Interop/Interop/Json/Encode/Video.cs b/win/CS/HandBrake.Interop/Interop/Json/Encode/Video.cs index 56af62869..f7391eaa3 100644 --- a/win/CS/HandBrake.Interop/Interop/Json/Encode/Video.cs +++ b/win/CS/HandBrake.Interop/Interop/Json/Encode/Video.cs @@ -70,7 +70,7 @@ namespace HandBrake.Interop.Interop.Json.Encode /// <summary> /// Gets or sets the quality. /// </summary> - public double? Quality { get; set; } + public decimal? Quality { get; set; } /// <summary> /// Gets or sets the tune. diff --git a/win/CS/HandBrake.Interop/Interop/Json/Scan/SubtitleAttributes.cs b/win/CS/HandBrake.Interop/Interop/Json/Scan/SubtitleAttributes.cs index 1cc2eaec4..491fdff5b 100644 --- a/win/CS/HandBrake.Interop/Interop/Json/Scan/SubtitleAttributes.cs +++ b/win/CS/HandBrake.Interop/Interop/Json/Scan/SubtitleAttributes.cs @@ -9,11 +9,11 @@ namespace HandBrake.Interop.Interop.Json.Scan { - using Newtonsoft.Json; + using System.Text.Json.Serialization; public class SubtitleAttributes { - [JsonProperty(PropertyName = "4By3")] + [JsonPropertyName("4By3")] public bool FourByThree { get; set; } public bool Children { get; set; } diff --git a/win/CS/HandBrake.Interop/Json/JsonSettings.cs b/win/CS/HandBrake.Interop/Json/JsonSettings.cs new file mode 100644 index 000000000..56cb229cc --- /dev/null +++ b/win/CS/HandBrake.Interop/Json/JsonSettings.cs @@ -0,0 +1,23 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="JsonSettings.cs" company="HandBrake Project (https://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the JsonSettings type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Json +{ + using System.Text.Json; + + public class JsonSettings + { + public static JsonSerializerOptions Options = new JsonSerializerOptions + { + IgnoreNullValues = true, + WriteIndented = true, + PropertyNameCaseInsensitive = true + }; + } +} |