mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Split CD tag reading from dumping.
This commit is contained in:
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -237,6 +237,7 @@
|
||||
<e p="Dump.cs" t="Include" />
|
||||
<e p="LeadOuts.cs" t="Include" />
|
||||
<e p="Subchannel.cs" t="Include" />
|
||||
<e p="Tags.cs" t="Include" />
|
||||
<e p="Tracks.cs" t="Include" />
|
||||
</e>
|
||||
<e p="Dump.cs" t="Include" />
|
||||
|
||||
@@ -46,11 +46,9 @@ using DiscImageChef.Core.Media.Detection;
|
||||
using DiscImageChef.Database.Models;
|
||||
using DiscImageChef.Decoders.CD;
|
||||
using DiscImageChef.Decoders.SCSI;
|
||||
using DiscImageChef.Decoders.SCSI.MMC;
|
||||
using DiscImageChef.Devices;
|
||||
using Schemas;
|
||||
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
|
||||
using Session = DiscImageChef.Decoders.CD.Session;
|
||||
using TrackType = DiscImageChef.CommonTypes.Enums.TrackType;
|
||||
|
||||
// ReSharper disable JoinDeclarationAndInitializer
|
||||
@@ -74,7 +72,7 @@ namespace DiscImageChef.Core.Devices.Dumping
|
||||
uint blockSize; // Size of the read sector in bytes
|
||||
uint blocksToRead = 0; // How many sectors to read at once
|
||||
CdOffset cdOffset; // Read offset from database
|
||||
byte[] cmdBuf; // Data buffer
|
||||
byte[] cmdBuf = null; // Data buffer
|
||||
double cmdDuration = 0; // Command execution time
|
||||
DumpHardwareType currentTry = null; // Current dump hardware try
|
||||
double currentSpeed = 0; // Current read speed
|
||||
@@ -100,9 +98,9 @@ namespace DiscImageChef.Core.Devices.Dumping
|
||||
const uint sectorSize = 2352; // Full sector size
|
||||
int sectorsForOffset = 0; // Sectors needed to fix offset
|
||||
ulong sectorSpeedStart = 0; // Used to calculate correct speed
|
||||
bool sense; // Sense indicator
|
||||
byte[] senseBuf; // Sense buffer
|
||||
int sessions = 1; // Number of sessions in disc
|
||||
bool sense=true; // Sense indicator
|
||||
byte[] senseBuf = null; // Sense buffer
|
||||
int sessions; // Number of sessions in disc
|
||||
DateTime start; // Start of operation
|
||||
uint subSize; // Subchannel size in bytes
|
||||
TrackSubchannelType subType; // Track subchannel type
|
||||
@@ -119,7 +117,7 @@ namespace DiscImageChef.Core.Devices.Dumping
|
||||
|
||||
Dictionary<MediaTagType, byte[]> mediaTags = new Dictionary<MediaTagType, byte[]>(); // Media tags
|
||||
|
||||
int firstTrackLastSession = 0; // Number of first track in last session
|
||||
int firstTrackLastSession; // Number of first track in last session
|
||||
|
||||
MmcSubchannel supportedSubchannel; // Drive's maximum supported subchannel
|
||||
|
||||
@@ -382,89 +380,8 @@ namespace DiscImageChef.Core.Devices.Dumping
|
||||
return;
|
||||
}
|
||||
|
||||
// ATIP exists on blank CDs
|
||||
_dumpLog.WriteLine("Reading ATIP");
|
||||
UpdateStatus?.Invoke("Reading ATIP");
|
||||
sense = _dev.ReadAtip(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
ATIP.CDATIP? atip = ATIP.Decode(cmdBuf);
|
||||
|
||||
if(atip.HasValue)
|
||||
{
|
||||
// Only CD-R and CD-RW have ATIP
|
||||
dskType = atip.Value.DiscType ? MediaType.CDRW : MediaType.CDR;
|
||||
|
||||
tmpBuf = new byte[cmdBuf.Length - 4];
|
||||
Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4);
|
||||
mediaTags.Add(MediaTagType.CD_ATIP, tmpBuf);
|
||||
}
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading Disc Information");
|
||||
UpdateStatus?.Invoke("Reading Disc Information");
|
||||
|
||||
sense = _dev.ReadDiscInformation(out cmdBuf, out senseBuf, MmcDiscInformationDataTypes.DiscInformation,
|
||||
_dev.Timeout, out _);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
DiscInformation.StandardDiscInformation? discInfo = DiscInformation.Decode000b(cmdBuf);
|
||||
|
||||
if(discInfo.HasValue &&
|
||||
dskType == MediaType.CD)
|
||||
switch(discInfo.Value.DiscType)
|
||||
{
|
||||
case 0x10:
|
||||
dskType = MediaType.CDI;
|
||||
|
||||
break;
|
||||
case 0x20:
|
||||
dskType = MediaType.CDROMXA;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading PMA");
|
||||
UpdateStatus?.Invoke("Reading PMA");
|
||||
sense = _dev.ReadPma(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
||||
|
||||
if(!sense &&
|
||||
PMA.Decode(cmdBuf).HasValue)
|
||||
{
|
||||
tmpBuf = new byte[cmdBuf.Length - 4];
|
||||
Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4);
|
||||
mediaTags.Add(MediaTagType.CD_PMA, tmpBuf);
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading Session Information");
|
||||
UpdateStatus?.Invoke("Reading Session Information");
|
||||
sense = _dev.ReadSessionInfo(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
Session.CDSessionInfo? session = Session.Decode(cmdBuf);
|
||||
|
||||
if(session.HasValue)
|
||||
{
|
||||
sessions = session.Value.LastCompleteSession;
|
||||
firstTrackLastSession = session.Value.TrackDescriptors[0].TrackNumber;
|
||||
}
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading CD-Text from Lead-In");
|
||||
UpdateStatus?.Invoke("Reading CD-Text from Lead-In");
|
||||
sense = _dev.ReadCdText(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
||||
|
||||
if(!sense &&
|
||||
CDTextOnLeadIn.Decode(cmdBuf).HasValue)
|
||||
{
|
||||
tmpBuf = new byte[cmdBuf.Length - 4];
|
||||
Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4);
|
||||
mediaTags.Add(MediaTagType.CD_TEXT, tmpBuf);
|
||||
}
|
||||
// Read media tags
|
||||
ReadCdTags(ref dskType, mediaTags, out sessions, out firstTrackLastSession);
|
||||
|
||||
// Check if output format supports all disc tags we have retrieved so far
|
||||
foreach(MediaTagType tag in mediaTags.Keys)
|
||||
|
||||
147
DiscImageChef.Core/Devices/Dumping/CompactDisc/Tags.cs
Normal file
147
DiscImageChef.Core/Devices/Dumping/CompactDisc/Tags.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : CompactDisc.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Core algorithms.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Dumps CDs and DDCDs.
|
||||
//
|
||||
// --[ 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.Decoders.CD;
|
||||
using DiscImageChef.Decoders.SCSI.MMC;
|
||||
using DiscImageChef.Devices;
|
||||
|
||||
// ReSharper disable JoinDeclarationAndInitializer
|
||||
// ReSharper disable InlineOutVariableDeclaration
|
||||
// ReSharper disable TooWideLocalVariableScope
|
||||
|
||||
namespace DiscImageChef.Core.Devices.Dumping
|
||||
{
|
||||
partial class Dump
|
||||
{
|
||||
/// <summary>Reads media tags from Compact Disc media</summary>
|
||||
/// <param name="mediaType">Media type</param>
|
||||
/// <param name="mediaTags">Media tags dictionary</param>
|
||||
/// <param name="sessions">Sessions</param>
|
||||
/// <param name="firstTrackLastSession">First track in last session</param>
|
||||
void ReadCdTags(ref MediaType mediaType, Dictionary<MediaTagType, byte[]> mediaTags, out int sessions,
|
||||
out int firstTrackLastSession)
|
||||
{
|
||||
byte[] cmdBuf; // Data buffer
|
||||
bool sense; // Sense indicator
|
||||
byte[] tmpBuf; // Temporary buffer
|
||||
sessions = 1;
|
||||
firstTrackLastSession = 1;
|
||||
|
||||
// ATIP exists on blank CDs
|
||||
_dumpLog.WriteLine("Reading ATIP");
|
||||
UpdateStatus?.Invoke("Reading ATIP");
|
||||
sense = _dev.ReadAtip(out cmdBuf, out _, _dev.Timeout, out _);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
ATIP.CDATIP? atip = ATIP.Decode(cmdBuf);
|
||||
|
||||
if(atip.HasValue)
|
||||
{
|
||||
// Only CD-R and CD-RW have ATIP
|
||||
mediaType = atip.Value.DiscType ? MediaType.CDRW : MediaType.CDR;
|
||||
|
||||
tmpBuf = new byte[cmdBuf.Length - 4];
|
||||
Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4);
|
||||
mediaTags.Add(MediaTagType.CD_ATIP, tmpBuf);
|
||||
}
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading Disc Information");
|
||||
UpdateStatus?.Invoke("Reading Disc Information");
|
||||
|
||||
sense = _dev.ReadDiscInformation(out cmdBuf, out _, MmcDiscInformationDataTypes.DiscInformation,
|
||||
_dev.Timeout, out _);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
DiscInformation.StandardDiscInformation? discInfo = DiscInformation.Decode000b(cmdBuf);
|
||||
|
||||
if(discInfo.HasValue &&
|
||||
mediaType == MediaType.CD)
|
||||
switch(discInfo.Value.DiscType)
|
||||
{
|
||||
case 0x10:
|
||||
mediaType = MediaType.CDI;
|
||||
|
||||
break;
|
||||
case 0x20:
|
||||
mediaType = MediaType.CDROMXA;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading PMA");
|
||||
UpdateStatus?.Invoke("Reading PMA");
|
||||
sense = _dev.ReadPma(out cmdBuf, out _, _dev.Timeout, out _);
|
||||
|
||||
if(!sense &&
|
||||
PMA.Decode(cmdBuf).HasValue)
|
||||
{
|
||||
tmpBuf = new byte[cmdBuf.Length - 4];
|
||||
Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4);
|
||||
mediaTags.Add(MediaTagType.CD_PMA, tmpBuf);
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading Session Information");
|
||||
UpdateStatus?.Invoke("Reading Session Information");
|
||||
sense = _dev.ReadSessionInfo(out cmdBuf, out _, _dev.Timeout, out _);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
Session.CDSessionInfo? session = Session.Decode(cmdBuf);
|
||||
|
||||
if(session.HasValue)
|
||||
{
|
||||
sessions = session.Value.LastCompleteSession;
|
||||
firstTrackLastSession = session.Value.TrackDescriptors[0].TrackNumber;
|
||||
}
|
||||
}
|
||||
|
||||
_dumpLog.WriteLine("Reading CD-Text from Lead-In");
|
||||
UpdateStatus?.Invoke("Reading CD-Text from Lead-In");
|
||||
sense = _dev.ReadCdText(out cmdBuf, out _, _dev.Timeout, out _);
|
||||
|
||||
if(sense || !CDTextOnLeadIn.Decode(cmdBuf).HasValue)
|
||||
return;
|
||||
|
||||
tmpBuf = new byte[cmdBuf.Length - 4];
|
||||
Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4);
|
||||
mediaTags.Add(MediaTagType.CD_TEXT, tmpBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@
|
||||
<Compile Include="Devices\Dumping\CompactDisc\Dump.cs" />
|
||||
<Compile Include="Devices\Dumping\CompactDisc\LeadOuts.cs" />
|
||||
<Compile Include="Devices\Dumping\CompactDisc\Subchannel.cs" />
|
||||
<Compile Include="Devices\Dumping\CompactDisc\Tags.cs" />
|
||||
<Compile Include="Devices\Dumping\CompactDisc\Tracks.cs" />
|
||||
<Compile Include="Devices\Dumping\Dump.cs" />
|
||||
<Compile Include="Devices\Dumping\Metadata.cs" />
|
||||
|
||||
Reference in New Issue
Block a user