mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Move common offset fixing code to a separate class.
This commit is contained in:
112
Aaru.Core/Devices/Dumping/CompactDisc/Offset.cs
Normal file
112
Aaru.Core/Devices/Dumping/CompactDisc/Offset.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// 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-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using Aaru.Devices;
|
||||
|
||||
// ReSharper disable JoinDeclarationAndInitializer
|
||||
// ReSharper disable InlineOutVariableDeclaration
|
||||
// ReSharper disable TooWideLocalVariableScope
|
||||
|
||||
namespace Aaru.Core.Devices.Dumping
|
||||
{
|
||||
partial class Dump
|
||||
{
|
||||
static void FixOffsetData(int offsetBytes, uint sectorSize, int sectorsForOffset,
|
||||
MmcSubchannel supportedSubchannel, ref uint blocksToRead, uint subSize,
|
||||
ref byte[] cmdBuf, uint blockSize, bool failedCrossingLeadOut)
|
||||
{
|
||||
if(cmdBuf.Length == 0)
|
||||
return;
|
||||
|
||||
int offsetFix = offsetBytes < 0 ? (int)((sectorSize * sectorsForOffset) + offsetBytes) : offsetBytes;
|
||||
|
||||
byte[] tmpBuf;
|
||||
|
||||
if(supportedSubchannel != MmcSubchannel.None)
|
||||
{
|
||||
// De-interleave subchannel
|
||||
byte[] data = new byte[sectorSize * blocksToRead];
|
||||
byte[] sub = new byte[subSize * blocksToRead];
|
||||
|
||||
for(int b = 0; b < blocksToRead; b++)
|
||||
{
|
||||
Array.Copy(cmdBuf, (int)(0 + (b * blockSize)), data, sectorSize * b, sectorSize);
|
||||
Array.Copy(cmdBuf, (int)(sectorSize + (b * blockSize)), sub, subSize * b, subSize);
|
||||
}
|
||||
|
||||
if(failedCrossingLeadOut)
|
||||
{
|
||||
blocksToRead += (uint)sectorsForOffset;
|
||||
|
||||
tmpBuf = new byte[sectorSize * blocksToRead];
|
||||
Array.Copy(data, 0, tmpBuf, 0, data.Length);
|
||||
data = tmpBuf;
|
||||
tmpBuf = new byte[subSize * blocksToRead];
|
||||
Array.Copy(sub, 0, tmpBuf, 0, sub.Length);
|
||||
sub = tmpBuf;
|
||||
}
|
||||
|
||||
tmpBuf = new byte[sectorSize * (blocksToRead - sectorsForOffset)];
|
||||
Array.Copy(data, offsetFix, tmpBuf, 0, tmpBuf.Length);
|
||||
data = tmpBuf;
|
||||
|
||||
blocksToRead -= (uint)sectorsForOffset;
|
||||
|
||||
// Re-interleave subchannel
|
||||
cmdBuf = new byte[blockSize * blocksToRead];
|
||||
|
||||
for(int b = 0; b < blocksToRead; b++)
|
||||
{
|
||||
Array.Copy(data, sectorSize * b, cmdBuf, (int)(0 + (b * blockSize)), sectorSize);
|
||||
Array.Copy(sub, subSize * b, cmdBuf, (int)(sectorSize + (b * blockSize)), subSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(failedCrossingLeadOut)
|
||||
{
|
||||
blocksToRead += (uint)sectorsForOffset;
|
||||
|
||||
tmpBuf = new byte[blockSize * blocksToRead];
|
||||
Array.Copy(cmdBuf, 0, tmpBuf, 0, cmdBuf.Length);
|
||||
cmdBuf = tmpBuf;
|
||||
}
|
||||
|
||||
tmpBuf = new byte[blockSize * (blocksToRead - sectorsForOffset)];
|
||||
Array.Copy(cmdBuf, offsetFix, tmpBuf, 0, tmpBuf.Length);
|
||||
cmdBuf = tmpBuf;
|
||||
blocksToRead -= (uint)sectorsForOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user