From b903d12ce8b76b710d005960ef20d2582776b3dd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 28 Jan 2018 21:26:41 +0000 Subject: [PATCH] Allow to use an existing metadata sidecar and resume file when converting images. --- DiscImageChef/Commands/ConvertImage.cs | 62 ++++++++++++++++++++++++-- DiscImageChef/Options.cs | 6 +++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/DiscImageChef/Commands/ConvertImage.cs b/DiscImageChef/Commands/ConvertImage.cs index b5974274..04e999c1 100644 --- a/DiscImageChef/Commands/ConvertImage.cs +++ b/DiscImageChef/Commands/ConvertImage.cs @@ -34,10 +34,12 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using DiscImageChef.Console; using DiscImageChef.Core; using DiscImageChef.DiscImages; using DiscImageChef.Filters; +using DiscImageChef.Metadata; using Schemas; using Version = DiscImageChef.Interop.Version; @@ -68,6 +70,8 @@ namespace DiscImageChef.Commands DicConsole.DebugWriteLine("Analyze command", "--drive-model={0}", options.DriveModel); DicConsole.DebugWriteLine("Analyze command", "--drive-serial={0}", options.DriveSerialNumber); DicConsole.DebugWriteLine("Analyze command", "--drive-revision={0}", options.DriveFirmwareRevision); + DicConsole.DebugWriteLine("Analyze command", "--cicm-xml={0}", options.CicmXml); + DicConsole.DebugWriteLine("Analyze command", "--resume-file={0}", options.ResumeFile); DicConsole.DebugWriteLine("Analyze command", "--options={0}", options.Options); Dictionary parsedOptions = Options.Parse(options.Options); @@ -81,6 +85,49 @@ namespace DiscImageChef.Commands return; } + Resume resume = null; + CICMMetadataType sidecar = null; + + XmlSerializer xs = new XmlSerializer(typeof(CICMMetadataType)); + if(options.CicmXml != null) + if(File.Exists(options.CicmXml)) + try + { + StreamReader sr = new StreamReader(options.CicmXml); + sidecar = (CICMMetadataType)xs.Deserialize(sr); + sr.Close(); + } + catch + { + DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing..."); + return; + } + else + { + DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing..."); + return; + } + + xs = new XmlSerializer(typeof(Resume)); + if(options.ResumeFile != null) + if(File.Exists(options.ResumeFile)) + try + { + StreamReader sr = new StreamReader(options.ResumeFile); + resume = (Resume)xs.Deserialize(sr); + sr.Close(); + } + catch + { + DicConsole.ErrorWriteLine("Incorrect resume file, not continuing..."); + return; + } + else + { + DicConsole.ErrorWriteLine("Could not find resume file, not continuing..."); + return; + } + FiltersList filtersList = new FiltersList(); IFilter inputFilter = filtersList.GetFilter(options.InputFile); @@ -588,10 +635,17 @@ namespace DiscImageChef.Commands } } - if(dumpHardware != null && outputFormat.SetDumpHardware(dumpHardware)) - DicConsole.WriteLine("Written dump hardware list to output image."); - if(cicmMetadata != null && outputFormat.SetCicmMetadata(cicmMetadata)) - DicConsole.WriteLine("Written CICM XML metadata to output image."); + bool ret; + + if(resume != null) ret = outputFormat.SetDumpHardware(resume.Tries); + else if(dumpHardware != null) + ret = outputFormat.SetDumpHardware(dumpHardware); + if(ret) DicConsole.WriteLine("Written dump hardware list to output image."); + + if(sidecar != null) ret = outputFormat.SetCicmMetadata(sidecar); + else if(cicmMetadata != null) + ret = outputFormat.SetCicmMetadata(cicmMetadata); + if(ret) DicConsole.WriteLine("Written CICM XML metadata to output image."); DicConsole.WriteLine("Closing output image."); diff --git a/DiscImageChef/Options.cs b/DiscImageChef/Options.cs index 6d63f49f..17b73072 100644 --- a/DiscImageChef/Options.cs +++ b/DiscImageChef/Options.cs @@ -432,6 +432,12 @@ namespace DiscImageChef [Option('O', "options", Default = null, HelpText = "Comma separated name=value pairs of options to pass to output image plugin")] public string Options { get; set; } + + [Option('x', "cicm-xml", Default = null, HelpText = "Take metadata from existing CICM XML sidecar.")] + public string CicmXml { get; set; } + + [Option('r', "resume-file", Default = null, HelpText = "Take list of dump hardware from existing resume file.")] + public string ResumeFile { get; set; } } [Verb("image-info", HelpText =