mirror of
https://github.com/aaru-dps/Aaru.git
synced 2026-05-19 20:06:24 +00:00
Use JSON for resume file instead of XML.
This commit is contained in:
Submodule Aaru.CommonTypes updated: 73730c4e0f...24c8aa3476
Submodule Aaru.Console updated: b5dcb2b058...72ff6760c1
@@ -36,7 +36,8 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
@@ -292,9 +293,21 @@ public partial class Dump
|
||||
if(File.Exists(_outputPrefix + ".resume.xml"))
|
||||
File.Delete(_outputPrefix + ".resume.xml");
|
||||
|
||||
var fs = new FileStream(_outputPrefix + ".resume.xml", FileMode.Create, FileAccess.ReadWrite);
|
||||
var xs = new XmlSerializer(_resume.GetType());
|
||||
xs.Serialize(fs, _resume);
|
||||
if(File.Exists(_outputPrefix + ".resume.json"))
|
||||
File.Delete(_outputPrefix + ".resume.json");
|
||||
|
||||
var fs = new FileStream(_outputPrefix + ".resume.json", FileMode.Create, FileAccess.ReadWrite);
|
||||
|
||||
JsonSerializer.Serialize(fs, new ResumeJson
|
||||
{
|
||||
Resume = _resume
|
||||
}, new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
IncludeFields = true,
|
||||
WriteIndented = true
|
||||
});
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ using System.IO;
|
||||
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;
|
||||
@@ -692,13 +694,32 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
async Task CheckResumeFile()
|
||||
{
|
||||
_resume = null;
|
||||
var xs = new XmlSerializer(typeof(Resume));
|
||||
|
||||
try
|
||||
{
|
||||
var sr = new StreamReader(_outputPrefix + ".resume.xml");
|
||||
_resume = (Resume)xs.Deserialize(sr);
|
||||
sr.Close();
|
||||
if(File.Exists(_outputPrefix + ".resume.json"))
|
||||
{
|
||||
var fs = new FileStream(_outputPrefix + ".resume.json", FileMode.Open);
|
||||
|
||||
_resume = JsonSerializer.Deserialize<ResumeJson>(fs, new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
IncludeFields = true,
|
||||
WriteIndented = true
|
||||
})?.Resume;
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
// DEPRECATED: To be removed in Aaru 7
|
||||
else if(File.Exists(_outputPrefix + ".resume.xml"))
|
||||
{
|
||||
var xs = new XmlSerializer(typeof(Resume));
|
||||
|
||||
var sr = new StreamReader(_outputPrefix + ".resume.xml");
|
||||
_resume = (Resume)xs.Deserialize(sr);
|
||||
sr.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -39,6 +39,8 @@ using System.Globalization;
|
||||
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;
|
||||
@@ -465,12 +467,31 @@ sealed class DumpMediaCommand : Command
|
||||
Resume resumeClass = null;
|
||||
var xs = new XmlSerializer(typeof(Resume));
|
||||
|
||||
if(File.Exists(outputPrefix + ".resume.xml") && resume)
|
||||
if(resume)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sr = new StreamReader(outputPrefix + ".resume.xml");
|
||||
resumeClass = (Resume)xs.Deserialize(sr);
|
||||
sr.Close();
|
||||
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;
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
// DEPRECATED: To be removed in Aaru 7
|
||||
else if(File.Exists(outputPrefix + ".resume.xml") && resume)
|
||||
{
|
||||
var sr = new StreamReader(outputPrefix + ".resume.xml");
|
||||
resumeClass = (Resume)xs.Deserialize(sr);
|
||||
sr.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -481,6 +502,7 @@ sealed class DumpMediaCommand : Command
|
||||
|
||||
return (int)ErrorNumber.InvalidResume;
|
||||
}
|
||||
}
|
||||
|
||||
if(resumeClass != null &&
|
||||
resumeClass.NextBlock > resumeClass.LastBlock &&
|
||||
|
||||
Reference in New Issue
Block a user