mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use source generator for resume JSON serializing.
This commit is contained in:
Submodule Aaru.CommonTypes updated: 4c11c82189...e5d8b627a1
@@ -37,7 +37,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.AaruMetadata;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
@@ -301,12 +300,7 @@ public partial class Dump
|
||||
JsonSerializer.Serialize(fs, new ResumeJson
|
||||
{
|
||||
Resume = _resume
|
||||
}, new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
IncludeFields = true,
|
||||
WriteIndented = true
|
||||
});
|
||||
}, typeof(ResumeJson), ResumeJsonContext.Default);
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.AaruMetadata;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
@@ -2069,7 +2068,7 @@ public sealed class ImageConvertViewModel : ViewModelBase
|
||||
Name = UI.Dialog_Choose_existing_resume_file,
|
||||
Extensions = new List<string>(new[]
|
||||
{
|
||||
".xml"
|
||||
".json"
|
||||
})
|
||||
});
|
||||
|
||||
@@ -2079,12 +2078,15 @@ public sealed class ImageConvertViewModel : ViewModelBase
|
||||
result.Length != 1)
|
||||
return;
|
||||
|
||||
var sidecarXs = new XmlSerializer(typeof(Resume));
|
||||
|
||||
try
|
||||
{
|
||||
var sr = new StreamReader(result[0]);
|
||||
var resume = (Resume)sidecarXs.Deserialize(sr);
|
||||
var fs = new FileStream(result[0], FileMode.Open);
|
||||
|
||||
Resume resume =
|
||||
(await JsonSerializer.DeserializeAsync(fs, typeof(ResumeJson),
|
||||
ResumeJsonContext.Default) as ResumeJson)?.Resume;
|
||||
|
||||
fs.Close();
|
||||
|
||||
if(resume?.Tries?.Any() == false)
|
||||
{
|
||||
@@ -2096,8 +2098,6 @@ public sealed class ImageConvertViewModel : ViewModelBase
|
||||
GetMessageBoxStandardWindow(UI.Title_Error,
|
||||
UI.Resume_file_does_not_contain_dump_hardware_information,
|
||||
icon: Icon.Error).ShowDialog(_view);
|
||||
|
||||
sr.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -39,7 +39,6 @@ using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
@@ -705,12 +704,9 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
{
|
||||
var fs = new FileStream(_outputPrefix + ".resume.json", FileMode.Open);
|
||||
|
||||
_resume = JsonSerializer.Deserialize<ResumeJson>(fs, new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
IncludeFields = true,
|
||||
WriteIndented = true
|
||||
})?.Resume;
|
||||
_resume =
|
||||
(await JsonSerializer.DeserializeAsync(fs, typeof(ResumeJson), ResumeJsonContext.Default) as
|
||||
ResumeJson)?.Resume;
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
@@ -718,10 +714,18 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
// DEPRECATED: To be removed in Aaru 7
|
||||
else if(File.Exists(_outputPrefix + ".resume.xml"))
|
||||
{
|
||||
// Should be covered by virtue of being the same exact class as the JSON above
|
||||
#pragma warning disable IL2026
|
||||
var xs = new XmlSerializer(typeof(Resume));
|
||||
#pragma warning restore IL2026
|
||||
|
||||
var sr = new StreamReader(_outputPrefix + ".resume.xml");
|
||||
|
||||
// Should be covered by virtue of being the same exact class as the JSON above
|
||||
#pragma warning disable IL2026
|
||||
_resume = (Resume)xs.Deserialize(sr);
|
||||
#pragma warning restore IL2026
|
||||
|
||||
sr.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.AaruMetadata;
|
||||
@@ -333,11 +332,18 @@ sealed class ConvertImageCommand : Command
|
||||
if(File.Exists(cicmXml))
|
||||
try
|
||||
{
|
||||
// Should be covered by virtue of being the same exact class as the JSON above
|
||||
#pragma warning disable IL2026
|
||||
var xs = new XmlSerializer(typeof(CICMMetadataType));
|
||||
#pragma warning restore IL2026
|
||||
|
||||
var sr = new StreamReader(cicmXml);
|
||||
|
||||
// Should be covered by virtue of being the same exact class as the JSON above
|
||||
#pragma warning disable IL2026
|
||||
sidecar = (CICMMetadataType)xs.Deserialize(sr);
|
||||
#pragma warning restore IL2026
|
||||
|
||||
sr.Close();
|
||||
}
|
||||
catch(Exception ex)
|
||||
@@ -364,11 +370,9 @@ sealed class ConvertImageCommand : Command
|
||||
{
|
||||
var fs = new FileStream(resumeFile, FileMode.Open);
|
||||
|
||||
resume = JsonSerializer.Deserialize<ResumeJson>(fs, new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
})?.Resume;
|
||||
resume =
|
||||
(JsonSerializer.Deserialize(fs, typeof(ResumeJson),
|
||||
ResumeJsonContext.Default) as ResumeJson)?.Resume;
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Xml.Serialization;
|
||||
using Aaru.CommonTypes;
|
||||
@@ -479,16 +478,13 @@ sealed class DumpMediaCommand : Command
|
||||
{
|
||||
try
|
||||
{
|
||||
if(File.Exists(outputPrefix + "resume.json"))
|
||||
if(File.Exists(outputPrefix + ".resume.json"))
|
||||
{
|
||||
var fs = new FileStream(outputPrefix + ".resume.json", FileMode.Open);
|
||||
|
||||
resumeClass = JsonSerializer.Deserialize<ResumeJson>(fs, new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
IncludeFields = true,
|
||||
WriteIndented = true
|
||||
})?.Resume;
|
||||
resumeClass =
|
||||
(JsonSerializer.Deserialize(fs, typeof(ResumeJson),
|
||||
ResumeJsonContext.Default) as ResumeJson)?.Resume;
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
@@ -496,9 +492,18 @@ sealed class DumpMediaCommand : Command
|
||||
// DEPRECATED: To be removed in Aaru 7
|
||||
else if(File.Exists(outputPrefix + ".resume.xml") && resume)
|
||||
{
|
||||
// Should be covered by virtue of being the same exact class as the JSON above
|
||||
#pragma warning disable IL2026
|
||||
var xs = new XmlSerializer(typeof(Resume));
|
||||
#pragma warning restore IL2026
|
||||
|
||||
var sr = new StreamReader(outputPrefix + ".resume.xml");
|
||||
|
||||
// Should be covered by virtue of being the same exact class as the JSON above
|
||||
#pragma warning disable IL2026
|
||||
resumeClass = (Resume)xs.Deserialize(sr);
|
||||
#pragma warning restore IL2026
|
||||
|
||||
sr.Close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user