2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2015-12-23 23:46:31 +00:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
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-23 23:46:31 +00:00
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Component : Disk image plugins.
|
2015-12-23 23:46:31 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads cdrdao cuesheets (toc/bin).
|
2015-12-23 23:46:31 +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-23 23:46:31 +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-23 23:46:31 +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-23 23:46:31 +00:00
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2015-12-23 23:46:31 +00:00
|
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
|
2015-12-23 23:46:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.Text;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Checksums;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Exceptions;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Structs;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using DiscImageChef.Console;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public partial class Cdrdao
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(imageFilter == null) return false;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
cdrdaoFilter = imageFilter;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
|
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
tocStream = new StreamReader(imageFilter.GetDataForkStream());
|
2015-12-23 23:46:31 +00:00
|
|
|
|
bool intrack = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize all RegExs
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Regex regexComment = new Regex(REGEX_COMMENT);
|
|
|
|
|
|
Regex regexDiskType = new Regex(REGEX_DISCTYPE);
|
|
|
|
|
|
Regex regexMcn = new Regex(REGEX_MCN);
|
|
|
|
|
|
Regex regexTrack = new Regex(REGEX_TRACK);
|
|
|
|
|
|
Regex regexCopy = new Regex(REGEX_COPY);
|
|
|
|
|
|
Regex regexEmphasis = new Regex(REGEX_EMPHASIS);
|
|
|
|
|
|
Regex regexStereo = new Regex(REGEX_STEREO);
|
|
|
|
|
|
Regex regexIsrc = new Regex(REGEX_ISRC);
|
|
|
|
|
|
Regex regexIndex = new Regex(REGEX_INDEX);
|
|
|
|
|
|
Regex regexPregap = new Regex(REGEX_PREGAP);
|
|
|
|
|
|
Regex regexZeroPregap = new Regex(REGEX_ZERO_PREGAP);
|
|
|
|
|
|
Regex regexZeroData = new Regex(REGEX_ZERO_DATA);
|
|
|
|
|
|
Regex regexZeroAudio = new Regex(REGEX_ZERO_AUDIO);
|
|
|
|
|
|
Regex regexAudioFile = new Regex(REGEX_FILE_AUDIO);
|
|
|
|
|
|
Regex regexFile = new Regex(REGEX_FILE_DATA);
|
|
|
|
|
|
Regex regexTitle = new Regex(REGEX_TITLE);
|
|
|
|
|
|
Regex regexPerformer = new Regex(REGEX_PERFORMER);
|
|
|
|
|
|
Regex regexSongwriter = new Regex(REGEX_SONGWRITER);
|
|
|
|
|
|
Regex regexComposer = new Regex(REGEX_COMPOSER);
|
|
|
|
|
|
Regex regexArranger = new Regex(REGEX_ARRANGER);
|
|
|
|
|
|
Regex regexMessage = new Regex(REGEX_MESSAGE);
|
|
|
|
|
|
Regex regexDiscId = new Regex(REGEX_DISC_ID);
|
|
|
|
|
|
Regex regexUpc = new Regex(REGEX_UPC);
|
|
|
|
|
|
Regex regexCdText = new Regex(REGEX_CD_TEXT);
|
|
|
|
|
|
Regex regexLanguage = new Regex(REGEX_LANGUAGE);
|
|
|
|
|
|
Regex regexClosure = new Regex(REGEX_CLOSURE);
|
|
|
|
|
|
Regex regexLanguageMap = new Regex(REGEX_LANGUAGE_MAP);
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Regex regexLanguageMapping = new Regex(REGEX_LANGUAGE_MAPPING);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
// Initialize all RegEx matches
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Match matchComment;
|
|
|
|
|
|
Match matchDiskType;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
// Initialize disc
|
2017-12-22 06:55:04 +00:00
|
|
|
|
discimage = new CdrdaoDisc {Tracks = new List<CdrdaoTrack>(), Comment = ""};
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
CdrdaoTrack currenttrack = new CdrdaoTrack();
|
|
|
|
|
|
uint currentTrackNumber = 0;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Indexes = new Dictionary<int, ulong>();
|
|
|
|
|
|
currenttrack.Pregap = 0;
|
|
|
|
|
|
ulong currentSector = 0;
|
|
|
|
|
|
int nextindex = 2;
|
|
|
|
|
|
StringBuilder commentBuilder = new StringBuilder();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
tocStream = new StreamReader(cdrdaoFilter.GetDataForkStream());
|
|
|
|
|
|
string line;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
int lineNumber = 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
while(tocStream.Peek() >= 0)
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber++;
|
|
|
|
|
|
line = tocStream.ReadLine();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
matchDiskType = regexDiskType.Match(line ?? throw new InvalidOperationException());
|
2018-01-01 21:32:12 +00:00
|
|
|
|
matchComment = regexComment.Match(line);
|
2017-09-11 21:01:11 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
// Skip comments at start of file
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(matchComment.Success) continue;
|
2017-09-11 21:01:11 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!matchDiskType.Success)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Not a CDRDAO TOC or TOC type not in line {0}.",
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-09-11 21:01:11 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
tocStream = new StreamReader(cdrdaoFilter.GetDataForkStream());
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber = 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
tocStream.BaseStream.Position = 0;
|
|
|
|
|
|
while(tocStream.Peek() >= 0)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber++;
|
|
|
|
|
|
line = tocStream.ReadLine();
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
matchComment = regexComment.Match(line ?? throw new InvalidOperationException());
|
|
|
|
|
|
matchDiskType = regexDiskType.Match(line);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Match matchMcn = regexMcn.Match(line);
|
|
|
|
|
|
Match matchTrack = regexTrack.Match(line);
|
|
|
|
|
|
Match matchCopy = regexCopy.Match(line);
|
|
|
|
|
|
Match matchEmphasis = regexEmphasis.Match(line);
|
|
|
|
|
|
Match matchStereo = regexStereo.Match(line);
|
|
|
|
|
|
Match matchIsrc = regexIsrc.Match(line);
|
|
|
|
|
|
Match matchIndex = regexIndex.Match(line);
|
|
|
|
|
|
Match matchPregap = regexPregap.Match(line);
|
|
|
|
|
|
Match matchZeroPregap = regexZeroPregap.Match(line);
|
|
|
|
|
|
Match matchZeroData = regexZeroData.Match(line);
|
|
|
|
|
|
Match matchZeroAudio = regexZeroAudio.Match(line);
|
|
|
|
|
|
Match matchAudioFile = regexAudioFile.Match(line);
|
|
|
|
|
|
Match matchFile = regexFile.Match(line);
|
|
|
|
|
|
Match matchTitle = regexTitle.Match(line);
|
|
|
|
|
|
Match matchPerformer = regexPerformer.Match(line);
|
|
|
|
|
|
Match matchSongwriter = regexSongwriter.Match(line);
|
|
|
|
|
|
Match matchComposer = regexComposer.Match(line);
|
|
|
|
|
|
Match matchArranger = regexArranger.Match(line);
|
|
|
|
|
|
Match matchMessage = regexMessage.Match(line);
|
|
|
|
|
|
Match matchDiscId = regexDiscId.Match(line);
|
|
|
|
|
|
Match matchUpc = regexUpc.Match(line);
|
|
|
|
|
|
Match matchCdText = regexCdText.Match(line);
|
|
|
|
|
|
Match matchLanguage = regexLanguage.Match(line);
|
|
|
|
|
|
Match matchClosure = regexClosure.Match(line);
|
|
|
|
|
|
Match matchLanguageMap = regexLanguageMap.Match(line);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Match matchLanguageMapping = regexLanguageMapping.Match(line);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
|
|
|
|
|
if(matchComment.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
// Ignore "// Track X" comments
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(matchComment.Groups["comment"].Value.StartsWith(" Track ", StringComparison.Ordinal))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found comment \"{1}\" at line {0}", lineNumber,
|
2017-12-21 06:06:19 +00:00
|
|
|
|
matchComment.Groups["comment"].Value.Trim());
|
|
|
|
|
|
commentBuilder.AppendLine(matchComment.Groups["comment"].Value.Trim());
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchDiskType.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found {1} at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchDiskType.Groups["type"].Value);
|
|
|
|
|
|
discimage.Disktypestr = matchDiskType.Groups["type"].Value;
|
|
|
|
|
|
switch(matchDiskType.Groups["type"].Value)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
case "CD_DA":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktype = MediaType.CDDA;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "CD_ROM":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktype = MediaType.CDROM;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "CD_ROM_XA":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktype = MediaType.CDROMXA;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "CD_I":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktype = MediaType.CDI;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktype = MediaType.CD;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchMcn.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found CATALOG \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchMcn.Groups["catalog"].Value);
|
|
|
|
|
|
discimage.Mcn = matchMcn.Groups["catalog"].Value;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchTrack.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(matchTrack.Groups["subchan"].Value == "")
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin",
|
2017-12-24 00:12:31 +00:00
|
|
|
|
"Found TRACK type \"{1}\" with no subchannel at line {0}",
|
|
|
|
|
|
lineNumber, matchTrack.Groups["type"].Value);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin",
|
2017-12-22 06:55:04 +00:00
|
|
|
|
"Found TRACK type \"{1}\" subchannel {2} at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchTrack.Groups["type"].Value,
|
|
|
|
|
|
matchTrack.Groups["subchan"].Value);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(intrack)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentSector += currenttrack.Sectors;
|
|
|
|
|
|
if(currenttrack.Pregap != currenttrack.Sectors && !currenttrack.Indexes.ContainsKey(1))
|
|
|
|
|
|
currenttrack.Indexes.Add(1, currenttrack.StartSector + currenttrack.Pregap);
|
|
|
|
|
|
discimage.Tracks.Add(currenttrack);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
currenttrack = new CdrdaoTrack {Indexes = new Dictionary<int, ulong>(), Pregap = 0};
|
2018-01-01 21:32:12 +00:00
|
|
|
|
nextindex = 2;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2018-01-01 21:32:12 +00:00
|
|
|
|
|
2015-12-23 23:46:31 +00:00
|
|
|
|
currentTrackNumber++;
|
|
|
|
|
|
intrack = true;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
switch(matchTrack.Groups["type"].Value)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
case "AUDIO":
|
|
|
|
|
|
case "MODE1_RAW":
|
|
|
|
|
|
case "MODE2_RAW":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Bps = 2352;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "MODE1":
|
|
|
|
|
|
case "MODE2_FORM1":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Bps = 2048;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "MODE2_FORM2":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Bps = 2324;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "MODE2":
|
|
|
|
|
|
case "MODE2_FORM_MIX":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Bps = 2336;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
NotSupportedException($"Track mode {matchTrack.Groups["type"].Value} is unsupported");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
switch(matchTrack.Groups["subchan"].Value)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
case "": break;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
case "RW":
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Packedsubchannel = true;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
goto case "RW_RAW";
|
|
|
|
|
|
case "RW_RAW":
|
2018-01-03 17:36:29 +00:00
|
|
|
|
currenttrack.Subchannel = true;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
NotSupportedException($"Track subchannel mode {matchTrack.Groups["subchan"].Value} is unsupported");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Tracktype = matchTrack.Groups["type"].Value;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
currenttrack.Sequence = currentTrackNumber;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.StartSector = currentSector;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchCopy.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found {1} COPY at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchCopy.Groups["no"].Value);
|
|
|
|
|
|
currenttrack.FlagDcp |= intrack && matchCopy.Groups["no"].Value == "";
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchEmphasis.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found {1} PRE_EMPHASIS at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchEmphasis.Groups["no"].Value);
|
2018-01-03 17:36:29 +00:00
|
|
|
|
currenttrack.FlagPre |= intrack && matchEmphasis.Groups["no"].Value == "";
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchStereo.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found {1}_CHANNEL_AUDIO at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchStereo.Groups["num"].Value);
|
2018-01-03 17:36:29 +00:00
|
|
|
|
currenttrack.Flag_4Ch |= intrack && matchStereo.Groups["num"].Value == "FOUR";
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchIsrc.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found ISRC \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchIsrc.Groups["isrc"].Value);
|
|
|
|
|
|
if(intrack) currenttrack.Isrc = matchIsrc.Groups["isrc"].Value;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchIndex.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found INDEX \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchIndex.Groups["address"].Value);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
string[] lengthString = matchFile.Groups["length"].Value.Split(':');
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong nextIndexPos = ulong.Parse(lengthString[0]) * 60 * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[1]) * 75 + ulong.Parse(lengthString[2]);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Indexes.Add(nextindex,
|
|
|
|
|
|
nextIndexPos + currenttrack.Pregap + currenttrack.StartSector);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchPregap.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found START \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchPregap.Groups["address"].Value);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Indexes.Add(0, currenttrack.StartSector);
|
|
|
|
|
|
if(matchPregap.Groups["address"].Value != "")
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
string[] lengthString = matchPregap.Groups["address"].Value.Split(':');
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Pregap = ulong.Parse(lengthString[0]) * 60 * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[1]) * 75 + ulong.Parse(lengthString[2]);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else currenttrack.Pregap = currenttrack.Sectors;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchZeroPregap.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found PREGAP \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchZeroPregap.Groups["length"].Value);
|
|
|
|
|
|
currenttrack.Indexes.Add(0, currenttrack.StartSector);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
string[] lengthString = matchZeroPregap.Groups["length"].Value.Split(':');
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Pregap = ulong.Parse(lengthString[0]) * 60 * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[1]) * 75 + ulong.Parse(lengthString[2]);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchZeroData.Success)
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found ZERO \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchZeroData.Groups["length"].Value);
|
|
|
|
|
|
else if(matchZeroAudio.Success)
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found SILENCE \"{1}\" at line {0}", lineNumber,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
matchZeroAudio.Groups["length"].Value);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
else
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FiltersList filtersList;
|
|
|
|
|
|
if(matchAudioFile.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found AUDIOFILE \"{1}\" at line {0}",
|
|
|
|
|
|
lineNumber, matchAudioFile.Groups["filename"].Value);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
filtersList = new FiltersList();
|
2017-12-22 06:55:04 +00:00
|
|
|
|
currenttrack.Trackfile = new CdrdaoTrackFile
|
|
|
|
|
|
{
|
|
|
|
|
|
Datafilter =
|
|
|
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
|
|
|
|
|
matchAudioFile.Groups["filename"].Value)),
|
|
|
|
|
|
Datafile = matchAudioFile.Groups["filename"].Value,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Offset = matchAudioFile.Groups["base_offset"].Value != ""
|
|
|
|
|
|
? ulong.Parse(matchAudioFile.Groups["base_offset"].Value)
|
|
|
|
|
|
: 0,
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Filetype = "BINARY",
|
|
|
|
|
|
Sequence = currentTrackNumber
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ulong startSectors = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(matchAudioFile.Groups["start"].Value != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] startString = matchAudioFile.Groups["start"].Value.Split(':');
|
2018-06-22 08:08:38 +01:00
|
|
|
|
startSectors = ulong.Parse(startString[0]) * 60 * 75 +
|
|
|
|
|
|
ulong.Parse(startString[1]) * 75 + ulong.Parse(startString[2]);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currenttrack.Trackfile.Offset += startSectors * currenttrack.Bps;
|
|
|
|
|
|
|
|
|
|
|
|
if(matchAudioFile.Groups["length"].Value != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] lengthString = matchAudioFile.Groups["length"].Value.Split(':');
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Sectors = ulong.Parse(lengthString[0]) * 60 * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[1]) * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[2]);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
currenttrack.Sectors =
|
|
|
|
|
|
((ulong)currenttrack.Trackfile.Datafilter.GetDataForkLength() -
|
|
|
|
|
|
currenttrack.Trackfile.Offset) / currenttrack.Bps;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-22 06:55:04 +00:00
|
|
|
|
else if(matchFile.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found DATAFILE \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchFile.Groups["filename"].Value);
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
filtersList = new FiltersList();
|
2017-12-22 06:55:04 +00:00
|
|
|
|
currenttrack.Trackfile = new CdrdaoTrackFile
|
|
|
|
|
|
{
|
|
|
|
|
|
Datafilter =
|
|
|
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
|
|
|
|
|
matchFile.Groups["filename"].Value)),
|
|
|
|
|
|
Datafile = matchAudioFile.Groups["filename"].Value,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Offset = matchFile.Groups["base_offset"].Value != ""
|
|
|
|
|
|
? ulong.Parse(matchFile.Groups["base_offset"].Value)
|
|
|
|
|
|
: 0,
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Filetype = "BINARY",
|
|
|
|
|
|
Sequence = currentTrackNumber
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(matchFile.Groups["length"].Value != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] lengthString = matchFile.Groups["length"].Value.Split(':');
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Sectors = ulong.Parse(lengthString[0]) * 60 * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[1]) * 75 +
|
|
|
|
|
|
ulong.Parse(lengthString[2]);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
currenttrack.Sectors =
|
|
|
|
|
|
((ulong)currenttrack.Trackfile.Datafilter.GetDataForkLength() -
|
|
|
|
|
|
currenttrack.Trackfile.Offset) / currenttrack.Bps;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-22 06:55:04 +00:00
|
|
|
|
else if(matchTitle.Success)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found TITLE \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchTitle.Groups["title"].Value);
|
|
|
|
|
|
if(intrack) currenttrack.Title = matchTitle.Groups["title"].Value;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else discimage.Title = matchTitle.Groups["title"].Value;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-22 06:55:04 +00:00
|
|
|
|
else if(matchPerformer.Success)
|
|
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found PERFORMER \"{1}\" at line {0}",
|
|
|
|
|
|
lineNumber, matchPerformer.Groups["performer"].Value);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(intrack) currenttrack.Performer = matchPerformer.Groups["performer"].Value;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else discimage.Performer = matchPerformer.Groups["performer"].Value;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(matchSongwriter.Success)
|
|
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found SONGWRITER \"{1}\" at line {0}",
|
|
|
|
|
|
lineNumber, matchSongwriter.Groups["songwriter"].Value);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(intrack) currenttrack.Songwriter = matchSongwriter.Groups["songwriter"].Value;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else discimage.Songwriter = matchSongwriter.Groups["songwriter"].Value;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(matchComposer.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found COMPOSER \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchComposer.Groups["composer"].Value);
|
|
|
|
|
|
if(intrack) currenttrack.Composer = matchComposer.Groups["composer"].Value;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else discimage.Composer = matchComposer.Groups["composer"].Value;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(matchArranger.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found ARRANGER \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchArranger.Groups["arranger"].Value);
|
|
|
|
|
|
if(intrack) currenttrack.Arranger = matchArranger.Groups["arranger"].Value;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else discimage.Arranger = matchArranger.Groups["arranger"].Value;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(matchMessage.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found MESSAGE \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchMessage.Groups["message"].Value);
|
|
|
|
|
|
if(intrack) currenttrack.Message = matchMessage.Groups["message"].Value;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else discimage.Message = matchMessage.Groups["message"].Value;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(matchDiscId.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found DISC_ID \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchDiscId.Groups["discid"].Value);
|
|
|
|
|
|
if(!intrack) discimage.DiskId = matchDiscId.Groups["discid"].Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(matchUpc.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Found UPC_EAN \"{1}\" at line {0}", lineNumber,
|
|
|
|
|
|
matchUpc.Groups["catalog"].Value);
|
|
|
|
|
|
if(!intrack) discimage.Barcode = matchUpc.Groups["catalog"].Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Ignored fields
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else if(matchCdText.Success || matchLanguage.Success || matchClosure.Success ||
|
2017-12-22 06:55:04 +00:00
|
|
|
|
matchLanguageMap.Success || matchLanguageMapping.Success) { }
|
|
|
|
|
|
else if(line == "") // Empty line, ignore it
|
|
|
|
|
|
{ }
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2018-01-01 21:32:12 +00:00
|
|
|
|
|
2015-12-23 23:46:31 +00:00
|
|
|
|
// TODO: Regex CD-TEXT SIZE_INFO
|
|
|
|
|
|
/*
|
|
|
|
|
|
else // Non-empty unknown field
|
|
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new FeatureUnsupportedImageException(string.Format("Found unknown field defined at line {0}: \"{1}\"", line, _line));
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currenttrack.Sequence != 0)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currenttrack.Pregap != currenttrack.Sectors && !currenttrack.Indexes.ContainsKey(1))
|
|
|
|
|
|
currenttrack.Indexes.Add(1, currenttrack.StartSector + currenttrack.Pregap);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Tracks.Add(currenttrack);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Comment = commentBuilder.ToString();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
// DEBUG information
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Disc image parsing results");
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Disc CD-TEXT:");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Arranger == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tArranger is not set.");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tArranger: {0}",
|
|
|
|
|
|
discimage.Arranger);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Composer == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tComposer is not set.");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tComposer: {0}",
|
|
|
|
|
|
discimage.Composer);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Performer == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tPerformer is not set.");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPerformer: {0}",
|
|
|
|
|
|
discimage.Performer);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Songwriter == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tSongwriter is not set.");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tSongwriter: {0}",
|
|
|
|
|
|
discimage.Songwriter);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Title == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tTitle is not set.");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\tTitle: {0}", discimage.Title);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Disc information:");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tGuessed disk type: {0}", discimage.Disktype);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Barcode == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tBarcode not set.");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tBarcode: {0}",
|
|
|
|
|
|
discimage.Barcode);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.DiskId == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tDisc ID not set.");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tDisc ID: {0}",
|
|
|
|
|
|
discimage.DiskId);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Mcn == null) DicConsole.DebugWriteLine("CDRDAO plugin", "\tMCN not set.");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\tMCN: {0}", discimage.Mcn);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(string.IsNullOrEmpty(discimage.Comment))
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tComment not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\tComment: \"{0}\"", discimage.Comment);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Track information:");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tDisc contains {0} tracks", discimage.Tracks.Count);
|
|
|
|
|
|
for(int i = 0; i < discimage.Tracks.Count; i++)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tTrack {0} information:",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Tracks[i].Sequence);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\t{0} bytes per sector", discimage.Tracks[i].Bps);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tPregap: {0} sectors", discimage.Tracks[i].Pregap);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tData: {0} sectors starting at sector {1}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Tracks[i].Sectors, discimage.Tracks[i].StartSector);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tPostgap: {0} sectors", discimage.Tracks[i].Postgap);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Flag_4Ch)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tTrack is flagged as quadraphonic");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].FlagDcp)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tTrack allows digital copy");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].FlagPre)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tTrack has pre-emphasis applied");
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin",
|
|
|
|
|
|
"\t\tTrack resides in file {0}, type defined as {1}, starting at byte {2}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Tracks[i].Trackfile.Datafilter.GetFilename(),
|
|
|
|
|
|
discimage.Tracks[i].Trackfile.Filetype,
|
|
|
|
|
|
discimage.Tracks[i].Trackfile.Offset);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tIndexes:");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
foreach(KeyValuePair<int, ulong> kvp in discimage.Tracks[i].Indexes)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\t\tIndex {0} starts at sector {1}", kvp.Key,
|
|
|
|
|
|
kvp.Value);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Isrc == null)
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tISRC is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tISRC: {0}", discimage.Tracks[i].Isrc);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Arranger == null)
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tArranger is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tArranger: {0}", discimage.Tracks[i].Arranger);
|
|
|
|
|
|
if(discimage.Tracks[i].Composer == null)
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tComposer is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tComposer: {0}", discimage.Tracks[i].Composer);
|
|
|
|
|
|
if(discimage.Tracks[i].Performer == null)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tPerformer is not set.");
|
|
|
|
|
|
else
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tPerformer: {0}", discimage.Tracks[i].Performer);
|
|
|
|
|
|
if(discimage.Tracks[i].Songwriter == null)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tSongwriter is not set.");
|
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tSongwriter: {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Tracks[i].Songwriter);
|
|
|
|
|
|
if(discimage.Tracks[i].Title == null)
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tTitle is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRDAO plugin", "\t\tTitle: {0}", discimage.Tracks[i].Title);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Building offset map");
|
|
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Partitions = new List<Partition>();
|
|
|
|
|
|
offsetmap = new Dictionary<uint, ulong>();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
ulong byteOffset = 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
ulong partitionSequence = 0;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < discimage.Tracks.Count; i++)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
ulong index0Len = 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Sequence == 1 && i != 0)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
throw new ImageNotSupportedException("Unordered tracks");
|
|
|
|
|
|
|
|
|
|
|
|
// Index 01
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Partition partition = new Partition
|
|
|
|
|
|
{
|
|
|
|
|
|
Description = $"Track {discimage.Tracks[i].Sequence}.",
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Name = discimage.Tracks[i].Title,
|
|
|
|
|
|
Start = discimage.Tracks[i].StartSector,
|
|
|
|
|
|
Size = (discimage.Tracks[i].Sectors - index0Len) * discimage.Tracks[i].Bps,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Length = discimage.Tracks[i].Sectors - index0Len,
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Sequence = partitionSequence,
|
|
|
|
|
|
Offset = byteOffset,
|
|
|
|
|
|
Type = discimage.Tracks[i].Tracktype
|
2017-12-22 06:55:04 +00:00
|
|
|
|
};
|
2017-07-19 16:37:11 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byteOffset += partition.Size;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
partitionSequence++;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!offsetmap.ContainsKey(discimage.Tracks[i].Sequence))
|
|
|
|
|
|
offsetmap.Add(discimage.Tracks[i].Sequence, partition.Start);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
offsetmap.TryGetValue(discimage.Tracks[i].Sequence, out ulong oldStart);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(partition.Start < oldStart)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
offsetmap.Remove(discimage.Tracks[i].Sequence);
|
|
|
|
|
|
offsetmap.Add(discimage.Tracks[i].Sequence, partition.Start);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
Partitions.Add(partition);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Print partition map
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "printing partition map");
|
2018-01-01 21:32:12 +00:00
|
|
|
|
foreach(Partition partition in Partitions)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "Partition sequence: {0}", partition.Sequence);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition name: {0}", partition.Name);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition description: {0}",
|
|
|
|
|
|
partition.Description);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition type: {0}", partition.Type);
|
2017-07-19 16:37:11 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition starting sector: {0}", partition.Start);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition sectors: {0}", partition.Length);
|
2017-07-19 16:37:11 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition starting offset: {0}", partition.Offset);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRDAO plugin", "\tPartition size in bytes: {0}", partition.Size);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
foreach(CdrdaoTrack track in discimage.Tracks)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.ImageSize += track.Bps * track.Sectors;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
imageInfo.Sectors += track.Sectors;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-03 17:36:29 +00:00
|
|
|
|
if(discimage.Disktype != MediaType.CDG && discimage.Disktype != MediaType.CDEG &&
|
|
|
|
|
|
discimage.Disktype != MediaType.CDMIDI && discimage.Disktype != MediaType.CDROMXA &&
|
|
|
|
|
|
discimage.Disktype != MediaType.CDDA && discimage.Disktype != MediaType.CDI &&
|
|
|
|
|
|
discimage.Disktype != MediaType.CDPLUS) imageInfo.SectorSize = 2048; // Only data tracks
|
|
|
|
|
|
else imageInfo.SectorSize = 2352; // All others
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(discimage.Mcn != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_MCN);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Application = "CDRDAO";
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
imageInfo.Comments = discimage.Comment;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.MediaSerialNumber = discimage.Mcn;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
imageInfo.MediaBarcode = discimage.Barcode;
|
|
|
|
|
|
imageInfo.MediaType = discimage.Disktype;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
foreach(CdrdaoTrack track in discimage.Tracks)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(track.Subchannel)
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
switch(track.Tracktype)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_AUDIO:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdTrackIsrc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackIsrc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_MIX:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
DicConsole.VerboseWriteLine("CDRDAO image describes a disc of type {0}", imageInfo.MediaType);
|
|
|
|
|
|
if(!string.IsNullOrEmpty(imageInfo.Comments))
|
|
|
|
|
|
DicConsole.VerboseWriteLine("CDRDAO comments: {0}", imageInfo.Comments);
|
2016-08-21 17:35:35 +01:00
|
|
|
|
|
2015-12-23 23:46:31 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
catch(Exception ex)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
|
DicConsole.ErrorWriteLine("Exception trying to identify image file {0}", imageFilter);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Exception: {0}", ex.Message);
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Stack trace: {0}", ex.StackTrace);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2016-01-16 03:54:55 +00:00
|
|
|
|
case MediaTagType.CD_MCN:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
|
if(discimage.Mcn != null) return Encoding.ASCII.GetBytes(discimage.Mcn);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain MCN information.");
|
|
|
|
|
|
}
|
2015-12-23 23:46:31 +00:00
|
|
|
|
default:
|
|
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1, track);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, track, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
|
where sectorAddress >= kvp.Value
|
|
|
|
|
|
from cdrdaoTrack in discimage.Tracks
|
2018-01-01 21:32:12 +00:00
|
|
|
|
where cdrdaoTrack.Sequence == kvp.Key
|
2017-12-24 00:12:31 +00:00
|
|
|
|
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-21 17:58:51 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
|
where sectorAddress >= kvp.Value
|
|
|
|
|
|
from cdrdaoTrack in discimage.Tracks
|
2018-01-01 21:32:12 +00:00
|
|
|
|
where cdrdaoTrack.Sequence == kvp.Key
|
2017-12-24 00:12:31 +00:00
|
|
|
|
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-21 17:58:51 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrdaoTrack dicTrack = new CdrdaoTrack {Sequence = 0};
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(CdrdaoTrack cdrdaoTrack in discimage.Tracks.Where(cdrdaoTrack => cdrdaoTrack.Sequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = cdrdaoTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.Sequence == 0)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(length > dicTrack.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-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.Tracktype)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_FORM1:
|
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 = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_FORM2:
|
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 = 2324;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_MIX:
|
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 = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_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;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 16;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 288;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 16;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.Subchannel) sectorSkip += 96;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
imageStream = dicTrack.Trackfile.Datafilter.GetDataForkStream();
|
2016-09-05 17:37:31 +01:00
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
br.BaseStream
|
2017-12-22 06:55:04 +00:00
|
|
|
|
.Seek((long)dicTrack.Trackfile.Offset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) buffer = br.ReadBytes((int)(sectorSize * length));
|
2016-09-05 17:37:31 +01:00
|
|
|
|
else
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
2015-12-23 23:46:31 +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);
|
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 19:39:35 +00:00
|
|
|
|
// cdrdao audio tracks are endian swapped corresponding to DiscImageChef
|
|
|
|
|
|
if(dicTrack.Tracktype != CDRDAO_TRACK_TYPE_AUDIO) return buffer;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] swapped = new byte[buffer.Length];
|
|
|
|
|
|
for(long i = 0; i < buffer.Length; i += 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
swapped[i] = buffer[i + 1];
|
|
|
|
|
|
swapped[i + 1] = buffer[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return swapped;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrdaoTrack dicTrack = new CdrdaoTrack {Sequence = 0};
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(CdrdaoTrack cdrdaoTrack in discimage.Tracks.Where(cdrdaoTrack => cdrdaoTrack.Sequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = cdrdaoTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.Sequence == 0)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(length > dicTrack.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-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip = 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(!dicTrack.Subchannel && tag == SectorTagType.CdSectorSubchannel)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentException("No tags in image for requested track", nameof(tag));
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(tag)
|
2015-12-23 23:46:31 +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.CdSectorSubchannel:
|
|
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSync: break;
|
|
|
|
|
|
case SectorTagType.CdTrackFlags:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2018-01-01 21:32:12 +00:00
|
|
|
|
CdFlags flags = 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.Tracktype != CDRDAO_TRACK_TYPE_AUDIO) flags |= CdFlags.DataTrack;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.FlagDcp) flags |= CdFlags.CopyPermitted;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.FlagPre) flags |= CdFlags.PreEmphasis;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.Flag_4Ch) flags |= CdFlags.FourChannel;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
return new[] {(byte)flags};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
2018-01-03 17:36:29 +00:00
|
|
|
|
case SectorTagType.CdTrackIsrc:
|
|
|
|
|
|
if(dicTrack.Isrc == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
return Encoding.UTF8.GetBytes(dicTrack.Isrc);
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.Tracktype)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_FORM1:
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
throw new ArgumentException("No tags in image for requested track", nameof(tag));
|
|
|
|
|
|
|
|
|
|
|
|
sectorOffset = 2048;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 96;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_FORM2:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_MIX:
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
throw new ArgumentException("No tags in image for requested track", nameof(tag));
|
|
|
|
|
|
|
|
|
|
|
|
sectorOffset = 2336;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 96;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_AUDIO:
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
throw new ArgumentException("No tags in image for requested track", nameof(tag));
|
|
|
|
|
|
|
|
|
|
|
|
sectorOffset = 2352;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 96;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch(tag)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSync:
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 12;
|
|
|
|
|
|
sectorSkip = 2340;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2015-12-23 23:46:31 +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;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2352;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 96;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
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;
|
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;
|
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;
|
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;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_RAW: // Requires reading sector
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
|
|
|
|
|
|
|
|
|
|
|
|
sectorOffset = 2352;
|
2018-01-01 21:32:12 +00:00
|
|
|
|
sectorSize = 96;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
imageStream = dicTrack.Trackfile.Datafilter.GetDataForkStream();
|
2016-09-05 17:37:31 +01:00
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
br.BaseStream
|
2017-12-22 06:55:04 +00:00
|
|
|
|
.Seek((long)dicTrack.Trackfile.Offset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) buffer = br.ReadBytes((int)(sectorSize * length));
|
2016-09-05 17:37:31 +01:00
|
|
|
|
else
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
2015-12-23 23:46:31 +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);
|
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1, track);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
|
where sectorAddress >= kvp.Value
|
|
|
|
|
|
from cdrdaoTrack in discimage.Tracks
|
2018-01-01 21:32:12 +00:00
|
|
|
|
where cdrdaoTrack.Sequence == kvp.Key
|
2017-12-24 00:12:31 +00:00
|
|
|
|
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrdaoTrack dicTrack = new CdrdaoTrack {Sequence = 0};
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(CdrdaoTrack cdrdaoTrack in discimage.Tracks.Where(cdrdaoTrack => cdrdaoTrack.Sequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = cdrdaoTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.Sequence == 0)
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(length > dicTrack.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-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.Tracktype)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_FORM1:
|
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 = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_FORM2:
|
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 = 2324;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_MIX:
|
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 = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE1_RAW:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_MODE2_RAW:
|
|
|
|
|
|
case CDRDAO_TRACK_TYPE_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;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.Subchannel) sectorSkip += 96;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
imageStream = dicTrack.Trackfile.Datafilter.GetDataForkStream();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
br.BaseStream
|
2017-12-22 06:55:04 +00:00
|
|
|
|
.Seek((long)dicTrack.Trackfile.Offset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) buffer = br.ReadBytes((int)(sectorSize * length));
|
2015-12-23 23:46:31 +00:00
|
|
|
|
else
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(int i = 0; i < length; i++)
|
2015-12-23 23:46:31 +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);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 19:39:35 +00:00
|
|
|
|
// cdrdao audio tracks are endian swapped corresponding to DiscImageChef
|
|
|
|
|
|
if(dicTrack.Tracktype != CDRDAO_TRACK_TYPE_AUDIO) return buffer;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] swapped = new byte[buffer.Length];
|
|
|
|
|
|
for(long i = 0; i < buffer.Length; i += 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
swapped[i] = buffer[i + 1];
|
|
|
|
|
|
swapped[i + 1] = buffer[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return swapped;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
return GetSessionTracks(session.SessionSequence);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
2017-12-26 02:51:10 +00:00
|
|
|
|
if(session == 1) return Tracks;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2015-12-23 23:46:31 +00:00
|
|
|
|
throw new ImageNotSupportedException("Session does not exist in disc image");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress, track);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
|
|
|
|
|
out List<ulong> unknownLbas)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
int bps = (int)(buffer.Length / length);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
byte[] sector = new byte[bps];
|
2018-06-22 08:08:38 +01:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(int i = 0; i < length; i++)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(sectorStatus)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(unknownLbas.Count > 0) return null;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
return failingLbas.Count <= 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
|
|
|
|
|
out List<ulong> unknownLbas)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
2018-01-01 21:32:12 +00:00
|
|
|
|
int bps = (int)(buffer.Length / length);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
byte[] sector = new byte[bps];
|
2018-06-22 08:08:38 +01:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(int i = 0; i < length; i++)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(sectorStatus)
|
2015-12-23 23:46:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2015-12-23 23:46:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(unknownLbas.Count > 0) return null;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
return failingLbas.Count <= 0;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|