mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Move CD user data trimming to a separate file.
This commit is contained in:
@@ -976,158 +976,9 @@ namespace DiscImageChef.Core.Devices.Dumping
|
||||
_dumpLog.WriteLine("Average write speed {0:F3} KiB/sec.",
|
||||
((double)blockSize * (double)(blocks + 1)) / 1024 / imageWriteDuration);
|
||||
|
||||
#region Compact Disc Error trimming
|
||||
if(_resume.BadBlocks.Count > 0 &&
|
||||
!_aborted &&
|
||||
!_notrim &&
|
||||
newTrim)
|
||||
{
|
||||
start = DateTime.UtcNow;
|
||||
UpdateStatus?.Invoke("Trimming bad sectors");
|
||||
_dumpLog.WriteLine("Trimming bad sectors");
|
||||
|
||||
ulong[] tmpArray = _resume.BadBlocks.ToArray();
|
||||
InitProgress?.Invoke();
|
||||
|
||||
foreach(ulong badSector in tmpArray)
|
||||
{
|
||||
if(_aborted)
|
||||
{
|
||||
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
||||
UpdateStatus?.Invoke("Aborted!");
|
||||
_dumpLog.WriteLine("Aborted!");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
PulseProgress?.Invoke($"Trimming sector {badSector}");
|
||||
|
||||
byte sectorsToTrim = 1;
|
||||
uint badSectorToRead = (uint)badSector;
|
||||
|
||||
if(_fixOffset &&
|
||||
audioExtents.Contains(badSector) &&
|
||||
offsetBytes != 0)
|
||||
{
|
||||
if(offsetBytes > 0)
|
||||
{
|
||||
badSectorToRead -= (uint)sectorsForOffset;
|
||||
}
|
||||
|
||||
sectorsToTrim = (byte)(sectorsForOffset + 1);
|
||||
}
|
||||
|
||||
if(readcd)
|
||||
sense = _dev.ReadCd(out cmdBuf, out senseBuf, badSectorToRead, blockSize, sectorsToTrim,
|
||||
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders,
|
||||
true, true, MmcErrorField.None, supportedSubchannel, _dev.Timeout,
|
||||
out cmdDuration);
|
||||
else if(read16)
|
||||
sense = _dev.Read16(out cmdBuf, out senseBuf, 0, false, true, false, badSectorToRead, blockSize,
|
||||
0, sectorsToTrim, false, _dev.Timeout, out cmdDuration);
|
||||
else if(read12)
|
||||
sense = _dev.Read12(out cmdBuf, out senseBuf, 0, false, true, false, false, badSectorToRead,
|
||||
blockSize, 0, sectorsToTrim, false, _dev.Timeout, out cmdDuration);
|
||||
else if(read10)
|
||||
sense = _dev.Read10(out cmdBuf, out senseBuf, 0, false, true, false, false, badSectorToRead,
|
||||
blockSize, 0, sectorsToTrim, _dev.Timeout, out cmdDuration);
|
||||
else if(read6)
|
||||
sense = _dev.Read6(out cmdBuf, out senseBuf, badSectorToRead, blockSize, sectorsToTrim,
|
||||
_dev.Timeout, out cmdDuration);
|
||||
|
||||
totalDuration += cmdDuration;
|
||||
|
||||
if(sense || _dev.Error)
|
||||
continue;
|
||||
|
||||
if(!sense &&
|
||||
!_dev.Error)
|
||||
{
|
||||
_resume.BadBlocks.Remove(badSector);
|
||||
extents.Add(badSector);
|
||||
}
|
||||
|
||||
// Because one block has been partially used to fix the offset
|
||||
if(_fixOffset &&
|
||||
audioExtents.Contains(badSector) &&
|
||||
offsetBytes != 0)
|
||||
{
|
||||
int offsetFix = offsetBytes < 0 ? offsetFix = (int)(sectorSize - (offsetBytes * -1))
|
||||
: offsetFix = offsetBytes;
|
||||
|
||||
if(supportedSubchannel != MmcSubchannel.None)
|
||||
{
|
||||
// Deinterleave subchannel
|
||||
byte[] data = new byte[sectorSize * sectorsToTrim];
|
||||
byte[] sub = new byte[subSize * sectorsToTrim];
|
||||
|
||||
for(int b = 0; b < sectorsToTrim; b++)
|
||||
{
|
||||
Array.Copy(cmdBuf, (int)(0 + (b * blockSize)), data, sectorSize * b, sectorSize);
|
||||
|
||||
Array.Copy(cmdBuf, (int)(sectorSize + (b * blockSize)), sub, subSize * b, subSize);
|
||||
}
|
||||
|
||||
tmpBuf = new byte[sectorSize * (sectorsToTrim - sectorsForOffset)];
|
||||
Array.Copy(data, offsetFix, tmpBuf, 0, tmpBuf.Length);
|
||||
data = tmpBuf;
|
||||
|
||||
// Reinterleave subchannel
|
||||
cmdBuf = new byte[blockSize * sectorsToTrim];
|
||||
|
||||
for(int b = 0; b < sectorsToTrim; b++)
|
||||
{
|
||||
Array.Copy(data, sectorSize * b, cmdBuf, (int)(0 + (b * blockSize)), sectorSize);
|
||||
|
||||
Array.Copy(sub, subSize * b, cmdBuf, (int)(sectorSize + (b * blockSize)), subSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpBuf = new byte[blockSize * (sectorsToTrim - sectorsForOffset)];
|
||||
Array.Copy(cmdBuf, offsetFix, tmpBuf, 0, tmpBuf.Length);
|
||||
cmdBuf = tmpBuf;
|
||||
}
|
||||
}
|
||||
|
||||
if(supportedSubchannel != MmcSubchannel.None)
|
||||
{
|
||||
byte[] data = new byte[sectorSize];
|
||||
byte[] sub = new byte[subSize];
|
||||
Array.Copy(cmdBuf, 0, data, 0, sectorSize);
|
||||
Array.Copy(cmdBuf, sectorSize, sub, 0, subSize);
|
||||
_outputPlugin.WriteSectorLong(data, badSector);
|
||||
_outputPlugin.WriteSectorTag(sub, badSector, SectorTagType.CdSectorSubchannel);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(supportsLongSectors)
|
||||
{
|
||||
_outputPlugin.WriteSectorLong(cmdBuf, badSector);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cmdBuf.Length % sectorSize == 0)
|
||||
{
|
||||
byte[] data = new byte[2048];
|
||||
Array.Copy(cmdBuf, 16, data, 0, 2048);
|
||||
|
||||
_outputPlugin.WriteSector(data, badSector);
|
||||
}
|
||||
else
|
||||
{
|
||||
_outputPlugin.WriteSectorLong(cmdBuf, badSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EndProgress?.Invoke();
|
||||
end = DateTime.UtcNow;
|
||||
UpdateStatus?.Invoke($"Trimming finished in {(end - start).TotalSeconds} seconds.");
|
||||
_dumpLog.WriteLine("Trimming finished in {0} seconds.", (end - start).TotalSeconds);
|
||||
}
|
||||
#endregion Compact Disc Error trimming
|
||||
TrimCdUserData(audioExtents, blockSize, currentTry, extents, newTrim, offsetBytes, read6, read10, read12,
|
||||
read16, readcd, sectorsForOffset, subSize, supportedSubchannel, supportsLongSectors,
|
||||
ref totalDuration);
|
||||
|
||||
#region Compact Disc Error handling
|
||||
if(_resume.BadBlocks.Count > 0 &&
|
||||
|
||||
Reference in New Issue
Block a user