2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2015-12-25 20:47:40 +00:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Filename : Read.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-12-25 20:47:40 +00:00
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Component : Disk image plugins.
|
2015-12-25 20:47:40 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads Dreamcast GDI disc images.
|
2015-12-25 20:47:40 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-12-25 20:47:40 +00:00
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// This library 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
|
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-12-25 20:47:40 +00:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-12-25 20:47:40 +00:00
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2015-12-25 20:47:40 +00:00
|
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
|
2015-12-25 20:47:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Exceptions;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
|
using Aaru.Console;
|
2020-06-21 22:30:07 +01:00
|
|
|
|
using Aaru.Decoders.CD;
|
|
|
|
|
|
using Session = Aaru.CommonTypes.Structs.Session;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.DiscImages
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed partial class Gdi
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-16 19:10:39 +01:00
|
|
|
|
public ErrorNumber Open(IFilter imageFilter)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(imageFilter == null)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.NoSuchFile;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
|
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_gdiStream = new StreamReader(imageFilter.GetDataForkStream());
|
2018-01-01 21:32:12 +00:00
|
|
|
|
int lineNumber = 0;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
bool highDensity = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize all RegExs
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var regexTrack = new Regex(REGEX_TRACK);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
// Initialize all RegEx matches
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize disc
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage = new GdiDisc
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Sessions = new List<Session>(),
|
|
|
|
|
|
Tracks = new List<GdiTrack>()
|
2020-02-29 18:03:35 +00:00
|
|
|
|
};
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong currentStart = 0;
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_offsetMap = new Dictionary<uint, ulong>();
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_densitySeparationSectors = 0;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
while(_gdiStream.Peek() >= 0)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber++;
|
2020-07-20 21:11:32 +01:00
|
|
|
|
string line = _gdiStream.ReadLine();
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(lineNumber == 1)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(!int.TryParse(line, out _))
|
2015-12-25 20:47:40 +00:00
|
|
|
|
throw new ImageNotSupportedException("Not a correct Dreamcast GDI image");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Match trackMatch = regexTrack.Match(line ?? throw new InvalidOperationException());
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!trackMatch.Success)
|
2017-12-22 06:55:04 +00:00
|
|
|
|
throw new ImageNotSupportedException($"Unknown line \"{line}\" at line {lineNumber}");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
"Found track {0} starts at {1} flags {2} type {3} file {4} offset {5} at line {6}",
|
|
|
|
|
|
trackMatch.Groups["track"].Value, trackMatch.Groups["start"].Value,
|
|
|
|
|
|
trackMatch.Groups["flags"].Value, trackMatch.Groups["type"].Value,
|
|
|
|
|
|
trackMatch.Groups["filename"].Value,
|
|
|
|
|
|
trackMatch.Groups["offset"].Value, lineNumber);
|
|
|
|
|
|
|
|
|
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
|
|
|
|
|
|
|
var currentTrack = new GdiTrack
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Bps = ushort.Parse(trackMatch.Groups["type"].Value),
|
|
|
|
|
|
Flags = byte.Parse(trackMatch.Groups["flags"].Value),
|
|
|
|
|
|
Offset = long.Parse(trackMatch.Groups["offset"].Value),
|
|
|
|
|
|
Sequence = uint.Parse(trackMatch.Groups["track"].Value),
|
2017-12-22 06:55:04 +00:00
|
|
|
|
StartSector = ulong.Parse(trackMatch.Groups["start"].Value),
|
2021-09-15 11:25:26 +01:00
|
|
|
|
TrackFilter = filtersList.GetFilter(Path.Combine(imageFilter.ParentFolder,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
trackMatch.Groups["filename"].Value.
|
2020-11-11 04:19:18 +00:00
|
|
|
|
Replace("\\\"", "\"").Trim('"')))
|
2017-12-22 06:55:04 +00:00
|
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-09-15 11:25:26 +01:00
|
|
|
|
currentTrack.TrackFile = currentTrack.TrackFilter.Filename;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(currentTrack.StartSector - currentStart > 0)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(currentTrack.StartSector == 45000)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
highDensity = true;
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_offsetMap.Add(0, currentStart);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_densitySeparationSectors = currentTrack.StartSector - currentStart;
|
|
|
|
|
|
currentStart = currentTrack.StartSector;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-01-01 21:32:12 +00:00
|
|
|
|
currentTrack.Pregap = currentTrack.StartSector - currentStart;
|
2017-12-20 17:26:28 +00:00
|
|
|
|
currentTrack.StartSector -= currentTrack.StartSector - currentStart;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-15 11:25:26 +01:00
|
|
|
|
if((currentTrack.TrackFilter.DataForkLength - currentTrack.Offset) % currentTrack.Bps != 0)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw new ImageNotSupportedException("Track size not a multiple of sector size");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-09-15 11:25:26 +01:00
|
|
|
|
currentTrack.Sectors = (ulong)((currentTrack.TrackFilter.DataForkLength - currentTrack.Offset) /
|
|
|
|
|
|
currentTrack.Bps);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
currentTrack.Sectors += currentTrack.Pregap;
|
|
|
|
|
|
currentStart += currentTrack.Sectors;
|
|
|
|
|
|
currentTrack.HighDensity = highDensity;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
currentTrack.TrackType =
|
2018-01-01 21:32:12 +00:00
|
|
|
|
(currentTrack.Flags & 0x4) == 0x4 ? TrackType.CdMode1 : TrackType.Audio;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Tracks.Add(currentTrack);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Session[] sessions = new Session[2];
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
for(int s = 0; s < sessions.Length; s++)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(s == 0)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2021-09-14 21:18:28 +01:00
|
|
|
|
sessions[s].Sequence = 1;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack trk in _discImage.Tracks.Where(trk => !trk.HighDensity))
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(sessions[s].StartTrack == 0)
|
|
|
|
|
|
sessions[s].StartTrack = trk.Sequence;
|
|
|
|
|
|
else if(sessions[s].StartTrack > trk.Sequence)
|
|
|
|
|
|
sessions[s].StartTrack = trk.Sequence;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(sessions[s].EndTrack < trk.Sequence)
|
|
|
|
|
|
sessions[s].EndTrack = trk.Sequence;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(sessions[s].StartSector > trk.StartSector)
|
|
|
|
|
|
sessions[s].StartSector = trk.StartSector;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 14:27:19 +01:00
|
|
|
|
if(sessions[s].EndSector < trk.Sectors + trk.StartSector - 1)
|
|
|
|
|
|
sessions[s].EndSector = trk.Sectors + trk.StartSector - 1;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-09-14 21:18:28 +01:00
|
|
|
|
sessions[s].Sequence = 2;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack trk in _discImage.Tracks.Where(trk => trk.HighDensity))
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(sessions[s].StartTrack == 0)
|
|
|
|
|
|
sessions[s].StartTrack = trk.Sequence;
|
|
|
|
|
|
else if(sessions[s].StartTrack > trk.Sequence)
|
|
|
|
|
|
sessions[s].StartTrack = trk.Sequence;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(sessions[s].EndTrack < trk.Sequence)
|
|
|
|
|
|
sessions[s].EndTrack = trk.Sequence;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(sessions[s].StartSector > trk.StartSector)
|
|
|
|
|
|
sessions[s].StartSector = trk.StartSector;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 14:27:19 +01:00
|
|
|
|
if(sessions[s].EndSector < trk.Sectors + trk.StartSector - 1)
|
|
|
|
|
|
sessions[s].EndSector = trk.Sectors + trk.StartSector - 1;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Sessions.Add(sessions[0]);
|
|
|
|
|
|
_discImage.Sessions.Add(sessions[1]);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Disktype = MediaType.GDROM;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
// DEBUG information
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "Disc image parsing results");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "Session information:");
|
2020-11-11 04:19:18 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\tDisc contains {0} sessions", _discImage.Sessions.Count);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
for(int i = 0; i < _discImage.Sessions.Count; i++)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\tSession {0} information:", i + 1);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tStarting track: {0}",
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Sessions[i].StartTrack);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tStarting sector: {0}",
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Sessions[i].StartSector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tEnding track: {0}", _discImage.Sessions[i].EndTrack);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
|
|
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tEnding sector: {0}",
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Sessions[i].EndSector);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "Track information:");
|
2020-11-11 04:19:18 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\tDisc contains {0} tracks", _discImage.Tracks.Count);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
for(int i = 0; i < _discImage.Tracks.Count; i++)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-11-11 04:19:18 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\tTrack {0} information:", _discImage.Tracks[i].Sequence);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\t{0} bytes per sector", _discImage.Tracks[i].Bps);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tPregap: {0} sectors", _discImage.Tracks[i].Pregap);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
if((_discImage.Tracks[i].Flags & 0x8) == 0x8)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tTrack is flagged as quadraphonic");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
if((_discImage.Tracks[i].Flags & 0x4) == 0x4)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tTrack is data");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
if((_discImage.Tracks[i].Flags & 0x2) == 0x2)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tTrack allows digital copy");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
if((_discImage.Tracks[i].Flags & 0x1) == 0x1)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "\t\tTrack has pre-emphasis applied");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
"\t\tTrack resides in file {0}, type defined as {1}, starting at byte {2}",
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_discImage.Tracks[i].TrackFilter, _discImage.Tracks[i].TrackType,
|
|
|
|
|
|
_discImage.Tracks[i].Offset);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("GDI plugin", "Building offset map");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Partitions = new List<Partition>();
|
2017-12-20 17:15:26 +00:00
|
|
|
|
ulong byteOffset = 0;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
for(int i = 0; i < _discImage.Tracks.Count; i++)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-11-11 04:19:18 +00:00
|
|
|
|
if(_discImage.Tracks[i].Sequence == 1 &&
|
2020-07-20 21:11:32 +01:00
|
|
|
|
i != 0)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
throw new ImageNotSupportedException("Unordered tracks");
|
|
|
|
|
|
|
|
|
|
|
|
// Index 01
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var partition = new Partition
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
2020-11-11 04:19:18 +00:00
|
|
|
|
Description = $"Track {_discImage.Tracks[i].Sequence}.",
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Name = null,
|
2020-11-11 04:19:18 +00:00
|
|
|
|
Start = _discImage.Tracks[i].StartSector,
|
|
|
|
|
|
Size = _discImage.Tracks[i].Sectors * _discImage.Tracks[i].Bps,
|
|
|
|
|
|
Length = _discImage.Tracks[i].Sectors,
|
|
|
|
|
|
Sequence = _discImage.Tracks[i].Sequence,
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Offset = byteOffset,
|
2020-11-11 04:19:18 +00:00
|
|
|
|
Type = _discImage.Tracks[i].TrackType.ToString()
|
2017-12-22 06:55:04 +00:00
|
|
|
|
};
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
|
|
|
|
|
byteOffset += partition.Size;
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_offsetMap.Add(_discImage.Tracks[i].Sequence, partition.Start);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Partitions.Add(partition);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack track in _discImage.Tracks)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ImageSize += track.Bps * track.Sectors;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack track in _discImage.Tracks)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Sectors += track.Sectors;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Sectors += _densitySeparationSectors;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.SectorSize = 2352; // All others
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack unused in _discImage.Tracks.Where(track => (track.Flags & 0x4) == 0x4 &&
|
2020-07-20 21:11:32 +01:00
|
|
|
|
track.Bps == 2352))
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-21 07:08:26 +00:00
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-09-15 11:25:26 +01:00
|
|
|
|
_imageInfo.CreationTime = imageFilter.CreationTime;
|
|
|
|
|
|
_imageInfo.LastModificationTime = imageFilter.LastWriteTime;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_imageInfo.MediaType = _discImage.Disktype;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.VerboseWriteLine("GDI image describes a disc of type {0}", _imageInfo.MediaType);
|
2016-08-21 17:35:35 +01:00
|
|
|
|
|
2020-06-21 22:30:07 +01:00
|
|
|
|
_sectorBuilder = new SectorBuilder();
|
|
|
|
|
|
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.NoError;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
catch(Exception ex)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2021-09-15 11:25:26 +01:00
|
|
|
|
AaruConsole.ErrorWriteLine("Exception trying to identify image file {0}", imageFilter.BasePath);
|
2021-09-16 19:10:39 +01:00
|
|
|
|
AaruConsole.ErrorWriteLine("Exception: {0}", ex);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.UnexpectedException;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
|
|
|
|
|
|
ReadSectors(sectorAddress, 1, out buffer);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track) => ReadSectors(sectorAddress, 1, track);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag) =>
|
|
|
|
|
|
ReadSectorsTag(sectorAddress, 1, track, tag);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
|
|
|
|
|
from gdiTrack in _discImage.Tracks
|
2018-01-01 21:32:12 +00:00
|
|
|
|
where gdiTrack.Sequence == kvp.Key
|
2020-02-29 18:03:35 +00:00
|
|
|
|
where sectorAddress - kvp.Value < gdiTrack.Sectors select kvp)
|
2021-09-19 21:16:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
buffer = ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
|
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_offsetMap.TryGetValue(0, out ulong transitionStart);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
if(sectorAddress < transitionStart ||
|
|
|
|
|
|
sectorAddress >= _densitySeparationSectors + transitionStart)
|
|
|
|
|
|
return ErrorNumber.SectorNotFound;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
buffer = ReadSectors(sectorAddress - transitionStart, length, 0);
|
|
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
|
|
|
|
|
from gdiTrack in _discImage.Tracks
|
2018-01-01 21:32:12 +00:00
|
|
|
|
where gdiTrack.Sequence == kvp.Key
|
2020-02-29 18:03:35 +00:00
|
|
|
|
where sectorAddress - kvp.Value < gdiTrack.Sectors select kvp)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_offsetMap.TryGetValue(0, out ulong transitionStart);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
if(sectorAddress >= transitionStart &&
|
2020-07-20 21:11:32 +01:00
|
|
|
|
sectorAddress < _densitySeparationSectors + transitionStart)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
return ReadSectorsTag(sectorAddress - transitionStart, length, 0, tag);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(track == 0)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _densitySeparationSectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
|
"Requested more sectors than present in track, won't cross tracks");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
return new byte[length * 2352];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var aaruTrack = new GdiTrack
|
|
|
|
|
|
{
|
|
|
|
|
|
Sequence = 0
|
|
|
|
|
|
};
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack gdiTrack in _discImage.Tracks.Where(gdiTrack => gdiTrack.Sequence == track))
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
aaruTrack = gdiTrack;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.Sequence == 0)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(sectorAddress + length > aaruTrack.Sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
|
"Requested more sectors than present in track, won't cross tracks");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
switch(aaruTrack.TrackType)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
case TrackType.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.Bps == 2352)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 16;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 288;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2018-01-01 21:32:12 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
ulong remainingSectors = length;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(aaruTrack.Pregap > 0 &&
|
|
|
|
|
|
sectorAddress < aaruTrack.Pregap)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-03-09 23:47:03 +00:00
|
|
|
|
ulong remainingPregap = aaruTrack.Pregap - sectorAddress;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:47:03 +00:00
|
|
|
|
remainingSectors -= length > remainingPregap ? remainingPregap : length;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(remainingSectors == 0)
|
|
|
|
|
|
return buffer;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
2020-07-20 21:11:32 +01:00
|
|
|
|
var br = new BinaryReader(_imageStream);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:44:06 +00:00
|
|
|
|
long pos = aaruTrack.Offset + (long)((sectorAddress * (sectorOffset + sectorSize + sectorSkip)) -
|
|
|
|
|
|
(aaruTrack.Pregap * aaruTrack.Bps));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:44:06 +00:00
|
|
|
|
if(pos < 0)
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
br.BaseStream.Seek(pos, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0 &&
|
|
|
|
|
|
remainingSectors == length)
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
buffer = br.ReadBytes((int)(sectorSize * remainingSectors));
|
2020-03-09 23:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] tmp = br.ReadBytes((int)(sectorSize * remainingSectors));
|
|
|
|
|
|
Array.Copy(tmp, 0, buffer, (int)((length - remainingSectors) * sectorSize), tmp.Length);
|
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
else
|
2020-03-09 23:44:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
int bufferPos = (int)((length - remainingSectors) * sectorSize);
|
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
|
for(ulong i = 0; i < remainingSectors; i++)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
2020-03-09 23:44:06 +00:00
|
|
|
|
Array.Copy(sector, 0, buffer, bufferPos, sectorSize);
|
|
|
|
|
|
bufferPos += (int)sectorSize;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2020-03-09 23:44:06 +00:00
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-06-14 23:45:26 +01:00
|
|
|
|
if(tag == SectorTagType.CdTrackFlags)
|
|
|
|
|
|
track = (uint)sectorAddress;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(track == 0)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _densitySeparationSectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
|
"Requested more sectors than present in track, won't cross tracks");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(tag == SectorTagType.CdTrackFlags)
|
|
|
|
|
|
return new byte[]
|
|
|
|
|
|
{
|
|
|
|
|
|
0x00
|
|
|
|
|
|
};
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var aaruTrack = new GdiTrack
|
|
|
|
|
|
{
|
|
|
|
|
|
Sequence = 0
|
|
|
|
|
|
};
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack gdiTrack in _discImage.Tracks.Where(gdiTrack => gdiTrack.Sequence == track))
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
aaruTrack = gdiTrack;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.Sequence == 0)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(length > aaruTrack.Sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
|
"Requested more sectors than present in track, won't cross tracks");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(tag)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEcc:
|
|
|
|
|
|
case SectorTagType.CdSectorEccP:
|
|
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
|
|
|
|
|
case SectorTagType.CdSectorEdc:
|
|
|
|
|
|
case SectorTagType.CdSectorHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSync: break;
|
|
|
|
|
|
case SectorTagType.CdTrackFlags:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] flags = new byte[1];
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
flags[0] += aaruTrack.Flags;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
switch(aaruTrack.TrackType)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
case TrackType.Audio: throw new ArgumentException("There are no tags on audio tracks", nameof(tag));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.Bps != 2352)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new FeatureNotPresentImageException("Image does not include tags for mode 1 sectors");
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSync:
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 12;
|
|
|
|
|
|
sectorSkip = 2340;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 12;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 2336;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
|
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEcc:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2076;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 276;
|
|
|
|
|
|
sectorSkip = 0;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEccP:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2076;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 172;
|
|
|
|
|
|
sectorSkip = 104;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2248;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 104;
|
|
|
|
|
|
sectorSkip = 0;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2064;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 284;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
ulong remainingSectors = length;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(aaruTrack.Pregap > 0 &&
|
|
|
|
|
|
sectorAddress < aaruTrack.Pregap)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-03-09 23:47:03 +00:00
|
|
|
|
ulong remainingPregap = aaruTrack.Pregap - sectorAddress;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:47:03 +00:00
|
|
|
|
remainingSectors -= length > remainingPregap ? remainingPregap : length;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(remainingSectors == 0)
|
|
|
|
|
|
return buffer;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
2020-07-20 21:11:32 +01:00
|
|
|
|
var br = new BinaryReader(_imageStream);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:44:06 +00:00
|
|
|
|
long pos = aaruTrack.Offset + (long)((sectorAddress * (sectorOffset + sectorSize + sectorSkip)) -
|
|
|
|
|
|
(aaruTrack.Pregap * aaruTrack.Bps));
|
|
|
|
|
|
|
|
|
|
|
|
if(pos < 0)
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
br.BaseStream.Seek(pos, SeekOrigin.Begin);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:44:06 +00:00
|
|
|
|
if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0 &&
|
|
|
|
|
|
remainingSectors == length)
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
buffer = br.ReadBytes((int)(sectorSize * remainingSectors));
|
2020-03-09 23:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] tmp = br.ReadBytes((int)(sectorSize * remainingSectors));
|
|
|
|
|
|
Array.Copy(tmp, 0, buffer, (int)((length - remainingSectors) * sectorSize), tmp.Length);
|
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
else
|
2020-03-09 23:44:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
int bufferPos = (int)((length - remainingSectors) * sectorSize);
|
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
|
for(ulong i = 0; i < remainingSectors; i++)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
2020-03-09 23:44:06 +00:00
|
|
|
|
Array.Copy(sector, 0, buffer, bufferPos, sectorSize);
|
|
|
|
|
|
bufferPos += (int)sectorSize;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2020-03-09 23:44:06 +00:00
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-20 14:22:22 +01:00
|
|
|
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
|
|
|
|
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-20 14:22:22 +01:00
|
|
|
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2021-09-20 14:22:22 +01:00
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
|
|
|
|
|
from gdiTrack in _discImage.Tracks
|
2018-01-01 21:32:12 +00:00
|
|
|
|
where gdiTrack.Sequence == kvp.Key
|
2020-02-29 18:03:35 +00:00
|
|
|
|
where sectorAddress - kvp.Value < gdiTrack.Sectors select kvp)
|
2021-09-20 14:22:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2021-09-20 14:22:22 +01:00
|
|
|
|
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.SectorNotFound;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(track == 0)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _densitySeparationSectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
|
"Requested more sectors than present in track, won't cross tracks");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
return new byte[length * 2352];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var aaruTrack = new GdiTrack
|
|
|
|
|
|
{
|
|
|
|
|
|
Sequence = 0
|
|
|
|
|
|
};
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack gdiTrack in _discImage.Tracks.Where(gdiTrack => gdiTrack.Sequence == track))
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
aaruTrack = gdiTrack;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.Sequence == 0)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(sectorAddress + length > aaruTrack.Sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
|
"Requested more sectors than present in track, won't cross tracks");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
switch(aaruTrack.TrackType)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
case TrackType.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.Bps == 2352)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2018-01-01 21:32:12 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
ulong remainingSectors = length;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(aaruTrack.Pregap > 0 &&
|
|
|
|
|
|
sectorAddress < aaruTrack.Pregap)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-03-09 23:47:03 +00:00
|
|
|
|
ulong remainingPregap = aaruTrack.Pregap - sectorAddress;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-03-09 23:47:03 +00:00
|
|
|
|
remainingSectors -= length > remainingPregap ? remainingPregap : length;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(remainingSectors == 0)
|
|
|
|
|
|
return buffer;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
2020-07-20 21:11:32 +01:00
|
|
|
|
var br = new BinaryReader(_imageStream);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:44:06 +00:00
|
|
|
|
long pos = aaruTrack.Offset + (long)((sectorAddress * (sectorOffset + sectorSize + sectorSkip)) -
|
|
|
|
|
|
(aaruTrack.Pregap * aaruTrack.Bps));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-03-09 23:44:06 +00:00
|
|
|
|
if(pos < 0)
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
br.BaseStream.Seek(pos, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0 &&
|
|
|
|
|
|
remainingSectors == length)
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
buffer = br.ReadBytes((int)(sectorSize * remainingSectors));
|
2020-03-09 23:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] tmp = br.ReadBytes((int)(sectorSize * remainingSectors));
|
|
|
|
|
|
Array.Copy(tmp, 0, buffer, (int)((length - remainingSectors) * sectorSize), tmp.Length);
|
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
else
|
2020-03-09 23:44:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
int bufferPos = (int)((length - remainingSectors) * sectorSize);
|
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
|
for(ulong i = 0; i < remainingSectors; i++)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
2020-03-09 23:44:06 +00:00
|
|
|
|
Array.Copy(sector, 0, buffer, bufferPos, sectorSize);
|
|
|
|
|
|
bufferPos += (int)sectorSize;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
2020-03-09 23:44:06 +00:00
|
|
|
|
}
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
switch(aaruTrack.TrackType)
|
2020-06-21 22:30:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
case TrackType.CdMode1 when aaruTrack.Bps == 2048:
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] fullSector = new byte[2352];
|
|
|
|
|
|
byte[] fullBuffer = new byte[2352 * length];
|
|
|
|
|
|
|
|
|
|
|
|
for(uint i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * 2048, fullSector, 16, 2048);
|
|
|
|
|
|
_sectorBuilder.ReconstructPrefix(ref fullSector, TrackType.CdMode1, (long)(sectorAddress + i));
|
|
|
|
|
|
_sectorBuilder.ReconstructEcc(ref fullSector, TrackType.CdMode1);
|
|
|
|
|
|
Array.Copy(fullSector, 0, fullBuffer, i * 2352, 2352);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buffer = fullBuffer;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-25 20:47:40 +00:00
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-11-11 04:19:18 +00:00
|
|
|
|
if(_discImage.Sessions.Contains(session))
|
2021-09-14 21:18:28 +01:00
|
|
|
|
return GetSessionTracks(session.Sequence);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2015-12-25 20:47:40 +00:00
|
|
|
|
throw new ImageNotSupportedException("Session does not exist in disc image");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2021-09-14 21:18:28 +01:00
|
|
|
|
List<Track> tracks = new();
|
2018-01-01 21:32:12 +00:00
|
|
|
|
bool expectedDensity;
|
2015-12-25 20:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
switch(session)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
expectedDensity = false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2015-12-25 20:47:40 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
expectedDensity = true;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2015-12-25 20:47:40 +00:00
|
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
default: throw new ImageNotSupportedException("Session does not exist in disc image");
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
foreach(GdiTrack gdiTrack in _discImage.Tracks)
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(gdiTrack.HighDensity == expectedDensity)
|
2015-12-25 20:47:40 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var track = new Track
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
2021-09-14 21:18:28 +01:00
|
|
|
|
Description = null,
|
|
|
|
|
|
StartSector = gdiTrack.StartSector,
|
|
|
|
|
|
Pregap = gdiTrack.Pregap,
|
|
|
|
|
|
Session = (ushort)(gdiTrack.HighDensity ? 2 : 1),
|
|
|
|
|
|
Sequence = gdiTrack.Sequence,
|
|
|
|
|
|
Type = gdiTrack.TrackType,
|
|
|
|
|
|
Filter = gdiTrack.TrackFilter,
|
|
|
|
|
|
File = gdiTrack.TrackFile,
|
|
|
|
|
|
FileOffset = (ulong)gdiTrack.Offset,
|
|
|
|
|
|
FileType = "BINARY",
|
|
|
|
|
|
RawBytesPerSector = gdiTrack.Bps,
|
|
|
|
|
|
BytesPerSector = gdiTrack.TrackType == TrackType.Data ? 2048 : 2352,
|
|
|
|
|
|
SubchannelType = TrackSubchannelType.None
|
2017-12-22 06:55:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-09-14 21:18:28 +01:00
|
|
|
|
track.EndSector = track.StartSector + gdiTrack.Sectors - 1;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
|
|
|
|
|
tracks.Add(track);
|
2015-12-25 20:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|