2017-12-29 00:46:03 +00:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ConvertImage.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Verbs.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Converts from one media image to another.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2017-12-29 00:46:03 +00:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
using System.CommandLine;
|
|
|
|
|
|
using System.CommandLine.Invocation;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2018-01-28 21:26:41 +00:00
|
|
|
|
using System.Xml.Serialization;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Metadata;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Structs;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
using DiscImageChef.Core;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
using Schemas;
|
2019-01-05 16:59:23 +00:00
|
|
|
|
using ImageInfo = DiscImageChef.CommonTypes.Structs.ImageInfo;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using Version = DiscImageChef.CommonTypes.Interop.Version;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
2020-01-03 17:41:19 +00:00
|
|
|
|
namespace DiscImageChef.Commands.Image
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
internal class ConvertImageCommand : Command
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2020-01-03 18:24:44 +00:00
|
|
|
|
public ConvertImageCommand() : base("convert", "Converts one image to another format.")
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Add(new Option(new[]
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
"--cicm-xml", "-x"
|
|
|
|
|
|
}, "Take metadata from existing CICM XML sidecar.")
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--comments", "Image comments.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option(new[]
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
"--count", "-c"
|
|
|
|
|
|
}, "How many sectors to convert at once.")
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Argument = new Argument<int>(() => 64), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--creator", "Who (person) created the image?.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--drive-manufacturer",
|
|
|
|
|
|
"Manufacturer of the drive used to read the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--drive-model", "Model of the drive used to read the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--drive-revision",
|
|
|
|
|
|
"Firmware revision of the drive used to read the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--drive-serial",
|
|
|
|
|
|
"Serial number of the drive used to read the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option(new[]
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
"--force", "-f"
|
|
|
|
|
|
}, "Continue conversion even if sector or media tags will be lost in the process.")
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Argument = new Argument<bool>(() => false), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option(new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
"--format", "-p"
|
|
|
|
|
|
},
|
|
|
|
|
|
"Format of the output image, as plugin name or plugin id. If not present, will try to detect it from output image extension.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-barcode", "Barcode of the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-lastsequence",
|
|
|
|
|
|
"Last media of the sequence the media represented by the image corresponds to.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<int>(() => 0), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-manufacturer", "Manufacturer of the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-model", "Model of the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-partnumber", "Part number of the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-sequence", "Number in sequence for the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<int>(() => 0), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-serial", "Serial number of the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option("--media-title", "Title of the media represented by the image.")
|
|
|
|
|
|
{
|
|
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option(new[]
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
"--options", "-O"
|
|
|
|
|
|
}, "Comma separated name=value pairs of options to pass to output image plugin.")
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Add(new Option(new[]
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
"--resume-file", "-r"
|
|
|
|
|
|
}, "Take list of dump hardware from existing resume file.")
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Argument = new Argument<string>(() => null), Required = false
|
|
|
|
|
|
});
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
AddArgument(new Argument<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
Arity = ArgumentArity.ExactlyOne, Description = "Input image path", Name = "input-path"
|
|
|
|
|
|
});
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
AddArgument(new Argument<string>
|
2019-01-05 16:59:23 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Arity = ArgumentArity.ExactlyOne, Description = "Output image path", Name = "output-path"
|
|
|
|
|
|
});
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:18:55 +00:00
|
|
|
|
public static int Invoke(bool verbose, bool debug, string cicmXml, string comments, int count, string creator,
|
|
|
|
|
|
string driveFirmwareRevision, string driveManufacturer, string driveModel,
|
|
|
|
|
|
string driveSerialNumber, bool force, string inputPath, int lastMediaSequence,
|
2020-01-03 17:41:19 +00:00
|
|
|
|
string mediaBarcode, string mediaManufacturer, string mediaModel,
|
|
|
|
|
|
string mediaPartNumber, int mediaSequence, string mediaSerialNumber, string mediaTitle,
|
|
|
|
|
|
string outputPath, string outputOptions, string resumeFile, string format)
|
2020-01-02 04:09:39 +00:00
|
|
|
|
{
|
2019-01-05 16:59:23 +00:00
|
|
|
|
MainClass.PrintCopyright();
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(debug)
|
|
|
|
|
|
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(verbose)
|
|
|
|
|
|
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
Statistics.AddCommand("convert-image");
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--cicm-xml={0}", cicmXml);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--comments={0}", comments);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--count={0}", count);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--creator={0}", creator);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--debug={0}", debug);
|
2019-01-05 16:59:23 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--drive-manufacturer={0}", driveManufacturer);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--drive-model={0}", driveModel);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--drive-revision={0}", driveFirmwareRevision);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--drive-serial={0}", driveSerialNumber);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--force={0}", force);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--format={0}", format);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--input={0}", inputPath);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-barcode={0}", mediaBarcode);
|
2019-01-05 16:59:23 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-lastsequence={0}", lastMediaSequence);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-manufacturer={0}", mediaManufacturer);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-model={0}", mediaModel);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-partnumber={0}", mediaPartNumber);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-sequence={0}", mediaSequence);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-serial={0}", mediaSerialNumber);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--media-title={0}", mediaTitle);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--options={0}", outputOptions);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--output={0}", outputPath);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--resume-file={0}", resumeFile);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--verbose={0}", verbose);
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
Dictionary<string, string> parsedOptions = Core.Options.Parse(outputOptions);
|
2018-01-17 19:10:46 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "Parsed options:");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-28 16:05:54 +00:00
|
|
|
|
foreach(KeyValuePair<string, string> parsedOption in parsedOptions)
|
2018-01-17 19:10:46 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "{0} = {1}", parsedOption.Key, parsedOption.Value);
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(count == 0)
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Need to specify more than 0 sectors to copy at once");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.InvalidArgument;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-28 21:26:41 +00:00
|
|
|
|
Resume resume = null;
|
|
|
|
|
|
CICMMetadataType sidecar = null;
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
var xs = new XmlSerializer(typeof(CICMMetadataType));
|
|
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(cicmXml != null)
|
|
|
|
|
|
if(File.Exists(cicmXml))
|
2018-01-28 21:26:41 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
var sr = new StreamReader(cicmXml);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sidecar = (CICMMetadataType)xs.Deserialize(sr);
|
2018-01-28 21:26:41 +00:00
|
|
|
|
sr.Close();
|
|
|
|
|
|
}
|
2020-02-01 19:44:55 +00:00
|
|
|
|
catch(Exception ex)
|
2018-01-28 21:26:41 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing...");
|
2020-02-01 19:44:55 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Image conversion", $"{ex}");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.InvalidSidecar;
|
2018-01-28 21:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing...");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.FileNotFound;
|
2018-01-28 21:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
xs = new XmlSerializer(typeof(Resume));
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(resumeFile != null)
|
|
|
|
|
|
if(File.Exists(resumeFile))
|
2018-01-28 21:26:41 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
var sr = new StreamReader(resumeFile);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
resume = (Resume)xs.Deserialize(sr);
|
2018-01-28 21:26:41 +00:00
|
|
|
|
sr.Close();
|
|
|
|
|
|
}
|
2020-02-01 19:44:55 +00:00
|
|
|
|
catch(Exception ex)
|
2018-01-28 21:26:41 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Incorrect resume file, not continuing...");
|
2020-02-01 19:44:55 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Image conversion", $"{ex}");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.InvalidResume;
|
2018-01-28 21:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Could not find resume file, not continuing...");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.FileNotFound;
|
2018-01-28 21:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
|
IFilter inputFilter = filtersList.GetFilter(inputPath);
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
|
|
|
|
|
if(inputFilter == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Cannot open specified file.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.CannotOpenFile;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(File.Exists(outputPath))
|
2018-01-18 23:18:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Output file already exists, not continuing.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.DestinationExists;
|
2018-01-18 23:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-20 22:53:46 +01:00
|
|
|
|
PluginBase plugins = GetPluginBase.Instance;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
|
|
|
|
|
|
|
|
|
|
|
|
if(inputFormat == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.WriteLine("Input image format not identified, not proceeding with conversion.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.UnrecognizedFormat;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(verbose)
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.VerboseWriteLine("Input image format identified by {0} ({1}).", inputFormat.Name,
|
|
|
|
|
|
inputFormat.Id);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.WriteLine("Input image format identified by {0}.", inputFormat.Name);
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!inputFormat.Open(inputFilter))
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.WriteLine("Unable to open image format");
|
|
|
|
|
|
DicConsole.WriteLine("No error given");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.CannotOpenFormat;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Convert-image command", "Correctly opened image file.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Convert-image command", "Image without headers is {0} bytes.",
|
|
|
|
|
|
inputFormat.Info.ImageSize);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Convert-image command", "Image has {0} sectors.", inputFormat.Info.Sectors);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Convert-image command", "Image identifies media type as {0}.",
|
|
|
|
|
|
inputFormat.Info.MediaType);
|
|
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
Statistics.AddMediaFormat(inputFormat.Format);
|
|
|
|
|
|
Statistics.AddMedia(inputFormat.Info.MediaType, false);
|
|
|
|
|
|
Statistics.AddFilter(inputFilter.Name);
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Unable to open image format");
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Convert-image command", "Stack trace: {0}", ex.StackTrace);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.CannotOpenFormat;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<IWritableImage> candidates = new List<IWritableImage>();
|
|
|
|
|
|
|
|
|
|
|
|
// Try extension
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(string.IsNullOrEmpty(format))
|
2017-12-29 00:46:03 +00:00
|
|
|
|
candidates.AddRange(plugins.WritableImages.Values.Where(t =>
|
2020-01-02 04:09:39 +00:00
|
|
|
|
t.KnownExtensions.
|
|
|
|
|
|
Contains(Path.GetExtension(outputPath))));
|
|
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
// Try Id
|
2020-01-02 04:09:39 +00:00
|
|
|
|
else if(Guid.TryParse(format, out Guid outId))
|
2017-12-29 00:46:03 +00:00
|
|
|
|
candidates.AddRange(plugins.WritableImages.Values.Where(t => t.Id.Equals(outId)));
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
// Try name
|
|
|
|
|
|
else
|
2020-01-02 04:09:39 +00:00
|
|
|
|
candidates.AddRange(plugins.WritableImages.Values.Where(t => string.Equals(t.Name, format,
|
|
|
|
|
|
StringComparison.
|
|
|
|
|
|
InvariantCultureIgnoreCase)));
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
|
|
|
|
|
if(candidates.Count == 0)
|
|
|
|
|
|
{
|
2018-01-01 20:01:37 +00:00
|
|
|
|
DicConsole.WriteLine("No plugin supports requested extension.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.FormatNotFound;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(candidates.Count > 1)
|
|
|
|
|
|
{
|
2018-01-01 20:01:37 +00:00
|
|
|
|
DicConsole.WriteLine("More than one plugin supports requested extension.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.TooManyFormats;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IWritableImage outputFormat = candidates[0];
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(verbose)
|
2017-12-29 01:17:57 +00:00
|
|
|
|
DicConsole.VerboseWriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.WriteLine("Output image format: {0}.", outputFormat.Name);
|
2017-12-29 01:17:57 +00:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
if(!outputFormat.SupportedMediaTypes.Contains(inputFormat.Info.MediaType))
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Output format does not support media type, cannot continue...");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.UnsupportedMedia;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags)
|
|
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(outputFormat.SupportedMediaTags.Contains(mediaTag) || force)
|
|
|
|
|
|
continue;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
2018-01-01 20:01:37 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Converting image will lose media tag {0}, not continuing...", mediaTag);
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("If you don't care, use force option.");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.DataWillBeLost;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool useLong = inputFormat.Info.ReadableSectorTags.Count != 0;
|
|
|
|
|
|
|
2018-01-01 20:01:37 +00:00
|
|
|
|
foreach(SectorTagType sectorTag in inputFormat.Info.ReadableSectorTags)
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(outputFormat.SupportedSectorTags.Contains(sectorTag))
|
|
|
|
|
|
continue;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(force)
|
2018-01-01 20:01:37 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(sectorTag != SectorTagType.CdTrackFlags &&
|
|
|
|
|
|
sectorTag != SectorTagType.CdTrackIsrc &&
|
|
|
|
|
|
sectorTag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
useLong = false;
|
|
|
|
|
|
|
2018-01-01 20:01:37 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Converting image will lose sector tag {0}, not continuing...", sectorTag);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.
|
|
|
|
|
|
ErrorWriteLine("If you don't care, use force option. This will skip all sector tags converting only user data.");
|
|
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.DataWillBeLost;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(!outputFormat.Create(outputPath, inputFormat.Info.MediaType, parsedOptions, inputFormat.Info.Sectors,
|
2019-01-05 16:59:23 +00:00
|
|
|
|
inputFormat.Info.SectorSize))
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} creating output image.", outputFormat.ErrorMessage);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.CannotCreateFormat;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
var metadata = new ImageInfo
|
2017-12-29 01:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
Application = "DiscImageChef",
|
2018-01-01 20:56:33 +00:00
|
|
|
|
ApplicationVersion = Version.GetVersion(),
|
2019-01-05 16:59:23 +00:00
|
|
|
|
Comments = comments ?? inputFormat.Info.Comments,
|
|
|
|
|
|
Creator = creator ?? inputFormat.Info.Creator,
|
|
|
|
|
|
DriveFirmwareRevision = driveFirmwareRevision ?? inputFormat.Info.DriveFirmwareRevision,
|
|
|
|
|
|
DriveManufacturer = driveManufacturer ?? inputFormat.Info.DriveManufacturer,
|
|
|
|
|
|
DriveModel = driveModel ?? inputFormat.Info.DriveModel,
|
|
|
|
|
|
DriveSerialNumber = driveSerialNumber ?? inputFormat.Info.DriveSerialNumber,
|
|
|
|
|
|
LastMediaSequence = lastMediaSequence != 0 ? lastMediaSequence : inputFormat.Info.LastMediaSequence,
|
|
|
|
|
|
MediaBarcode = mediaBarcode ?? inputFormat.Info.MediaBarcode,
|
|
|
|
|
|
MediaManufacturer = mediaManufacturer ?? inputFormat.Info.MediaManufacturer,
|
|
|
|
|
|
MediaModel = mediaModel ?? inputFormat.Info.MediaModel,
|
|
|
|
|
|
MediaPartNumber = mediaPartNumber ?? inputFormat.Info.MediaPartNumber,
|
|
|
|
|
|
MediaSequence = mediaSequence != 0 ? mediaSequence : inputFormat.Info.MediaSequence,
|
|
|
|
|
|
MediaSerialNumber = mediaSerialNumber ?? inputFormat.Info.MediaSerialNumber,
|
|
|
|
|
|
MediaTitle = mediaTitle ?? inputFormat.Info.MediaTitle
|
2017-12-29 01:17:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(!outputFormat.SetMetadata(metadata))
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWrite("Error {0} setting metadata, ", outputFormat.ErrorMessage);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(!force)
|
2017-12-29 01:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("not continuing...");
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2017-12-29 01:17:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.ErrorWriteLine("continuing...");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
CICMMetadataType cicmMetadata = inputFormat.CicmMetadata;
|
|
|
|
|
|
List<DumpHardwareType> dumpHardware = inputFormat.DumpHardware;
|
|
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags)
|
|
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(force && !outputFormat.SupportedMediaTags.Contains(mediaTag))
|
|
|
|
|
|
continue;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.WriteLine("Converting media tag {0}", mediaTag);
|
|
|
|
|
|
byte[] tag = inputFormat.ReadDiskTag(mediaTag);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(outputFormat.WriteMediaTag(tag, mediaTag))
|
|
|
|
|
|
continue;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(force)
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing media tag, continuing...", outputFormat.ErrorMessage);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing media tag, not continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("{0} sectors to convert", inputFormat.Info.Sectors);
|
|
|
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(inputFormat is IOpticalMediaImage inputOptical &&
|
|
|
|
|
|
outputFormat is IWritableOpticalImage outputOptical &&
|
2019-04-16 01:12:00 +01:00
|
|
|
|
inputOptical.Tracks != null)
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2019-01-20 20:11:10 +00:00
|
|
|
|
if(!outputOptical.SetTracks(inputOptical.Tracks))
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2019-01-20 20:11:10 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} sending tracks list to output image.",
|
|
|
|
|
|
outputFormat.ErrorMessage);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2018-01-01 20:01:37 +00:00
|
|
|
|
}
|
2018-01-01 20:56:33 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
foreach(Track track in inputOptical.Tracks)
|
2018-01-01 20:01:37 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
doneSectors = 0;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
ulong trackSectors = (track.TrackEndSector - track.TrackStartSector) + 1;
|
2018-01-01 20:56:33 +00:00
|
|
|
|
|
2018-01-01 20:01:37 +00:00
|
|
|
|
while(doneSectors < trackSectors)
|
2017-12-29 00:46:03 +00:00
|
|
|
|
{
|
2018-01-01 20:01:37 +00:00
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
|
|
uint sectorsToDo;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(trackSectors - doneSectors >= (ulong)count)
|
|
|
|
|
|
sectorsToDo = (uint)count;
|
|
|
|
|
|
else
|
|
|
|
|
|
sectorsToDo = (uint)(trackSectors - doneSectors);
|
2018-01-01 20:01:37 +00:00
|
|
|
|
|
2018-01-03 17:33:19 +00:00
|
|
|
|
DicConsole.Write("\rConverting sectors {0} to {1} in track {3} ({2:P2} done)",
|
2018-06-22 08:08:38 +01:00
|
|
|
|
doneSectors + track.TrackStartSector,
|
|
|
|
|
|
doneSectors + sectorsToDo + track.TrackStartSector,
|
2018-01-03 19:36:30 +00:00
|
|
|
|
(doneSectors + track.TrackStartSector) / (double)inputFormat.Info.Sectors,
|
|
|
|
|
|
track.TrackSequence);
|
2018-01-01 20:01:37 +00:00
|
|
|
|
|
|
|
|
|
|
bool result;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-01 20:01:37 +00:00
|
|
|
|
if(useLong)
|
|
|
|
|
|
if(sectorsToDo == 1)
|
|
|
|
|
|
{
|
2018-01-01 20:56:33 +00:00
|
|
|
|
sector = inputFormat.ReadSectorLong(doneSectors + track.TrackStartSector);
|
2018-01-01 20:01:37 +00:00
|
|
|
|
result = outputFormat.WriteSectorLong(sector, doneSectors + track.TrackStartSector);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sector = inputFormat.ReadSectorsLong(doneSectors + track.TrackStartSector, sectorsToDo);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
result = outputFormat.WriteSectorsLong(sector, doneSectors + track.TrackStartSector,
|
|
|
|
|
|
sectorsToDo);
|
2018-01-01 20:01:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sectorsToDo == 1)
|
|
|
|
|
|
{
|
2018-01-01 20:56:33 +00:00
|
|
|
|
sector = inputFormat.ReadSector(doneSectors + track.TrackStartSector);
|
2018-01-01 20:01:37 +00:00
|
|
|
|
result = outputFormat.WriteSector(sector, doneSectors + track.TrackStartSector);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sector = inputFormat.ReadSectors(doneSectors + track.TrackStartSector, sectorsToDo);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
result = outputFormat.WriteSectors(sector, doneSectors + track.TrackStartSector,
|
|
|
|
|
|
sectorsToDo);
|
2018-01-01 20:01:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!result)
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(force)
|
2018-01-01 20:01:37 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2018-01-01 20:01:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doneSectors += sectorsToDo;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
2018-01-03 19:36:30 +00:00
|
|
|
|
}
|
2017-12-29 00:46:03 +00:00
|
|
|
|
|
2018-01-03 19:36:30 +00:00
|
|
|
|
DicConsole.Write("\rConverting sectors {0} to {1} in track {3} ({2:P2} done)", inputFormat.Info.Sectors,
|
2019-01-20 20:11:10 +00:00
|
|
|
|
inputFormat.Info.Sectors, 1.0, inputOptical.Tracks.Count);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-03 19:36:30 +00:00
|
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
|
|
|
|
|
|
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.OrderBy(t => t))
|
|
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(!useLong)
|
|
|
|
|
|
break;
|
2018-01-01 22:19:31 +00:00
|
|
|
|
|
2018-01-03 19:36:30 +00:00
|
|
|
|
switch(tag)
|
2018-01-01 22:19:31 +00:00
|
|
|
|
{
|
2018-01-03 19:36:30 +00:00
|
|
|
|
case SectorTagType.AppleSectorTag:
|
|
|
|
|
|
case SectorTagType.CdSectorSync:
|
|
|
|
|
|
case SectorTagType.CdSectorHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorEdc:
|
|
|
|
|
|
case SectorTagType.CdSectorEccP:
|
|
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
|
|
|
|
|
case SectorTagType.CdSectorEcc:
|
|
|
|
|
|
// This tags are inline in long sector
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(force && !outputFormat.SupportedSectorTags.Contains(tag))
|
|
|
|
|
|
continue;
|
2018-01-01 22:19:31 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
foreach(Track track in inputOptical.Tracks)
|
2018-01-03 19:36:30 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
doneSectors = 0;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
ulong trackSectors = (track.TrackEndSector - track.TrackStartSector) + 1;
|
2018-01-01 22:19:31 +00:00
|
|
|
|
byte[] sector;
|
|
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SectorTagType.CdTrackFlags:
|
|
|
|
|
|
case SectorTagType.CdTrackIsrc:
|
2018-01-03 19:36:30 +00:00
|
|
|
|
DicConsole.Write("\rConverting tag {0} in track {1} ({2:P2} done).", tag,
|
2019-01-20 20:11:10 +00:00
|
|
|
|
track.TrackSequence,
|
|
|
|
|
|
track.TrackSequence / (double)inputOptical.Tracks.Count);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-01 22:19:31 +00:00
|
|
|
|
sector = inputFormat.ReadSectorTag(track.TrackStartSector, tag);
|
|
|
|
|
|
result = outputFormat.WriteSectorTag(sector, track.TrackStartSector, tag);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
if(!result)
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(force)
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing tag, continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing tag, not continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 22:19:31 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while(doneSectors < trackSectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint sectorsToDo;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(trackSectors - doneSectors >= (ulong)count)
|
|
|
|
|
|
sectorsToDo = (uint)count;
|
2018-01-01 22:19:31 +00:00
|
|
|
|
else
|
2020-01-02 04:09:39 +00:00
|
|
|
|
sectorsToDo = (uint)(trackSectors - doneSectors);
|
2018-01-01 22:19:31 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.Write("\rConverting tag {4} for sectors {0} to {1} in track {3} ({2:P2} done)",
|
2018-06-22 08:08:38 +01:00
|
|
|
|
doneSectors + track.TrackStartSector,
|
|
|
|
|
|
doneSectors + sectorsToDo + track.TrackStartSector,
|
2018-01-03 19:36:30 +00:00
|
|
|
|
(doneSectors + track.TrackStartSector) / (double)inputFormat.Info.Sectors,
|
|
|
|
|
|
track.TrackSequence, tag);
|
2018-01-01 22:19:31 +00:00
|
|
|
|
|
|
|
|
|
|
if(sectorsToDo == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectorTag(doneSectors + track.TrackStartSector, tag);
|
|
|
|
|
|
result = outputFormat.WriteSectorTag(sector, doneSectors + track.TrackStartSector, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectorsTag(doneSectors + track.TrackStartSector, sectorsToDo,
|
|
|
|
|
|
tag);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-01 22:19:31 +00:00
|
|
|
|
result = outputFormat.WriteSectorsTag(sector, doneSectors + track.TrackStartSector,
|
|
|
|
|
|
sectorsToDo, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!result)
|
2019-01-05 16:59:23 +00:00
|
|
|
|
if(force)
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing tag for sector {1}, continuing...",
|
2018-01-01 22:19:31 +00:00
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing tag for sector {1}, not continuing...",
|
2018-01-01 22:19:31 +00:00
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2018-01-01 22:19:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doneSectors += sectorsToDo;
|
|
|
|
|
|
}
|
2018-01-03 19:36:30 +00:00
|
|
|
|
}
|
2018-01-01 22:19:31 +00:00
|
|
|
|
|
2018-01-03 19:36:30 +00:00
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SectorTagType.CdTrackFlags:
|
|
|
|
|
|
case SectorTagType.CdTrackIsrc:
|
2019-01-20 20:11:10 +00:00
|
|
|
|
DicConsole.Write("\rConverting tag {0} in track {1} ({2:P2} done).", tag,
|
|
|
|
|
|
inputOptical.Tracks.Count, 1.0);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-03 19:36:30 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
DicConsole.Write("\rConverting tag {4} for sectors {0} to {1} in track {3} ({2:P2} done)",
|
2019-01-20 20:11:10 +00:00
|
|
|
|
inputFormat.Info.Sectors, inputFormat.Info.Sectors, 1.0,
|
|
|
|
|
|
inputOptical.Tracks.Count, tag);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2018-01-03 19:36:30 +00:00
|
|
|
|
break;
|
2018-01-01 22:19:31 +00:00
|
|
|
|
}
|
2018-01-03 19:36:30 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine();
|
2018-01-01 20:01:37 +00:00
|
|
|
|
}
|
2018-01-03 19:36:30 +00:00
|
|
|
|
}
|
2019-01-20 20:11:10 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.WriteLine("Setting geometry to {0} cylinders, {1} heads and {2} sectors per track",
|
|
|
|
|
|
inputFormat.Info.Cylinders, inputFormat.Info.Heads,
|
|
|
|
|
|
inputFormat.Info.SectorsPerTrack);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
if(!outputFormat.SetGeometry(inputFormat.Info.Cylinders, inputFormat.Info.Heads,
|
|
|
|
|
|
inputFormat.Info.SectorsPerTrack))
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} setting geometry, image may be incorrect, continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage);
|
|
|
|
|
|
|
|
|
|
|
|
while(doneSectors < inputFormat.Info.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
|
|
uint sectorsToDo;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(inputFormat.Info.Sectors - doneSectors >= (ulong)count)
|
|
|
|
|
|
sectorsToDo = (uint)count;
|
2019-01-20 20:11:10 +00:00
|
|
|
|
else
|
2020-01-02 04:09:39 +00:00
|
|
|
|
sectorsToDo = (uint)(inputFormat.Info.Sectors - doneSectors);
|
2019-01-20 20:11:10 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.Write("\rConverting sectors {0} to {1} ({2:P2} done)", doneSectors,
|
|
|
|
|
|
doneSectors + sectorsToDo, doneSectors / (double)inputFormat.Info.Sectors);
|
|
|
|
|
|
|
|
|
|
|
|
bool result;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
if(useLong)
|
|
|
|
|
|
if(sectorsToDo == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectorLong(doneSectors);
|
|
|
|
|
|
result = outputFormat.WriteSectorLong(sector, doneSectors);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectorsLong(doneSectors, sectorsToDo);
|
|
|
|
|
|
result = outputFormat.WriteSectorsLong(sector, doneSectors, sectorsToDo);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sectorsToDo == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSector(doneSectors);
|
|
|
|
|
|
result = outputFormat.WriteSector(sector, doneSectors);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectors(doneSectors, sectorsToDo);
|
|
|
|
|
|
result = outputFormat.WriteSectors(sector, doneSectors, sectorsToDo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!result)
|
|
|
|
|
|
if(force)
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2019-01-20 20:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doneSectors += sectorsToDo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.Write("\rConverting sectors {0} to {1} ({2:P2} done)", inputFormat.Info.Sectors,
|
|
|
|
|
|
inputFormat.Info.Sectors, 1.0);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
|
|
|
|
|
|
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags)
|
|
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(!useLong)
|
|
|
|
|
|
break;
|
2019-01-20 20:11:10 +00:00
|
|
|
|
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SectorTagType.AppleSectorTag:
|
|
|
|
|
|
case SectorTagType.CdSectorSync:
|
|
|
|
|
|
case SectorTagType.CdSectorHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorEdc:
|
|
|
|
|
|
case SectorTagType.CdSectorEccP:
|
|
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
|
|
|
|
|
case SectorTagType.CdSectorEcc:
|
|
|
|
|
|
// This tags are inline in long sector
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
if(force && !outputFormat.SupportedSectorTags.Contains(tag))
|
|
|
|
|
|
continue;
|
2019-01-20 20:11:10 +00:00
|
|
|
|
|
|
|
|
|
|
doneSectors = 0;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
while(doneSectors < inputFormat.Info.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
|
|
uint sectorsToDo;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(inputFormat.Info.Sectors - doneSectors >= (ulong)count)
|
|
|
|
|
|
sectorsToDo = (uint)count;
|
2019-01-20 20:11:10 +00:00
|
|
|
|
else
|
2020-01-02 04:09:39 +00:00
|
|
|
|
sectorsToDo = (uint)(inputFormat.Info.Sectors - doneSectors);
|
2019-01-20 20:11:10 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.Write("\rConverting tag {2} for sectors {0} to {1} ({2:P2} done)", doneSectors,
|
|
|
|
|
|
doneSectors + sectorsToDo, doneSectors / (double)inputFormat.Info.Sectors,
|
|
|
|
|
|
tag);
|
|
|
|
|
|
|
|
|
|
|
|
bool result;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
if(sectorsToDo == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectorTag(doneSectors, tag);
|
|
|
|
|
|
result = outputFormat.WriteSectorTag(sector, doneSectors, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = inputFormat.ReadSectorsTag(doneSectors, sectorsToDo, tag);
|
|
|
|
|
|
result = outputFormat.WriteSectorsTag(sector, doneSectors, sectorsToDo, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!result)
|
|
|
|
|
|
if(force)
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
|
|
|
|
|
|
outputFormat.ErrorMessage, doneSectors);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
return(int)ErrorNumber.WriteError;
|
2019-01-20 20:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doneSectors += sectorsToDo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.Write("\rConverting tag {2} for sectors {0} to {1} ({2:P2} done)",
|
|
|
|
|
|
inputFormat.Info.Sectors, inputFormat.Info.Sectors, 1.0, tag);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
2019-01-20 20:11:10 +00:00
|
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-01-01 20:56:33 +00:00
|
|
|
|
|
2018-01-28 21:34:52 +00:00
|
|
|
|
bool ret = false;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(resume != null ||
|
|
|
|
|
|
dumpHardware != null)
|
2018-01-28 21:34:52 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
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.");
|
2018-01-28 21:34:52 +00:00
|
|
|
|
}
|
2018-01-28 21:26:41 +00:00
|
|
|
|
|
2018-01-28 21:34:52 +00:00
|
|
|
|
ret = false;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
|
|
|
|
|
|
if(sidecar != null ||
|
|
|
|
|
|
cicmMetadata != null)
|
2018-01-28 21:34:52 +00:00
|
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
|
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.");
|
2018-01-28 21:34:52 +00:00
|
|
|
|
}
|
2018-01-28 20:29:46 +00:00
|
|
|
|
|
2017-12-29 00:46:03 +00:00
|
|
|
|
DicConsole.WriteLine("Closing output image.");
|
|
|
|
|
|
|
|
|
|
|
|
if(!outputFormat.Close())
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} closing output image... Contents are not correct.",
|
|
|
|
|
|
outputFormat.ErrorMessage);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
|
DicConsole.WriteLine("Conversion done.");
|
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
|
return(int)ErrorNumber.NoError;
|
2017-12-29 00:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|