2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2016-07-28 18:13:49 +01: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>
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Component : Disk image plugins.
|
2016-07-28 18:13:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads CDRWin cuesheets (cue/bin).
|
2016-07-28 18:13:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
|
2013-12-14 23:02:04 +00:00
|
|
|
|
using System;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
using System.Text;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Checksums;
|
2015-11-23 21:44:58 +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;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public partial class CdrWin
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(imageFilter == null) return false;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
cdrwinFilter = imageFilter;
|
2013-12-16 01:04:17 +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
|
|
|
|
cueStream = new StreamReader(imageFilter.GetDataForkStream());
|
2018-01-01 20:05:49 +00:00
|
|
|
|
int lineNumber = 0;
|
|
|
|
|
|
bool intrack = false;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
byte currentsession = 1;
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize all RegExs
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Regex regexSession = new Regex(REGEX_SESSION);
|
|
|
|
|
|
Regex regexDiskType = new Regex(REGEX_MEDIA_TYPE);
|
|
|
|
|
|
Regex regexLeadOut = new Regex(REGEX_LEAD_OUT);
|
|
|
|
|
|
Regex regexLba = new Regex(REGEX_LBA);
|
|
|
|
|
|
Regex regexDiskId = new Regex(REGEX_DISC_ID);
|
|
|
|
|
|
Regex regexBarCode = new Regex(REGEX_BARCODE);
|
|
|
|
|
|
Regex regexComment = new Regex(REGEX_COMMENT);
|
|
|
|
|
|
Regex regexCdText = new Regex(REGEX_CDTEXT);
|
|
|
|
|
|
Regex regexMcn = new Regex(REGEX_MCN);
|
|
|
|
|
|
Regex regexTitle = new Regex(REGEX_TITLE);
|
|
|
|
|
|
Regex regexGenre = new Regex(REGEX_GENRE);
|
|
|
|
|
|
Regex regexArranger = new Regex(REGEX_ARRANGER);
|
|
|
|
|
|
Regex regexComposer = new Regex(REGEX_COMPOSER);
|
|
|
|
|
|
Regex regexPerformer = new Regex(REGEX_PERFORMER);
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Regex regexSongWriter = new Regex(REGEX_SONGWRITER);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Regex regexFile = new Regex(REGEX_FILE);
|
|
|
|
|
|
Regex regexTrack = new Regex(REGEX_TRACK);
|
|
|
|
|
|
Regex regexIsrc = new Regex(REGEX_ISRC);
|
|
|
|
|
|
Regex regexIndex = new Regex(REGEX_INDEX);
|
|
|
|
|
|
Regex regexPregap = new Regex(REGEX_PREGAP);
|
|
|
|
|
|
Regex regexPostgap = new Regex(REGEX_POSTGAP);
|
|
|
|
|
|
Regex regexFlags = new Regex(REGEX_FLAGS);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
|
|
|
|
|
// Initialize all RegEx matches
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Match matchTrack;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
|
|
|
|
|
// Initialize disc
|
2017-12-22 06:55:04 +00:00
|
|
|
|
discimage = new CdrWinDisc
|
|
|
|
|
|
{
|
|
|
|
|
|
Sessions = new List<Session>(),
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Tracks = new List<CdrWinTrack>(),
|
|
|
|
|
|
Comment = ""
|
2017-12-22 06:55:04 +00:00
|
|
|
|
};
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
CdrWinTrack currenttrack = new CdrWinTrack {Indexes = new Dictionary<int, ulong>()};
|
|
|
|
|
|
CdrWinTrackFile currentfile = new CdrWinTrackFile();
|
|
|
|
|
|
ulong currentfileoffsetsector = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
int trackCount = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
while(cueStream.Peek() >= 0)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber++;
|
|
|
|
|
|
string line = cueStream.ReadLine();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
matchTrack = regexTrack.Match(line);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(!matchTrack.Success) continue;
|
|
|
|
|
|
|
|
|
|
|
|
uint trackSeq = uint.Parse(matchTrack.Groups[1].Value);
|
|
|
|
|
|
if(trackCount + 1 != trackSeq)
|
|
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found TRACK {trackSeq} out of order in line {lineNumber}");
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
|
|
trackCount++;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(trackCount == 0) throw new FeatureUnsupportedImageException("No tracks found");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrWinTrack[] cuetracks = new CdrWinTrack[trackCount];
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber = 0;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
cueStream = new StreamReader(imageFilter.GetDataForkStream());
|
2015-05-23 05:29:35 +01:00
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
|
FiltersList filtersList = new FiltersList();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
while(cueStream.Peek() >= 0)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
lineNumber++;
|
|
|
|
|
|
string line = cueStream.ReadLine();
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Match matchSession = regexSession.Match(line);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Match matchDiskType = regexDiskType.Match(line);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Match matchComment = regexComment.Match(line);
|
|
|
|
|
|
Match matchLba = regexLba.Match(line);
|
|
|
|
|
|
Match matchLeadOut = regexLeadOut.Match(line);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(matchDiskType.Success && !intrack)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM ORIGINAL MEDIA TYPE at line {0}",
|
|
|
|
|
|
lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktypestr = matchDiskType.Groups[1].Value;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchDiskType.Success && intrack)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found REM ORIGINAL MEDIA TYPE field after a track in line {lineNumber}");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchSession.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM SESSION at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentsession = byte.Parse(matchSession.Groups[1].Value);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
|
|
|
|
|
// What happens between sessions
|
|
|
|
|
|
}
|
2017-12-24 00:12:31 +00:00
|
|
|
|
else if(matchLba.Success)
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM MSF at line {0}", lineNumber);
|
|
|
|
|
|
else if(matchLeadOut.Success)
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM LEAD-OUT at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchComment.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Comment == "") discimage.Comment = matchComment.Groups[1].Value; // First comment
|
2014-04-14 01:14:20 +00:00
|
|
|
|
else
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Comment +=
|
|
|
|
|
|
Environment.NewLine + matchComment.Groups[1].Value; // Append new comments as new lines
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
matchTrack = regexTrack.Match(line);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Match matchTitle = regexTitle.Match(line);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Match matchSongWriter = regexSongWriter.Match(line);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Match matchPregap = regexPregap.Match(line);
|
|
|
|
|
|
Match matchPostgap = regexPostgap.Match(line);
|
|
|
|
|
|
Match matchPerformer = regexPerformer.Match(line);
|
|
|
|
|
|
Match matchMcn = regexMcn.Match(line);
|
|
|
|
|
|
Match matchIsrc = regexIsrc.Match(line);
|
|
|
|
|
|
Match matchIndex = regexIndex.Match(line);
|
|
|
|
|
|
Match matchGenre = regexGenre.Match(line);
|
|
|
|
|
|
Match matchFlags = regexFlags.Match(line);
|
|
|
|
|
|
Match matchFile = regexFile.Match(line);
|
|
|
|
|
|
Match matchDiskId = regexDiskId.Match(line);
|
|
|
|
|
|
Match matchComposer = regexComposer.Match(line);
|
|
|
|
|
|
Match matchCdText = regexCdText.Match(line);
|
|
|
|
|
|
Match matchBarCode = regexBarCode.Match(line);
|
|
|
|
|
|
Match matchArranger = regexArranger.Match(line);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
|
|
|
|
|
if(matchArranger.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found ARRANGER at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(intrack) currenttrack.Arranger = matchArranger.Groups[1].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else discimage.Arranger = matchArranger.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchBarCode.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found UPC_EAN at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!intrack) discimage.Barcode = matchBarCode.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found barcode field in incorrect place at line {lineNumber}");
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchCdText.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found CDTEXTFILE at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!intrack) discimage.Cdtextfile = matchCdText.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found CD-Text file field in incorrect place at line {lineNumber}");
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchComposer.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found COMPOSER at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(intrack) currenttrack.Composer = matchComposer.Groups[1].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else discimage.Composer = matchComposer.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchDiskId.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found DISC_ID at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!intrack) discimage.DiskId = matchDiskId.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found CDDB ID field in incorrect place at line {lineNumber}");
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchFile.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found FILE at line {0}", lineNumber);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currenttrack.Sequence != 0)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2018-01-01 20:05:49 +00:00
|
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Trackfile = currentfile;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Sectors =
|
2017-12-20 17:15:26 +00:00
|
|
|
|
((ulong)currentfile.Datafilter.GetLength() - currentfile.Offset) /
|
|
|
|
|
|
CdrWinTrackTypeToBytesPerSector(currenttrack.Tracktype);
|
|
|
|
|
|
cuetracks[currenttrack.Sequence - 1] = currenttrack;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
intrack = false;
|
|
|
|
|
|
currenttrack = new CdrWinTrack();
|
|
|
|
|
|
currentfile = new CdrWinTrackFile();
|
|
|
|
|
|
filtersList = new FiltersList();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
//currentfile = new CDRWinTrackFile();
|
2018-06-22 08:08:38 +01:00
|
|
|
|
string datafile = matchFile.Groups[1].Value;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Filetype = matchFile.Groups[2].Value;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
// Check if file path is quoted
|
2018-01-01 20:05:49 +00:00
|
|
|
|
if(datafile[0] == '"' && datafile[datafile.Length - 1] == '"')
|
2017-12-24 00:12:31 +00:00
|
|
|
|
datafile = datafile.Substring(1, datafile.Length - 2); // Unquote it
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter = filtersList.GetFilter(datafile);
|
2016-09-05 17:37:31 +01:00
|
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
|
// Check if file exists
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(datafile[0] == '/' || datafile[0] == '/' && datafile[1] == '.') // UNIX absolute path
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Regex unixpath = new Regex("^(.+)/([^/]+)$");
|
2016-09-05 17:37:31 +01:00
|
|
|
|
Match unixpathmatch = unixpath.Match(datafile);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(unixpathmatch.Success)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter = filtersList.GetFilter(unixpathmatch.Groups[1].Value);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
string path = imageFilter.GetParentFolder() + Path.PathSeparator +
|
|
|
|
|
|
unixpathmatch.Groups[1].Value;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter = filtersList.GetFilter(path);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found.");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found.");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else if(datafile[1] == ':' && datafile[2] == '\\' ||
|
2017-12-20 17:26:28 +00:00
|
|
|
|
datafile[0] == '\\' && datafile[1] == '\\' ||
|
2018-01-01 20:05:49 +00:00
|
|
|
|
datafile[0] == '.' && datafile[1] == '\\') // Windows absolute path
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Regex winpath =
|
|
|
|
|
|
new
|
|
|
|
|
|
Regex("^(?:[a-zA-Z]\\:(\\\\|\\/)|file\\:\\/\\/|\\\\\\\\|\\.(\\/|\\\\))([^\\\\\\/\\:\\*\\?\\<\\>\\\"\\|]+(\\\\|\\/){0,1})+$");
|
2016-09-05 17:37:31 +01:00
|
|
|
|
Match winpathmatch = winpath.Match(datafile);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(winpathmatch.Success)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter = filtersList.GetFilter(winpathmatch.Groups[1].Value);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
string path = imageFilter.GetParentFolder() + Path.PathSeparator +
|
|
|
|
|
|
winpathmatch.Groups[1].Value;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter = filtersList.GetFilter(path);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found.");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found.");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
string path = imageFilter.GetParentFolder() + Path.PathSeparator + datafile;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter = filtersList.GetFilter(path);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found.");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// File does exist, process it
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "File \"{0}\" found",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Datafilter.GetFilename());
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
switch(currentfile.Filetype)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_DISK_TYPE_LITTLE_ENDIAN: break;
|
|
|
|
|
|
case CDRWIN_DISK_TYPE_BIG_ENDIAN:
|
|
|
|
|
|
case CDRWIN_DISK_TYPE_AIFF:
|
|
|
|
|
|
case CDRWIN_DISK_TYPE_RIFF:
|
|
|
|
|
|
case CDRWIN_DISK_TYPE_MP3:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureSupportedButNotImplementedImageException($"Unsupported file type {currentfile.Filetype}");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
default:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw new
|
|
|
|
|
|
FeatureUnsupportedImageException($"Unknown file type {currentfile.Filetype}");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
currentfile.Offset = 0;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currentfile.Sequence = 0;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchFlags.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found FLAGS at line {0}", lineNumber);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(!intrack)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found FLAGS field in incorrect place at line {lineNumber}");
|
2015-12-23 23:46:31 +00:00
|
|
|
|
|
2018-01-01 22:19:31 +00:00
|
|
|
|
currenttrack.FlagDcp |= matchFlags.Groups["dcp"].Value == "DCP";
|
|
|
|
|
|
currenttrack.Flag4ch |= matchFlags.Groups["quad"].Value == "4CH";
|
|
|
|
|
|
currenttrack.FlagPre |= matchFlags.Groups["pre"].Value == "PRE";
|
|
|
|
|
|
currenttrack.FlagScms |= matchFlags.Groups["scms"].Value == "SCMS";
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchGenre.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found GENRE at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(intrack) currenttrack.Genre = matchGenre.Groups[1].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else discimage.Genre = matchGenre.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchIndex.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found INDEX at line {0}", lineNumber);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(!intrack)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException($"Found INDEX before a track {lineNumber}");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
int index = int.Parse(matchIndex.Groups[1].Value);
|
2017-12-21 02:57:32 +00:00
|
|
|
|
ulong offset = CdrWinMsftoLba(matchIndex.Groups[2].Value);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-21 02:57:32 +00:00
|
|
|
|
if(index != 0 && index != 1 && currenttrack.Indexes.Count == 0)
|
|
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found INDEX {index} before INDEX 00 or INDEX 01");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(index == 0 || index == 1 && !currenttrack.Indexes.ContainsKey(0))
|
2017-12-21 02:57:32 +00:00
|
|
|
|
if((int)(currenttrack.Sequence - 2) >= 0 && offset > 1)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-21 02:57:32 +00:00
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Sectors = offset - currentfileoffsetsector;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currentfile.Offset +=
|
2017-12-21 02:57:32 +00:00
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Sectors *
|
|
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Bps;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Sets currentfile.offset to {0}",
|
2017-12-21 02:57:32 +00:00
|
|
|
|
currentfile.Offset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin",
|
|
|
|
|
|
"cuetracks[currenttrack.sequence-2].sectors = {0}",
|
|
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Sectors);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin",
|
2017-12-21 02:57:32 +00:00
|
|
|
|
"cuetracks[currenttrack.sequence-2].bps = {0}",
|
|
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Bps);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if((index == 0 || index == 1 && !currenttrack.Indexes.ContainsKey(0)) &&
|
2017-12-21 02:57:32 +00:00
|
|
|
|
currenttrack.Sequence == 1)
|
|
|
|
|
|
{
|
2018-02-22 17:39:15 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Sets currentfile.offset to {0}",
|
2017-12-21 02:57:32 +00:00
|
|
|
|
offset * currenttrack.Bps);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currentfile.Offset = offset * currenttrack.Bps;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-21 02:57:32 +00:00
|
|
|
|
|
|
|
|
|
|
currentfileoffsetsector = offset;
|
|
|
|
|
|
currenttrack.Indexes.Add(index, offset);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchIsrc.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found ISRC at line {0}", lineNumber);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(!intrack)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException($"Found ISRC before a track {lineNumber}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Isrc = matchIsrc.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchMcn.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found CATALOG at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!intrack) discimage.Mcn = matchMcn.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found CATALOG field in incorrect place at line {lineNumber}");
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchPerformer.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found PERFORMER at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(intrack) currenttrack.Performer = matchPerformer.Groups[1].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else discimage.Performer = matchPerformer.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchPostgap.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found POSTGAP at line {0}", lineNumber);
|
2017-12-20 23:07:46 +00:00
|
|
|
|
if(intrack) currenttrack.Postgap = CdrWinMsftoLba(matchPostgap.Groups[1].Value);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found POSTGAP field before a track at line {lineNumber}");
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchPregap.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found PREGAP at line {0}", lineNumber);
|
2017-12-20 23:07:46 +00:00
|
|
|
|
if(intrack) currenttrack.Pregap = CdrWinMsftoLba(matchPregap.Groups[1].Value);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found PREGAP field before a track at line {lineNumber}");
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchSongWriter.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found SONGWRITER at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(intrack) currenttrack.Songwriter = matchSongWriter.Groups[1].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else discimage.Songwriter = matchSongWriter.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchTitle.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found TITLE at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(intrack) currenttrack.Title = matchTitle.Groups[1].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else discimage.Title = matchTitle.Groups[1].Value;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(matchTrack.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found TRACK at line {0}", lineNumber);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currentfile.Datafilter == null)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found TRACK field before a file is defined at line {lineNumber}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(intrack)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
if(currenttrack.Indexes.ContainsKey(0) && currenttrack.Pregap == 0)
|
|
|
|
|
|
currenttrack.Indexes.TryGetValue(0, out currenttrack.Pregap);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
|
|
|
|
|
currenttrack.Trackfile = currentfile;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cuetracks[currenttrack.Sequence - 1] = currenttrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2018-01-01 20:05:49 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
currenttrack = new CdrWinTrack
|
|
|
|
|
|
{
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Indexes = new Dictionary<int, ulong>(),
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Sequence = uint.Parse(matchTrack.Groups[1].Value)
|
|
|
|
|
|
};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Setting currenttrack.sequence to {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Sequence);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
|
|
|
|
|
currenttrack.Bps = CdrWinTrackTypeToBytesPerSector(matchTrack.Groups[2].Value);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Tracktype = matchTrack.Groups[2].Value;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
currenttrack.Session = currentsession;
|
|
|
|
|
|
intrack = true;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2017-12-22 06:55:04 +00:00
|
|
|
|
else if(line == "") // Empty line, ignore it
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{ }
|
2014-04-14 01:14:20 +00:00
|
|
|
|
else // Non-empty unknown field
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new
|
2017-12-22 06:55:04 +00:00
|
|
|
|
FeatureUnsupportedImageException($"Found unknown field defined at line {lineNumber}: \"{line}\"");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(currenttrack.Sequence != 0)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2018-01-01 20:05:49 +00:00
|
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
currenttrack.Trackfile = currentfile;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
currenttrack.Sectors = ((ulong)currentfile.Datafilter.GetLength() - currentfile.Offset) /
|
|
|
|
|
|
CdrWinTrackTypeToBytesPerSector(currenttrack.Tracktype);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cuetracks[currenttrack.Sequence - 1] = currenttrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Session[] sessions = new Session[currentsession];
|
|
|
|
|
|
for(int s = 1; s <= sessions.Length; s++)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sessions[s - 1].SessionSequence = 1;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(s > 1) sessions[s - 1].StartSector = sessions[s - 2].EndSector + 1;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else sessions[s - 1].StartSector = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
ulong sessionSectors = 0;
|
|
|
|
|
|
int lastSessionTrack = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
for(int i = 0; i < cuetracks.Length; i++)
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(cuetracks[i].Session == s)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sessionSectors += cuetracks[i].Sectors;
|
|
|
|
|
|
if(i > lastSessionTrack) lastSessionTrack = i;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sessions[s - 1].EndTrack = cuetracks[lastSessionTrack].Sequence;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sessions[s - 1].EndSector = sessionSectors - 1;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int s = 1; s <= sessions.Length; s++) discimage.Sessions.Add(sessions[s - 1]);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int t = 1; t <= cuetracks.Length; t++) discimage.Tracks.Add(cuetracks[t - 1]);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Disktype = CdrWinIsoBusterDiscTypeToMediaType(discimage.Disktypestr);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Disktype == MediaType.Unknown || discimage.Disktype == MediaType.CD)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2018-01-01 20:05:49 +00:00
|
|
|
|
bool data = false;
|
|
|
|
|
|
bool cdg = false;
|
|
|
|
|
|
bool cdi = false;
|
|
|
|
|
|
bool mode2 = false;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
bool firstaudio = false;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
bool firstdata = false;
|
|
|
|
|
|
bool audio = false;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < discimage.Tracks.Count; i++)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
// First track is audio
|
2017-12-20 17:15:26 +00:00
|
|
|
|
firstaudio |= i == 0 && discimage.Tracks[i].Tracktype == CDRWIN_TRACK_TYPE_AUDIO;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
// First track is data
|
2017-12-20 17:15:26 +00:00
|
|
|
|
firstdata |= i == 0 && discimage.Tracks[i].Tracktype != CDRWIN_TRACK_TYPE_AUDIO;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
// Any non first track is data
|
2017-12-20 17:15:26 +00:00
|
|
|
|
data |= i != 0 && discimage.Tracks[i].Tracktype != CDRWIN_TRACK_TYPE_AUDIO;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
// Any non first track is audio
|
2017-12-20 17:15:26 +00:00
|
|
|
|
audio |= i != 0 && discimage.Tracks[i].Tracktype == CDRWIN_TRACK_TYPE_AUDIO;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
switch(discimage.Tracks[i].Tracktype)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
cdg = true;
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
cdi = true;
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM1:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM2:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_RAW:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
mode2 = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!data && !firstdata) discimage.Disktype = MediaType.CDDA;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else if(cdg) discimage.Disktype = MediaType.CDG;
|
|
|
|
|
|
else if(cdi) discimage.Disktype = MediaType.CDI;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else if(firstaudio && data && discimage.Sessions.Count > 1 && mode2)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
discimage.Disktype = MediaType.CDPLUS;
|
|
|
|
|
|
else if(firstdata && audio || mode2) discimage.Disktype = MediaType.CDROMXA;
|
|
|
|
|
|
else if(!audio) discimage.Disktype = MediaType.CDROM;
|
|
|
|
|
|
else discimage.Disktype = MediaType.CD;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
// DEBUG information
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Disc image parsing results");
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Disc CD-TEXT:");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Arranger == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tArranger is not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tArranger: {0}",
|
|
|
|
|
|
discimage.Arranger);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Composer == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tComposer is not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tComposer: {0}",
|
|
|
|
|
|
discimage.Composer);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Genre == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tGenre is not set.");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tGenre: {0}", discimage.Genre);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Performer == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tPerformer is not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPerformer: {0}",
|
|
|
|
|
|
discimage.Performer);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Songwriter == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tSongwriter is not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tSongwriter: {0}",
|
|
|
|
|
|
discimage.Songwriter);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Title == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tTitle is not set.");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tTitle: {0}", discimage.Title);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Cdtextfile == null)
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tCD-TEXT binary file not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tCD-TEXT binary file: {0}", discimage.Cdtextfile);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Disc information:");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Disktypestr == null)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tISOBuster disc type not set.");
|
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tISOBuster disc type: {0}", discimage.Disktypestr);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tGuessed disk type: {0}", discimage.Disktype);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Barcode == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tBarcode not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tBarcode: {0}",
|
|
|
|
|
|
discimage.Barcode);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.DiskId == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc ID not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc ID: {0}",
|
|
|
|
|
|
discimage.DiskId);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(discimage.Mcn == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tMCN not set.");
|
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tMCN: {0}", discimage.Mcn);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Comment == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tComment not set.");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tComment: \"{0}\"",
|
|
|
|
|
|
discimage.Comment);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Session information:");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc contains {0} sessions", discimage.Sessions.Count);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < discimage.Sessions.Count; i++)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tSession {0} information:", i + 1);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tStarting track: {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Sessions[i].StartTrack);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tStarting sector: {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Sessions[i].StartSector);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tEnding track: {0}", discimage.Sessions[i].EndTrack);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tEnding sector: {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Sessions[i].EndSector);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Track information:");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc contains {0} tracks", discimage.Tracks.Count);
|
|
|
|
|
|
for(int i = 0; i < discimage.Tracks.Count; i++)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tTrack {0} information:",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
discimage.Tracks[i].Sequence);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\t{0} bytes per sector", discimage.Tracks[i].Bps);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tPregap: {0} sectors", discimage.Tracks[i].Pregap);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tData: {0} sectors", discimage.Tracks[i].Sectors);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tPostgap: {0} sectors", discimage.Tracks[i].Postgap);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Flag4ch)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tTrack is flagged as quadraphonic");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].FlagDcp)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tTrack allows digital copy");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].FlagPre)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tTrack has pre-emphasis applied");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].FlagScms) DicConsole.DebugWriteLine("CDRWin plugin", "\t\tTrack has SCMS");
|
2015-10-18 22:04:03 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin 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-10-18 22:04:03 +01:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin 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("CDRWin plugin", "\t\t\tIndex {0} starts at sector {1}", kvp.Key,
|
|
|
|
|
|
kvp.Value);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Isrc == null)
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tISRC is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\t\tISRC: {0}", discimage.Tracks[i].Isrc);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Arranger == null)
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tArranger is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\t\tArranger: {0}", discimage.Tracks[i].Arranger);
|
|
|
|
|
|
if(discimage.Tracks[i].Composer == null)
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tComposer is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\t\tComposer: {0}", discimage.Tracks[i].Composer);
|
|
|
|
|
|
if(discimage.Tracks[i].Genre == null)
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tGenre is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\t\tGenre: {0}", discimage.Tracks[i].Genre);
|
|
|
|
|
|
if(discimage.Tracks[i].Performer == null)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tPerformer is not set.");
|
2014-04-14 01:31:32 +00:00
|
|
|
|
else
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tPerformer: {0}", discimage.Tracks[i].Performer);
|
|
|
|
|
|
if(discimage.Tracks[i].Songwriter == null)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tSongwriter is not set.");
|
2014-04-14 01:31:32 +00:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin 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 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tTitle is not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\t\tTitle: {0}", discimage.Tracks[i].Title);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Building offset map");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Partitions = new List<Partition>();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
ulong byteOffset = 0;
|
|
|
|
|
|
ulong sectorOffset = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
ulong partitionSequence = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
ulong indexZeroOffset = 0;
|
|
|
|
|
|
ulong indexOneOffset = 0;
|
|
|
|
|
|
bool indexZero = false;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
offsetmap = new Dictionary<uint, ulong>();
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < discimage.Tracks.Count; i++)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
ulong index0Len = 0;
|
2015-11-09 19:42:00 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Tracks[i].Sequence == 1 && i != 0)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
throw new ImageNotSupportedException("Unordered tracks");
|
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
Partition partition = new Partition();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-08-08 18:44:08 +01:00
|
|
|
|
/*if(discimage.tracks[i].pregap > 0)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
|
partition.PartitionDescription = string.Format("Track {0} pregap.", discimage.tracks[i].sequence);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
partition.PartitionName = discimage.tracks[i].title;
|
|
|
|
|
|
partition.PartitionStartSector = sector_offset;
|
|
|
|
|
|
partition.PartitionLength = discimage.tracks[i].pregap * discimage.tracks[i].bps;
|
|
|
|
|
|
partition.PartitionSectors = discimage.tracks[i].pregap;
|
|
|
|
|
|
partition.PartitionSequence = partitionSequence;
|
|
|
|
|
|
partition.PartitionStart = byte_offset;
|
|
|
|
|
|
partition.PartitionType = discimage.tracks[i].tracktype;
|
|
|
|
|
|
|
|
|
|
|
|
sector_offset += partition.PartitionSectors;
|
|
|
|
|
|
byte_offset += partition.PartitionLength;
|
|
|
|
|
|
partitionSequence++;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(!offsetmap.ContainsKey(discimage.tracks[i].sequence))
|
2014-04-14 01:14:20 +00:00
|
|
|
|
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong old_start;
|
|
|
|
|
|
offsetmap.TryGetValue(discimage.tracks[i].sequence, out old_start);
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(partition.PartitionStartSector < old_start)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
offsetmap.Remove(discimage.tracks[i].sequence);
|
|
|
|
|
|
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
partitions.Add(partition);
|
2016-07-28 22:25:26 +01:00
|
|
|
|
partition = new Partition();
|
2016-08-08 18:44:08 +01:00
|
|
|
|
}*/
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
indexZero |= discimage.Tracks[i].Indexes.TryGetValue(0, out indexZeroOffset);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!discimage.Tracks[i].Indexes.TryGetValue(1, out indexOneOffset))
|
2017-12-21 17:58:51 +00:00
|
|
|
|
throw new ImageNotSupportedException($"Track {discimage.Tracks[i].Sequence} lacks index 01");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-08-08 18:44:08 +01:00
|
|
|
|
/*if(index_zero && index_one_offset > index_zero_offset)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
|
partition.PartitionDescription = string.Format("Track {0} index 00.", discimage.tracks[i].sequence);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
partition.PartitionName = discimage.tracks[i].title;
|
|
|
|
|
|
partition.PartitionStartSector = sector_offset;
|
|
|
|
|
|
partition.PartitionLength = (index_one_offset - index_zero_offset) * discimage.tracks[i].bps;
|
|
|
|
|
|
partition.PartitionSectors = index_one_offset - index_zero_offset;
|
|
|
|
|
|
partition.PartitionSequence = partitionSequence;
|
|
|
|
|
|
partition.PartitionStart = byte_offset;
|
|
|
|
|
|
partition.PartitionType = discimage.tracks[i].tracktype;
|
|
|
|
|
|
|
|
|
|
|
|
sector_offset += partition.PartitionSectors;
|
|
|
|
|
|
byte_offset += partition.PartitionLength;
|
2015-11-09 19:42:00 +00:00
|
|
|
|
index0_len = partition.PartitionSectors;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
partitionSequence++;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(!offsetmap.ContainsKey(discimage.tracks[i].sequence))
|
2014-04-14 01:14:20 +00:00
|
|
|
|
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong old_start;
|
|
|
|
|
|
offsetmap.TryGetValue(discimage.tracks[i].sequence, out old_start);
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(partition.PartitionStartSector < old_start)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
offsetmap.Remove(discimage.tracks[i].sequence);
|
|
|
|
|
|
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partitions.Add(partition);
|
2016-07-28 22:25:26 +01:00
|
|
|
|
partition = new Partition();
|
2016-08-08 18:44:08 +01:00
|
|
|
|
}*/
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
// Index 01
|
2017-12-21 17:58:51 +00:00
|
|
|
|
partition.Description = $"Track {discimage.Tracks[i].Sequence}.";
|
2018-01-01 20:05:49 +00:00
|
|
|
|
partition.Name = discimage.Tracks[i].Title;
|
|
|
|
|
|
partition.Start = sectorOffset;
|
|
|
|
|
|
partition.Size = (discimage.Tracks[i].Sectors - index0Len) * discimage.Tracks[i].Bps;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
partition.Length = discimage.Tracks[i].Sectors - index0Len;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
partition.Sequence = partitionSequence;
|
|
|
|
|
|
partition.Offset = byteOffset;
|
|
|
|
|
|
partition.Type = discimage.Tracks[i].Tracktype;
|
2017-07-19 16:37:11 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset += partition.Length;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
byteOffset += partition.Size;
|
2014-04-14 01:14:20 +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);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
offsetmap.TryGetValue(discimage.Tracks[i].Sequence, out ulong oldStart);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(partition.Start < oldStart)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
offsetmap.Remove(discimage.Tracks[i].Sequence);
|
|
|
|
|
|
offsetmap.Add(discimage.Tracks[i].Sequence, partition.Start);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Partitions.Add(partition);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-14 01:31:32 +00:00
|
|
|
|
// Print offset map
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "printing partition map");
|
2018-01-01 20:05:49 +00:00
|
|
|
|
foreach(Partition partition in Partitions)
|
2014-04-14 01:31:32 +00:00
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Partition sequence: {0}", partition.Sequence);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition name: {0}", partition.Name);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition description: {0}",
|
|
|
|
|
|
partition.Description);
|
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition type: {0}", partition.Type);
|
2017-07-19 16:37:11 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition starting sector: {0}", partition.Start);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition sectors: {0}", partition.Length);
|
2017-07-19 16:37:11 +01:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition starting offset: {0}", partition.Offset);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition size in bytes: {0}", partition.Size);
|
2014-04-14 01:31:32 +00:00
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
foreach(CdrWinTrack track in discimage.Tracks) imageInfo.ImageSize += track.Bps * track.Sectors;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
foreach(CdrWinTrack track in discimage.Tracks) imageInfo.Sectors += track.Sectors;
|
2014-08-24 17:46:29 +01:00
|
|
|
|
|
2018-01-03 17:34:51 +00:00
|
|
|
|
if(discimage.Disktype != MediaType.CDROMXA && discimage.Disktype != MediaType.CDDA &&
|
|
|
|
|
|
discimage.Disktype != MediaType.CDI && discimage.Disktype != MediaType.CDPLUS &&
|
|
|
|
|
|
discimage.Disktype != MediaType.CDG && discimage.Disktype != MediaType.CDEG &&
|
|
|
|
|
|
discimage.Disktype != MediaType.CDMIDI) imageInfo.SectorSize = 2048; // Only data tracks
|
|
|
|
|
|
else imageInfo.SectorSize = 2352; // All others
|
2014-08-24 17:46:29 +01:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
if(discimage.Mcn != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_MCN);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(discimage.Cdtextfile != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_TEXT);
|
2014-08-24 17:46:29 +01:00
|
|
|
|
|
|
|
|
|
|
// Detect ISOBuster extensions
|
2018-01-01 20:05:49 +00:00
|
|
|
|
if(discimage.Disktypestr != null || discimage.Comment.ToLower().Contains("isobuster") ||
|
2017-12-26 06:05:12 +00:00
|
|
|
|
discimage.Sessions.Count > 1) imageInfo.Application = "ISOBuster";
|
2018-01-01 20:05:49 +00:00
|
|
|
|
else imageInfo.Application = "CDRWin";
|
2014-08-24 17:46:29 +01:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
2014-08-24 17:46:29 +01:00
|
|
|
|
|
2018-01-01 20:05:49 +00:00
|
|
|
|
imageInfo.Comments = discimage.Comment;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.MediaSerialNumber = discimage.Mcn;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
imageInfo.MediaBarcode = discimage.Barcode;
|
|
|
|
|
|
imageInfo.MediaType = discimage.Disktype;
|
2014-08-24 17:46:29 +01: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(CdrWinTrack track in discimage.Tracks)
|
|
|
|
|
|
switch(track.Tracktype)
|
2014-08-24 17:46:29 +01:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_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 CDRWIN_TRACK_TYPE_CDG:
|
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);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
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 CDRWIN_TRACK_TYPE_MODE2_RAW:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_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 CDRWIN_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;
|
|
|
|
|
|
}
|
2014-08-24 17:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2015-12-05 17:21:47 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
DicConsole.VerboseWriteLine("CDRWIN image describes a disc of type {0}", imageInfo.MediaType);
|
|
|
|
|
|
if(!string.IsNullOrEmpty(imageInfo.Comments))
|
|
|
|
|
|
DicConsole.VerboseWriteLine("CDRWIN comments: {0}", imageInfo.Comments);
|
2016-08-21 17:35:35 +01:00
|
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return true;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
catch(Exception ex)
|
2013-12-16 01:04:17 +00:00
|
|
|
|
{
|
2016-09-05 21:22:04 +01:00
|
|
|
|
DicConsole.ErrorWriteLine("Exception trying to identify image file {0}", imageFilter.GetFilename());
|
2018-01-01 20:05:49 +00:00
|
|
|
|
DicConsole.ErrorWriteLine("Exception: {0}", ex.Message);
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Stack trace: {0}", ex.StackTrace);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(tag)
|
2014-04-14 01:14:20 +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.");
|
|
|
|
|
|
}
|
2016-01-16 03:54:55 +00:00
|
|
|
|
case MediaTagType.CD_TEXT:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(discimage.Cdtextfile != null)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
// TODO: Check that binary text file exists, open it, read it, send it to caller.
|
|
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
|
|
|
|
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain CD-TEXT information.");
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
default:
|
|
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, tag);
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return ReadSectors(sectorAddress, 1, track);
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, track, tag);
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2013-12-14 23:02:04 +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 cdrwinTrack in discimage.Tracks
|
2018-01-01 20:05:49 +00:00
|
|
|
|
where cdrwinTrack.Sequence == kvp.Key
|
2017-12-24 00:12:31 +00:00
|
|
|
|
where sectorAddress - kvp.Value < cdrwinTrack.Sectors
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2013-12-14 23:02:04 +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 cdrwinTrack in discimage.Tracks
|
2018-01-01 20:05:49 +00:00
|
|
|
|
where cdrwinTrack.Sequence == kvp.Key
|
2017-12-24 00:12:31 +00:00
|
|
|
|
where sectorAddress - kvp.Value < cdrwinTrack.Sectors
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrWinTrack dicTrack = new CdrWinTrack {Sequence = 0};
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks.Where(cdrwinTrack => cdrwinTrack.Sequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = cdrwinTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +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");
|
2014-04-14 01:14:20 +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");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.Tracktype)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE1:
|
|
|
|
|
|
case CDRWIN_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 20:05:49 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_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 20:05:49 +00:00
|
|
|
|
sectorSize = 2324;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_AUDIO:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_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 20:05:49 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 288;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_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 20:05:49 +00:00
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 16;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 96;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2014-04-14 01:14:20 +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++)
|
2014-04-14 01:14:20 +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);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrWinTrack dicTrack = new CdrWinTrack {Sequence = 0};
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks.Where(cdrwinTrack => cdrwinTrack.Sequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = cdrwinTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +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");
|
2014-04-14 01:14:20 +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");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(tag)
|
2014-04-14 01:14:20 +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;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.Tracktype != CDRWIN_TRACK_TYPE_AUDIO && dicTrack.Tracktype != CDRWIN_TRACK_TYPE_CDG)
|
2018-01-01 21:32:12 +00:00
|
|
|
|
flags |= CdFlags.DataTrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.FlagDcp) flags |= CdFlags.CopyPermitted;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.FlagPre) flags |= CdFlags.PreEmphasis;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-01-01 21:32:12 +00:00
|
|
|
|
if(dicTrack.Flag4ch) 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-01 22:19:31 +00:00
|
|
|
|
case SectorTagType.CdTrackIsrc:
|
|
|
|
|
|
if(dicTrack.Isrc == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
return Encoding.UTF8.GetBytes(dicTrack.Isrc);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdTrackText:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.Tracktype)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE1:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM1:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM2:
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentException("No tags in image for requested track", nameof(tag));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch(tag)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSync:
|
|
|
|
|
|
case SectorTagType.CdSectorHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
|
|
|
|
|
case SectorTagType.CdSectorEcc:
|
|
|
|
|
|
case SectorTagType.CdSectorEccP:
|
|
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
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.CdSectorSubHeader:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 8;
|
|
|
|
|
|
sectorSkip = 2328;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
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 = 2332;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_AUDIO:
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentException("There are no tags on audio tracks", nameof(tag));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE1_RAW:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch(tag)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSync:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 12;
|
|
|
|
|
|
sectorSkip = 2340;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2014-04-14 01:14:20 +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 20:05:49 +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:
|
|
|
|
|
|
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 20:05:49 +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 20:05:49 +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 20:05:49 +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 20:05:49 +00:00
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 284;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_RAW: // Requires reading sector
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW:
|
2014-04-14 01:14:20 +00:00
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2352;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2014-04-14 01:14:20 +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++)
|
2014-04-14 01:14:20 +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);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return ReadSectorsLong(sectorAddress, 1);
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
return ReadSectorsLong(sectorAddress, 1, track);
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2013-12-14 23:02:04 +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 cdrwinTrack in discimage.Tracks
|
2018-01-01 20:05:49 +00:00
|
|
|
|
where cdrwinTrack.Sequence == kvp.Key
|
2017-12-24 00:12:31 +00:00
|
|
|
|
where sectorAddress - kvp.Value < cdrwinTrack.Sectors
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
CdrWinTrack dicTrack = new CdrWinTrack {Sequence = 0};
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks.Where(cdrwinTrack => cdrwinTrack.Sequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = cdrwinTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +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");
|
2014-04-14 01:14:20 +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");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.Tracktype)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE1:
|
|
|
|
|
|
case CDRWIN_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 20:05:49 +00:00
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_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 20:05:49 +00:00
|
|
|
|
sectorSize = 2324;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE1_RAW:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_RAW:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW:
|
|
|
|
|
|
case CDRWIN_TRACK_TYPE_AUDIO:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
2018-01-03 17:34:51 +00:00
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 96;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
imageStream = dicTrack.Trackfile.Datafilter.GetDataForkStream();
|
2014-04-14 02:29:13 +00:00
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
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);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) buffer = br.ReadBytes((int)(sectorSize * length));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
else
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(int i = 0; i < length; i++)
|
2014-04-14 01:14:20 +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);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
|
if(discimage.Sessions.Contains(session)) return GetSessionTracks(session.SessionSequence);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
throw new ImageNotSupportedException("Session does not exist in disc image");
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2013-12-14 23:02:04 +00:00
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
|
List<Track> tracks = new List<Track>();
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
foreach(CdrWinTrack cdrTrack in discimage.Tracks)
|
|
|
|
|
|
if(cdrTrack.Session == session)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Track dicTrack = new Track
|
|
|
|
|
|
{
|
2018-01-01 20:05:49 +00:00
|
|
|
|
Indexes = cdrTrack.Indexes,
|
|
|
|
|
|
TrackDescription = cdrTrack.Title,
|
|
|
|
|
|
TrackPregap = cdrTrack.Pregap,
|
|
|
|
|
|
TrackSession = cdrTrack.Session,
|
|
|
|
|
|
TrackSequence = cdrTrack.Sequence,
|
|
|
|
|
|
TrackType = CdrWinTrackTypeToTrackType(cdrTrack.Tracktype),
|
|
|
|
|
|
TrackFile = cdrTrack.Trackfile.Datafilter.GetFilename(),
|
|
|
|
|
|
TrackFilter = cdrTrack.Trackfile.Datafilter,
|
|
|
|
|
|
TrackFileOffset = cdrTrack.Trackfile.Offset,
|
|
|
|
|
|
TrackFileType = cdrTrack.Trackfile.Filetype,
|
2017-12-22 06:55:04 +00:00
|
|
|
|
TrackRawBytesPerSector = cdrTrack.Bps,
|
2018-01-01 20:05:49 +00:00
|
|
|
|
TrackBytesPerSector = CdrWinTrackTypeToCookedBytesPerSector(cdrTrack.Tracktype)
|
2017-12-22 06:55:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(!cdrTrack.Indexes.TryGetValue(0, out dicTrack.TrackStartSector))
|
|
|
|
|
|
cdrTrack.Indexes.TryGetValue(1, out dicTrack.TrackStartSector);
|
|
|
|
|
|
dicTrack.TrackEndSector = dicTrack.TrackStartSector + cdrTrack.Sectors - 1;
|
2018-01-03 17:34:51 +00:00
|
|
|
|
if(cdrTrack.Tracktype == CDRWIN_TRACK_TYPE_CDG)
|
2015-12-06 05:09:31 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack.TrackSubchannelFilter = cdrTrack.Trackfile.Datafilter;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
dicTrack.TrackSubchannelFile = cdrTrack.Trackfile.Datafilter.GetFilename();
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack.TrackSubchannelOffset = cdrTrack.Trackfile.Offset;
|
2018-01-01 20:05:49 +00:00
|
|
|
|
dicTrack.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
2015-12-06 05:09:31 +00:00
|
|
|
|
}
|
2017-12-22 06:55:04 +00:00
|
|
|
|
else dicTrack.TrackSubchannelType = TrackSubchannelType.None;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
tracks.Add(dicTrack);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tracks;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress, track);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
|
|
|
|
|
out List<ulong> unknownLbas)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
int bps = (int)(buffer.Length / length);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
byte[] sector = new byte[bps];
|
2018-06-22 08:08:38 +01:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(int i = 0; i < length; i++)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(sectorStatus)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2014-08-25 05:00:25 +01: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-24 00:12:31 +00:00
|
|
|
|
return failingLbas.Count <= 0;
|
2014-08-25 05:00:25 +01: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)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
2018-01-01 20:05:49 +00:00
|
|
|
|
int bps = (int)(buffer.Length / length);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
byte[] sector = new byte[bps];
|
2018-06-22 08:08:38 +01:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(int i = 0; i < length; i++)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
switch(sectorStatus)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2014-08-25 05:00:25 +01: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-24 00:12:31 +00:00
|
|
|
|
return failingLbas.Count <= 0;
|
2014-08-25 05:00:25 +01:00
|
|
|
|
}
|
2013-12-14 23:02:04 +00:00
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
}
|