mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Enable sidecar creation for byte addressable images.
This commit is contained in:
@@ -52,7 +52,7 @@ namespace Aaru.Core
|
|||||||
/// <param name="imgChecksums">List of image checksums</param>
|
/// <param name="imgChecksums">List of image checksums</param>
|
||||||
/// <param name="sidecar">Metadata sidecar</param>
|
/// <param name="sidecar">Metadata sidecar</param>
|
||||||
/// <param name="encoding">Encoding to be used for filesystem plugins</param>
|
/// <param name="encoding">Encoding to be used for filesystem plugins</param>
|
||||||
static void AudioMedia(IMediaImage image, Guid filterId, string imagePath, FileInfo fi, PluginBase plugins,
|
static void AudioMedia(IBaseImage image, Guid filterId, string imagePath, FileInfo fi, PluginBase plugins,
|
||||||
List<ChecksumType> imgChecksums, ref CICMMetadataType sidecar, Encoding encoding)
|
List<ChecksumType> imgChecksums, ref CICMMetadataType sidecar, Encoding encoding)
|
||||||
{
|
{
|
||||||
sidecar.AudioMedia = new[]
|
sidecar.AudioMedia = new[]
|
||||||
|
|||||||
@@ -38,36 +38,35 @@ using Aaru.CommonTypes;
|
|||||||
using Aaru.CommonTypes.Interfaces;
|
using Aaru.CommonTypes.Interfaces;
|
||||||
using Schemas;
|
using Schemas;
|
||||||
|
|
||||||
namespace Aaru.Core
|
namespace Aaru.Core;
|
||||||
|
|
||||||
|
public sealed partial class Sidecar
|
||||||
{
|
{
|
||||||
public sealed partial class Sidecar
|
// TODO: Complete it
|
||||||
|
/// <summary>Creates a metadata sidecar for linear media (e.g. ROM chip)</summary>
|
||||||
|
/// <param name="image">Image</param>
|
||||||
|
/// <param name="filterId">Filter uuid</param>
|
||||||
|
/// <param name="imagePath">Image path</param>
|
||||||
|
/// <param name="fi">Image file information</param>
|
||||||
|
/// <param name="plugins">Image plugins</param>
|
||||||
|
/// <param name="imgChecksums">List of image checksums</param>
|
||||||
|
/// <param name="sidecar">Metadata sidecar</param>
|
||||||
|
/// <param name="encoding">Encoding to be used for filesystem plugins</param>
|
||||||
|
static void LinearMedia(IByteAddressableImage image, Guid filterId, string imagePath, FileInfo fi,
|
||||||
|
PluginBase plugins, List<ChecksumType> imgChecksums, ref CICMMetadataType sidecar,
|
||||||
|
Encoding encoding) => sidecar.LinearMedia = new[]
|
||||||
{
|
{
|
||||||
// TODO: Complete it
|
new LinearMediaType
|
||||||
/// <summary>Creates a metadata sidecar for linear media (e.g. ROM chip)</summary>
|
{
|
||||||
/// <param name="image">Image</param>
|
Checksums = imgChecksums.ToArray(),
|
||||||
/// <param name="filterId">Filter uuid</param>
|
Image = new ImageType
|
||||||
/// <param name="imagePath">Image path</param>
|
|
||||||
/// <param name="fi">Image file information</param>
|
|
||||||
/// <param name="plugins">Image plugins</param>
|
|
||||||
/// <param name="imgChecksums">List of image checksums</param>
|
|
||||||
/// <param name="sidecar">Metadata sidecar</param>
|
|
||||||
/// <param name="encoding">Encoding to be used for filesystem plugins</param>
|
|
||||||
void LinearMedia(IMediaImage image, Guid filterId, string imagePath, FileInfo fi, PluginBase plugins,
|
|
||||||
List<ChecksumType> imgChecksums, ref CICMMetadataType sidecar, Encoding encoding) =>
|
|
||||||
sidecar.LinearMedia = new[]
|
|
||||||
{
|
{
|
||||||
new LinearMediaType
|
format = image.Format,
|
||||||
{
|
offset = 0,
|
||||||
Checksums = imgChecksums.ToArray(),
|
offsetSpecified = true,
|
||||||
Image = new ImageType
|
Value = Path.GetFileName(imagePath)
|
||||||
{
|
},
|
||||||
format = image.Format,
|
Size = image.Info.Sectors
|
||||||
offset = 0,
|
}
|
||||||
offsetSpecified = true,
|
};
|
||||||
Value = Path.GetFileName(imagePath)
|
|
||||||
},
|
|
||||||
Size = (ulong)fi.Length
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -40,139 +40,155 @@ using Aaru.CommonTypes.Interfaces;
|
|||||||
using Aaru.Console;
|
using Aaru.Console;
|
||||||
using Schemas;
|
using Schemas;
|
||||||
|
|
||||||
namespace Aaru.Core
|
namespace Aaru.Core;
|
||||||
|
|
||||||
|
public sealed partial class Sidecar
|
||||||
{
|
{
|
||||||
public sealed partial class Sidecar
|
readonly ChecksumType[] _emptyChecksums;
|
||||||
|
readonly Encoding _encoding;
|
||||||
|
readonly FileInfo _fi;
|
||||||
|
readonly Guid _filterId;
|
||||||
|
readonly IBaseImage _image;
|
||||||
|
readonly string _imagePath;
|
||||||
|
readonly Checksum _imgChkWorker;
|
||||||
|
readonly PluginBase _plugins;
|
||||||
|
bool _aborted;
|
||||||
|
FileStream _fs;
|
||||||
|
CICMMetadataType _sidecar;
|
||||||
|
|
||||||
|
/// <summary>Initializes a new instance of this class</summary>
|
||||||
|
public Sidecar()
|
||||||
{
|
{
|
||||||
readonly ChecksumType[] _emptyChecksums;
|
_plugins = GetPluginBase.Instance;
|
||||||
readonly Encoding _encoding;
|
_imgChkWorker = new Checksum();
|
||||||
readonly FileInfo _fi;
|
_aborted = false;
|
||||||
readonly Guid _filterId;
|
|
||||||
readonly IMediaImage _image;
|
|
||||||
readonly string _imagePath;
|
|
||||||
readonly Checksum _imgChkWorker;
|
|
||||||
readonly PluginBase _plugins;
|
|
||||||
bool _aborted;
|
|
||||||
FileStream _fs;
|
|
||||||
CICMMetadataType _sidecar;
|
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of this class</summary>
|
var emptyChkWorker = new Checksum();
|
||||||
public Sidecar()
|
emptyChkWorker.Update(Array.Empty<byte>());
|
||||||
|
_emptyChecksums = emptyChkWorker.End().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="image">Image</param>
|
||||||
|
/// <param name="imagePath">Path to image</param>
|
||||||
|
/// <param name="filterId">Filter uuid</param>
|
||||||
|
/// <param name="encoding">Encoding for analysis</param>
|
||||||
|
public Sidecar(IBaseImage image, string imagePath, Guid filterId, Encoding encoding)
|
||||||
|
{
|
||||||
|
_image = image;
|
||||||
|
_imagePath = imagePath;
|
||||||
|
_filterId = filterId;
|
||||||
|
_encoding = encoding;
|
||||||
|
_sidecar = image.CicmMetadata ?? new CICMMetadataType();
|
||||||
|
_plugins = GetPluginBase.Instance;
|
||||||
|
_fi = new FileInfo(imagePath);
|
||||||
|
_fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
|
||||||
|
_imgChkWorker = new Checksum();
|
||||||
|
_aborted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Implements creating a metadata sidecar</summary>
|
||||||
|
/// <returns>The metadata sidecar</returns>
|
||||||
|
public CICMMetadataType Create()
|
||||||
|
{
|
||||||
|
// For fast debugging, skip checksum
|
||||||
|
//goto skipImageChecksum;
|
||||||
|
|
||||||
|
byte[] data;
|
||||||
|
long position = 0;
|
||||||
|
UpdateStatus("Hashing image file...");
|
||||||
|
InitProgress();
|
||||||
|
|
||||||
|
while(position < _fi.Length - 1048576)
|
||||||
{
|
{
|
||||||
_plugins = GetPluginBase.Instance;
|
if(_aborted)
|
||||||
_imgChkWorker = new Checksum();
|
return _sidecar;
|
||||||
_aborted = false;
|
|
||||||
|
|
||||||
var emptyChkWorker = new Checksum();
|
data = new byte[1048576];
|
||||||
emptyChkWorker.Update(Array.Empty<byte>());
|
_fs.Read(data, 0, 1048576);
|
||||||
_emptyChecksums = emptyChkWorker.End().ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <param name="image">Image</param>
|
|
||||||
/// <param name="imagePath">Path to image</param>
|
|
||||||
/// <param name="filterId">Filter uuid</param>
|
|
||||||
/// <param name="encoding">Encoding for analysis</param>
|
|
||||||
public Sidecar(IMediaImage image, string imagePath, Guid filterId, Encoding encoding)
|
|
||||||
{
|
|
||||||
_image = image;
|
|
||||||
_imagePath = imagePath;
|
|
||||||
_filterId = filterId;
|
|
||||||
_encoding = encoding;
|
|
||||||
_sidecar = image.CicmMetadata ?? new CICMMetadataType();
|
|
||||||
_plugins = GetPluginBase.Instance;
|
|
||||||
_fi = new FileInfo(imagePath);
|
|
||||||
_fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
|
|
||||||
_imgChkWorker = new Checksum();
|
|
||||||
_aborted = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Implements creating a metadata sidecar</summary>
|
|
||||||
/// <returns>The metadata sidecar</returns>
|
|
||||||
public CICMMetadataType Create()
|
|
||||||
{
|
|
||||||
// For fast debugging, skip checksum
|
|
||||||
//goto skipImageChecksum;
|
|
||||||
|
|
||||||
byte[] data;
|
|
||||||
long position = 0;
|
|
||||||
UpdateStatus("Hashing image file...");
|
|
||||||
InitProgress();
|
|
||||||
|
|
||||||
while(position < _fi.Length - 1048576)
|
|
||||||
{
|
|
||||||
if(_aborted)
|
|
||||||
return _sidecar;
|
|
||||||
|
|
||||||
data = new byte[1048576];
|
|
||||||
_fs.Read(data, 0, 1048576);
|
|
||||||
|
|
||||||
UpdateProgress("Hashing image file byte {0} of {1}", position, _fi.Length);
|
|
||||||
|
|
||||||
_imgChkWorker.Update(data);
|
|
||||||
|
|
||||||
position += 1048576;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = new byte[_fi.Length - position];
|
|
||||||
_fs.Read(data, 0, (int)(_fi.Length - position));
|
|
||||||
|
|
||||||
UpdateProgress("Hashing image file byte {0} of {1}", position, _fi.Length);
|
UpdateProgress("Hashing image file byte {0} of {1}", position, _fi.Length);
|
||||||
|
|
||||||
_imgChkWorker.Update(data);
|
_imgChkWorker.Update(data);
|
||||||
|
|
||||||
// For fast debugging, skip checksum
|
position += 1048576;
|
||||||
//skipImageChecksum:
|
}
|
||||||
|
|
||||||
EndProgress();
|
data = new byte[_fi.Length - position];
|
||||||
_fs.Close();
|
_fs.Read(data, 0, (int)(_fi.Length - position));
|
||||||
|
|
||||||
List<ChecksumType> imgChecksums = _imgChkWorker.End();
|
UpdateProgress("Hashing image file byte {0} of {1}", position, _fi.Length);
|
||||||
|
|
||||||
_sidecar.OpticalDisc = null;
|
_imgChkWorker.Update(data);
|
||||||
_sidecar.BlockMedia = null;
|
|
||||||
_sidecar.AudioMedia = null;
|
|
||||||
_sidecar.LinearMedia = null;
|
|
||||||
|
|
||||||
if(_aborted)
|
// For fast debugging, skip checksum
|
||||||
return _sidecar;
|
//skipImageChecksum:
|
||||||
|
|
||||||
switch(_image.Info.XmlMediaType)
|
EndProgress();
|
||||||
{
|
_fs.Close();
|
||||||
case XmlMediaType.OpticalDisc:
|
|
||||||
if(_image is IOpticalMediaImage opticalImage)
|
|
||||||
OpticalDisc(opticalImage, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar,
|
|
||||||
_encoding);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AaruConsole.
|
|
||||||
ErrorWriteLine("The specified image says it contains an optical media but at the same time says it does not support them.");
|
|
||||||
|
|
||||||
AaruConsole.ErrorWriteLine("Please open an issue at Github.");
|
List<ChecksumType> imgChecksums = _imgChkWorker.End();
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
_sidecar.OpticalDisc = null;
|
||||||
case XmlMediaType.BlockMedia:
|
_sidecar.BlockMedia = null;
|
||||||
BlockMedia(_image, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar, _encoding);
|
_sidecar.AudioMedia = null;
|
||||||
|
_sidecar.LinearMedia = null;
|
||||||
break;
|
|
||||||
case XmlMediaType.LinearMedia:
|
|
||||||
LinearMedia(_image, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar, _encoding);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case XmlMediaType.AudioMedia:
|
|
||||||
AudioMedia(_image, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar, _encoding);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(_aborted)
|
||||||
return _sidecar;
|
return _sidecar;
|
||||||
|
|
||||||
|
switch(_image.Info.XmlMediaType)
|
||||||
|
{
|
||||||
|
case XmlMediaType.OpticalDisc:
|
||||||
|
if(_image is IOpticalMediaImage opticalImage)
|
||||||
|
OpticalDisc(opticalImage, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar,
|
||||||
|
_encoding);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AaruConsole.
|
||||||
|
ErrorWriteLine("The specified image says it contains an optical media but at the same time says it does not support them.");
|
||||||
|
|
||||||
|
AaruConsole.ErrorWriteLine("Please open an issue at Github.");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case XmlMediaType.BlockMedia:
|
||||||
|
if(_image is IMediaImage blockImage)
|
||||||
|
BlockMedia(blockImage, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar, _encoding);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AaruConsole.
|
||||||
|
ErrorWriteLine("The specified image says it contains a block addressable media but at the same time says it does not support them.");
|
||||||
|
|
||||||
|
AaruConsole.ErrorWriteLine("Please open an issue at Github.");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case XmlMediaType.LinearMedia:
|
||||||
|
if(_image is IByteAddressableImage byteAddressableImage)
|
||||||
|
LinearMedia(byteAddressableImage, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar,
|
||||||
|
_encoding);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AaruConsole.
|
||||||
|
ErrorWriteLine("The specified image says it contains a byte addressable media but at the same time says it does not support them.");
|
||||||
|
|
||||||
|
AaruConsole.ErrorWriteLine("Please open an issue at Github.");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case XmlMediaType.AudioMedia:
|
||||||
|
AudioMedia(_image, _filterId, _imagePath, _fi, _plugins, imgChecksums, ref _sidecar, _encoding);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Aborts sidecar running operation</summary>
|
return _sidecar;
|
||||||
public void Abort()
|
}
|
||||||
{
|
|
||||||
UpdateStatus("Aborting...");
|
/// <summary>Aborts sidecar running operation</summary>
|
||||||
_aborted = true;
|
public void Abort()
|
||||||
}
|
{
|
||||||
|
UpdateStatus("Aborting...");
|
||||||
|
_aborted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ namespace Aaru.Commands.Image
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IMediaImage imageFormat = null;
|
IBaseImage imageFormat = null;
|
||||||
|
|
||||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user