2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : CDRWin.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Disc image plugins.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Manages CDRWin cuesheets (cue/bin).
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 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;
|
|
|
|
|
using System.Text;
|
2013-12-16 01:04:17 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2015-11-23 21:44:58 +00:00
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Console;
|
2016-09-05 17:37:31 +01:00
|
|
|
using DiscImageChef.Filters;
|
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
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
// TODO: Implement track flags
|
2017-12-20 17:15:26 +00:00
|
|
|
public class CdrWin : ImagePlugin
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
#region Internal structures
|
2017-12-20 17:15:26 +00:00
|
|
|
struct CdrWinTrackFile
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track #</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public uint Sequence;
|
2016-09-05 17:37:31 +01:00
|
|
|
/// <summary>Filter of file containing track</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public Filter Datafilter;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Offset of track start in file</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public ulong Offset;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Type of file</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Filetype;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
struct CdrWinTrack
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track #</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public uint Sequence;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track title (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Title;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track genre (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Genre;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track arranger (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Arranger;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track composer (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Composer;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track performer (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Performer;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track song writer (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Songwriter;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track ISRC</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Isrc;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>File struct for this track</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public CdrWinTrackFile Trackfile;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Indexes on this track</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public Dictionary<int, ulong> Indexes;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track pre-gap in sectors</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public ulong Pregap;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track post-gap in sectors</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public ulong Postgap;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Digical Copy Permitted</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public bool FlagDcp;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track is quadraphonic</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public bool Flag4ch;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track has preemphasis</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public bool FlagPre;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track has SCMS</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public bool FlagScms;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Bytes per sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public ushort Bps;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Sectors in track</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public ulong Sectors;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track type</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Tracktype;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Track session</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public ushort Session;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
struct CdrWinDisc
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk title (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Title;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk genre (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Genre;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk arranger (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Arranger;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk composer (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Composer;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk performer (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Performer;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk song writer (from CD-Text)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Songwriter;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Media catalog number</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Mcn;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk type</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public MediaType Disktype;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk type string</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Disktypestr;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk CDDB ID</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string DiskId;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk UPC/EAN</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Barcode;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Sessions</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public List<Session> Sessions;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Tracks</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public List<CdrWinTrack> Tracks;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Disk comment</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Comment;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>File containing CD-Text</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
public string Cdtextfile;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Internal consts
|
|
|
|
|
// Type for FILE entity
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Data as-is in little-endian</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_LITTLE_ENDIAN = "BINARY";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Data as-is in big-endian</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_BIG_ENDIAN = "MOTOROLA";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Audio in Apple AIF file</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_AIFF = "AIFF";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Audio in Microsoft WAV file</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_RIFF = "WAVE";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Audio in MP3 file</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_MP3 = "MP3";
|
2015-12-06 07:37:20 +00:00
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
// Type for TRACK entity
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Audio track, 2352 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_AUDIO = "AUDIO";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>CD+G track, 2448 bytes/sector (audio+subchannel)</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_CDG = "CDG";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Mode 1 track, cooked, 2048 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_MODE1 = "MODE1/2048";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Mode 1 track, raw, 2352 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_MODE1_RAW = "MODE1/2352";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Mode 2 form 1 track, cooked, 2048 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_MODE2_FORM1 = "MODE2/2048";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Mode 2 form 2 track, cooked, 2324 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_MODE2_FORM2 = "MODE2/2324";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Mode 2 formless track, cooked, 2336 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_MODE2_FORMLESS = "MODE2/2336";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Mode 2 track, raw, 2352 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_MODE2_RAW = "MODE2/2352";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>CD-i track, cooked, 2336 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_CDI = "CDI/2336";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>CD-i track, raw, 2352 bytes/sector</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_TRACK_TYPE_CDI_RAW = "CDI/2352";
|
2015-12-06 07:37:20 +00:00
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
// Type for REM ORIGINAL MEDIA-TYPE entity
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.CD</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_CD = "CD";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.CDRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_CDRW = "CD-RW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.CDMRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_CDMRW = "CD-MRW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.CDMRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_CDMRW2 = "CD-(MRW)";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDROM</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVD = "DVD";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPMRW = "DVD+MRW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPMRW2 = "DVD+(MRW)";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRWDL</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPMRWDL = "DVD+MRW DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRWDL</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPMRWDL2 = "DVD+(MRW) DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPR = "DVD+R";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRDL</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPRDL = "DVD+R DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPRW = "DVD+RW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPRWDL</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPRWDL = "DVD+RW DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDPR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDPVR = "DVD+VR";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDRAM</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDRAM = "DVD-RAM";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDR = "DVD-R";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDRDL</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDRDL = "DVD-R DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDRW = "DVD-RW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDRWDL</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDRWDL = "DVD-RW DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDVR = "DVD-VR";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.DVDRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_DVDRW2 = "DVDRW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.HDDVDROM</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_HDDVD = "HD DVD";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.HDDVDRAM</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_HDDVDRAM = "HD DVD-RAM";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.HDDVDR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_HDDVDR = "HD DVD-R";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.HDDVDR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_HDDVDRDL = "HD DVD-R DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.HDDVDRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_HDDVDRW = "HD DVD-RW";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.HDDVDRW</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_HDDVDRWDL = "HD DVD-RW DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.BDROM</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_BD = "BD";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.BDR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_BDR = "BD-R";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.BDRE</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_BDRE = "BD-RE";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.BDR</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_BDRDL = "BD-R DL";
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>DiskType.BDRE</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
const string CDRWIN_DISK_TYPE_BDREDL = "BD-RE DL";
|
2014-04-14 01:14:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Internal variables
|
2016-09-05 17:37:31 +01:00
|
|
|
Filter imageFilter;
|
2014-04-14 01:14:20 +00:00
|
|
|
StreamReader cueStream;
|
2016-09-05 17:37:31 +01:00
|
|
|
Stream imageStream;
|
2015-12-06 07:37:20 +00:00
|
|
|
/// <summary>Dictionary, index is track #, value is TrackFile</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
Dictionary<uint, ulong> offsetmap;
|
2017-12-20 17:15:26 +00:00
|
|
|
CdrWinDisc discimage;
|
2016-07-28 22:25:26 +01:00
|
|
|
List<Partition> partitions;
|
2014-04-14 01:14:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Parsing regexs
|
2017-12-20 17:15:26 +00:00
|
|
|
const string SESSION_REGEX = "\\bREM\\s+SESSION\\s+(?<number>\\d+).*$";
|
|
|
|
|
const string DISK_TYPE_REGEX = "\\bREM\\s+ORIGINAL MEDIA-TYPE:\\s+(?<mediatype>.+)$";
|
|
|
|
|
const string LEAD_OUT_REGEX = "\\bREM\\s+LEAD-OUT\\s+(?<msf>[\\d]+:[\\d]+:[\\d]+)$";
|
2014-04-14 01:14:20 +00:00
|
|
|
// Not checked
|
2017-12-20 17:15:26 +00:00
|
|
|
const string LBA_REGEX = "\\bREM MSF:\\s+(?<msf>[\\d]+:[\\d]+:[\\d]+)\\s+=\\s+LBA:\\s+(?<lba>[\\d]+)$";
|
|
|
|
|
const string DISK_ID_REGEX = "\\bDISC_ID\\s+(?<diskid>[\\da-f]{8})$";
|
|
|
|
|
const string BAR_CODE_REGEX = "\\bUPC_EAN\\s+(?<barcode>[\\d]{12,13})$";
|
|
|
|
|
const string COMMENT_REGEX = "\\bREM\\s+(?<comment>.+)$";
|
|
|
|
|
const string CD_TEXT_REGEX = "\\bCDTEXTFILE\\s+(?<filename>.+)$";
|
|
|
|
|
const string MCN_REGEX = "\\bCATALOG\\s+(?<catalog>\\d{13})$";
|
|
|
|
|
const string TITLE_REGEX = "\\bTITLE\\s+(?<title>.+)$";
|
|
|
|
|
const string GENRE_REGEX = "\\bGENRE\\s+(?<genre>.+)$";
|
|
|
|
|
const string ARRANGER_REGEX = "\\bARRANGER\\s+(?<arranger>.+)$";
|
|
|
|
|
const string COMPOSER_REGEX = "\\bCOMPOSER\\s+(?<composer>.+)$";
|
|
|
|
|
const string PERFORMER_REGEX = "\\bPERFORMER\\s+(?<performer>.+)$";
|
|
|
|
|
const string SONG_WRITER_REGEX = "\\bSONGWRITER\\s+(?<songwriter>.+)$";
|
|
|
|
|
const string FILE_REGEX = "\\bFILE\\s+(?<filename>.+)\\s+(?<type>\\S+)$";
|
|
|
|
|
const string TRACK_REGEX = "\\bTRACK\\s+(?<number>\\d+)\\s+(?<type>\\S+)$";
|
|
|
|
|
const string ISRC_REGEX = "\\bISRC\\s+(?<isrc>\\w{12})$";
|
|
|
|
|
const string INDEX_REGEX = "\\bINDEX\\s+(?<index>\\d+)\\s+(?<msf>[\\d]+:[\\d]+:[\\d]+)$";
|
|
|
|
|
const string PREGAP_REGEX = "\\bPREGAP\\s+(?<msf>[\\d]+:[\\d]+:[\\d]+)$";
|
|
|
|
|
const string POSTGAP_REGEX = "\\bPOSTGAP\\s+(?<msf>[\\d]+:[\\d]+:[\\d]+)$";
|
|
|
|
|
const string FLAGS_REGEX = "\\bFLAGS\\s+(((?<dcp>DCP)|(?<quad>4CH)|(?<pre>PRE)|(?<scms>SCMS))\\s*)+$";
|
2014-04-14 01:14:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2017-12-20 17:15:26 +00:00
|
|
|
public CdrWin()
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2014-06-07 17:32:14 +01:00
|
|
|
Name = "CDRWin cuesheet";
|
2017-12-20 17:15:26 +00:00
|
|
|
PluginUuid = new Guid("664568B2-15D4-4E64-8A7A-20BDA8B8386F");
|
2014-08-28 19:29:18 +01:00
|
|
|
ImageInfo = new ImageInfo();
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.ReadableSectorTags = new List<SectorTagType>();
|
|
|
|
|
ImageInfo.ReadableMediaTags = new List<MediaTagType>();
|
|
|
|
|
ImageInfo.ImageHasPartitions = true;
|
|
|
|
|
ImageInfo.ImageHasSessions = true;
|
|
|
|
|
ImageInfo.ImageVersion = null;
|
|
|
|
|
ImageInfo.ImageApplicationVersion = null;
|
|
|
|
|
ImageInfo.ImageName = null;
|
|
|
|
|
ImageInfo.ImageCreator = null;
|
|
|
|
|
ImageInfo.MediaManufacturer = null;
|
|
|
|
|
ImageInfo.MediaModel = null;
|
|
|
|
|
ImageInfo.MediaPartNumber = null;
|
|
|
|
|
ImageInfo.MediaSequence = 0;
|
|
|
|
|
ImageInfo.LastMediaSequence = 0;
|
|
|
|
|
ImageInfo.DriveManufacturer = null;
|
|
|
|
|
ImageInfo.DriveModel = null;
|
|
|
|
|
ImageInfo.DriveSerialNumber = null;
|
|
|
|
|
ImageInfo.DriveFirmwareRevision = null;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
2014-08-24 17:46:29 +01:00
|
|
|
|
2013-12-16 01:04:17 +00:00
|
|
|
// Due to .cue format, this method must parse whole file, ignoring errors (those will be thrown by OpenImage()).
|
2016-09-05 17:37:31 +01:00
|
|
|
public override bool IdentifyImage(Filter imageFilter)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
this.imageFilter = imageFilter;
|
2013-12-14 23:02:04 +00:00
|
|
|
|
2013-12-16 01:04:17 +00:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
|
|
|
|
|
byte[] testArray = new byte[512];
|
|
|
|
|
imageFilter.GetDataForkStream().Read(testArray, 0, 512);
|
|
|
|
|
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
|
|
|
|
|
// Check for unexpected control characters that shouldn't be present in a text file and can crash this plugin
|
|
|
|
|
bool twoConsecutiveNulls = false;
|
|
|
|
|
for(int i = 0; i < 512; i++)
|
|
|
|
|
{
|
|
|
|
|
if(i >= imageFilter.GetDataForkStream().Length) break;
|
|
|
|
|
|
|
|
|
|
if(testArray[i] == 0)
|
|
|
|
|
{
|
|
|
|
|
if(twoConsecutiveNulls) return false;
|
|
|
|
|
|
|
|
|
|
twoConsecutiveNulls = true;
|
|
|
|
|
}
|
|
|
|
|
else twoConsecutiveNulls = false;
|
|
|
|
|
|
|
|
|
|
if(testArray[i] < 0x20 && testArray[i] != 0x0A && testArray[i] != 0x0D && testArray[i] != 0x00)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cueStream = new StreamReader(this.imageFilter.GetDataForkStream());
|
2013-12-16 01:04:17 +00:00
|
|
|
int line = 0;
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
while(cueStream.Peek() >= 0)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
|
|
|
|
line++;
|
2014-04-14 01:14:20 +00:00
|
|
|
string _line = cueStream.ReadLine();
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
Regex sr = new Regex(SESSION_REGEX);
|
|
|
|
|
Regex rr = new Regex(COMMENT_REGEX);
|
|
|
|
|
Regex cr = new Regex(MCN_REGEX);
|
|
|
|
|
Regex fr = new Regex(FILE_REGEX);
|
|
|
|
|
Regex tr = new Regex(CD_TEXT_REGEX);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
Match sm;
|
|
|
|
|
Match rm;
|
|
|
|
|
Match cm;
|
|
|
|
|
Match fm;
|
|
|
|
|
Match tm;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2016-08-08 18:44:08 +01:00
|
|
|
// First line must be SESSION, REM, CATALOG, FILE or CDTEXTFILE.
|
2017-12-20 17:15:26 +00:00
|
|
|
sm = sr.Match(_line);
|
|
|
|
|
rm = rr.Match(_line);
|
|
|
|
|
cm = cr.Match(_line);
|
|
|
|
|
fm = fr.Match(_line);
|
|
|
|
|
tm = tr.Match(_line);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(!sm.Success && !rm.Success && !cm.Success && !fm.Success && !tm.Success) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
return true;
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
catch(Exception ex)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
DicConsole.ErrorWriteLine("Exception trying to identify image file {0}", this.imageFilter);
|
2015-10-18 22:04:03 +01: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
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
public override bool OpenImage(Filter 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
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
this.imageFilter = imageFilter;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
|
|
|
|
|
cueStream = new StreamReader(imageFilter.GetDataForkStream());
|
2013-12-16 01:04:17 +00:00
|
|
|
int line = 0;
|
|
|
|
|
bool intrack = false;
|
|
|
|
|
byte currentsession = 1;
|
|
|
|
|
|
|
|
|
|
// Initialize all RegExs
|
2017-12-20 17:15:26 +00:00
|
|
|
Regex regexSession = new Regex(SESSION_REGEX);
|
|
|
|
|
Regex regexDiskType = new Regex(DISK_TYPE_REGEX);
|
|
|
|
|
Regex regexLeadOut = new Regex(LEAD_OUT_REGEX);
|
|
|
|
|
Regex regexLba = new Regex(LBA_REGEX);
|
|
|
|
|
Regex regexDiskId = new Regex(DISK_ID_REGEX);
|
|
|
|
|
Regex regexBarCode = new Regex(BAR_CODE_REGEX);
|
|
|
|
|
Regex regexComment = new Regex(COMMENT_REGEX);
|
|
|
|
|
Regex regexCdText = new Regex(CD_TEXT_REGEX);
|
|
|
|
|
Regex regexMcn = new Regex(MCN_REGEX);
|
|
|
|
|
Regex regexTitle = new Regex(TITLE_REGEX);
|
|
|
|
|
Regex regexGenre = new Regex(GENRE_REGEX);
|
|
|
|
|
Regex regexArranger = new Regex(ARRANGER_REGEX);
|
|
|
|
|
Regex regexComposer = new Regex(COMPOSER_REGEX);
|
|
|
|
|
Regex regexPerformer = new Regex(PERFORMER_REGEX);
|
|
|
|
|
Regex regexSongWriter = new Regex(SONG_WRITER_REGEX);
|
|
|
|
|
Regex regexFile = new Regex(FILE_REGEX);
|
|
|
|
|
Regex regexTrack = new Regex(TRACK_REGEX);
|
|
|
|
|
Regex regexIsrc = new Regex(ISRC_REGEX);
|
|
|
|
|
Regex regexIndex = new Regex(INDEX_REGEX);
|
|
|
|
|
Regex regexPregap = new Regex(PREGAP_REGEX);
|
|
|
|
|
Regex regexPostgap = new Regex(POSTGAP_REGEX);
|
|
|
|
|
Regex regexFlags = new Regex(FLAGS_REGEX);
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
|
|
|
// Initialize all RegEx matches
|
2017-12-20 17:15:26 +00:00
|
|
|
Match matchSession;
|
|
|
|
|
Match matchDiskType;
|
|
|
|
|
Match matchLeadOut;
|
|
|
|
|
Match matchLba;
|
|
|
|
|
Match matchDiskId;
|
|
|
|
|
Match matchBarCode;
|
|
|
|
|
Match matchComment;
|
|
|
|
|
Match matchCdText;
|
|
|
|
|
Match matchMcn;
|
|
|
|
|
Match matchTitle;
|
|
|
|
|
Match matchGenre;
|
|
|
|
|
Match matchArranger;
|
|
|
|
|
Match matchComposer;
|
|
|
|
|
Match matchPerformer;
|
|
|
|
|
Match matchSongWriter;
|
|
|
|
|
Match matchFile;
|
|
|
|
|
Match matchTrack;
|
|
|
|
|
Match matchIsrc;
|
|
|
|
|
Match matchIndex;
|
|
|
|
|
Match matchPregap;
|
|
|
|
|
Match matchPostgap;
|
|
|
|
|
Match matchFlags;
|
2013-12-16 01:04:17 +00:00
|
|
|
|
|
|
|
|
// Initialize disc
|
2017-12-20 17:15:26 +00:00
|
|
|
discimage = new CdrWinDisc();
|
|
|
|
|
discimage.Sessions = new List<Session>();
|
|
|
|
|
discimage.Tracks = new List<CdrWinTrack>();
|
|
|
|
|
discimage.Comment = "";
|
|
|
|
|
|
|
|
|
|
CdrWinTrack currenttrack = new CdrWinTrack();
|
|
|
|
|
currenttrack.Indexes = new Dictionary<int, ulong>();
|
|
|
|
|
CdrWinTrackFile currentfile = new CdrWinTrackFile();
|
2014-04-14 01:14:20 +00:00
|
|
|
ulong currentfileoffsetsector = 0;
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
CdrWinTrack[] cuetracks;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
line++;
|
|
|
|
|
string _line = cueStream.ReadLine();
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
matchTrack = regexTrack.Match(_line);
|
|
|
|
|
if(matchTrack.Success)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
uint trackSeq = uint.Parse(matchTrack.Groups[1].Value);
|
|
|
|
|
if(trackCount + 1 != trackSeq)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found TRACK {0} out of order in line {1}",
|
2017-12-20 17:15:26 +00:00
|
|
|
trackSeq, line));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +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-20 17:15:26 +00:00
|
|
|
cuetracks = new CdrWinTrack[trackCount];
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
line = 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
|
|
|
{
|
|
|
|
|
line++;
|
2014-04-14 01:14:20 +00:00
|
|
|
string _line = cueStream.ReadLine();
|
2013-12-16 01:04:17 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
matchSession = regexSession.Match(_line);
|
|
|
|
|
matchDiskType = regexDiskType.Match(_line);
|
|
|
|
|
matchComment = regexComment.Match(_line);
|
|
|
|
|
matchLba = regexLba.Match(_line); // Unhandled, just ignored
|
|
|
|
|
matchLeadOut = regexLeadOut.Match(_line); // Unhandled, just ignored
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM ORIGINAL MEDIA TYPE at line {0}", line);
|
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)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found REM ORIGINAL MEDIA TYPE field after a track in line {0}",
|
|
|
|
|
line));
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
else if(matchSession.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM SESSION at line {0}", line);
|
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-20 17:15:26 +00:00
|
|
|
else if(matchLba.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM MSF at line {0}", line);
|
2013-12-16 01:04:17 +00:00
|
|
|
// Just ignored
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
else if(matchLeadOut.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM LEAD-OUT at line {0}", line);
|
2013-12-16 01:04:17 +00:00
|
|
|
// Just ignored
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
else if(matchComment.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found REM at line {0}", line);
|
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
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
matchTrack = regexTrack.Match(_line);
|
|
|
|
|
matchTitle = regexTitle.Match(_line);
|
|
|
|
|
matchSongWriter = regexSongWriter.Match(_line);
|
|
|
|
|
matchPregap = regexPregap.Match(_line);
|
|
|
|
|
matchPostgap = regexPostgap.Match(_line);
|
|
|
|
|
matchPerformer = regexPerformer.Match(_line);
|
|
|
|
|
matchMcn = regexMcn.Match(_line);
|
|
|
|
|
matchIsrc = regexIsrc.Match(_line);
|
|
|
|
|
matchIndex = regexIndex.Match(_line);
|
|
|
|
|
matchGenre = regexGenre.Match(_line);
|
|
|
|
|
matchFlags = regexFlags.Match(_line);
|
|
|
|
|
matchFile = regexFile.Match(_line);
|
|
|
|
|
matchDiskId = regexDiskId.Match(_line);
|
|
|
|
|
matchComposer = regexComposer.Match(_line);
|
|
|
|
|
matchCdText = regexCdText.Match(_line);
|
|
|
|
|
matchBarCode = regexBarCode.Match(_line);
|
|
|
|
|
matchArranger = regexArranger.Match(_line);
|
|
|
|
|
|
|
|
|
|
if(matchArranger.Success)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found ARRANGER at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(intrack) currenttrack.Arranger = matchArranger.Groups[1].Value;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found UPC_EAN at line {0}", line);
|
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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found barcode field in incorrect place at line {0}",
|
|
|
|
|
line));
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found CDTEXTFILE at line {0}", line);
|
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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found CD-Text file field in incorrect place at line {0}",
|
|
|
|
|
line));
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found COMPOSER at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(intrack) currenttrack.Composer = matchComposer.Groups[1].Value;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found DISC_ID at line {0}", line);
|
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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found CDDB ID field in incorrect place at line {0}",
|
|
|
|
|
line));
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found FILE at line {0}", 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
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
|
|
|
|
currenttrack.Trackfile = currentfile;
|
|
|
|
|
currenttrack.Sectors =
|
|
|
|
|
((ulong)currentfile.Datafilter.GetLength() - currentfile.Offset) /
|
|
|
|
|
CdrWinTrackTypeToBytesPerSector(currenttrack.Tracktype);
|
|
|
|
|
cuetracks[currenttrack.Sequence - 1] = currenttrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
intrack = false;
|
2017-12-20 17:15:26 +00:00
|
|
|
currenttrack = new CdrWinTrack();
|
|
|
|
|
currentfile = new CdrWinTrackFile();
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList = new FiltersList();
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
//currentfile = new CDRWinTrackFile();
|
2017-12-20 17:15:26 +00:00
|
|
|
string datafile = matchFile.Groups[1].Value;
|
|
|
|
|
currentfile.Filetype = matchFile.Groups[2].Value;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
// Check if file path is quoted
|
2016-09-05 17:37:31 +01:00
|
|
|
if(datafile[0] == '"' && datafile[datafile.Length - 1] == '"')
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01: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)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(datafile[0] == '/' || (datafile[0] == '/' && datafile[1] == '.')
|
|
|
|
|
) // UNIX absolute path
|
2014-04-14 01:14:20 +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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("File \"{0}\" not found.",
|
2017-12-20 17:15:26 +00:00
|
|
|
matchFile
|
2017-12-19 20:33:03 +00:00
|
|
|
.Groups[1].Value));
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string.Format("File \"{0}\" not found.",
|
2017-12-20 17:15:26 +00:00
|
|
|
matchFile.Groups[1].Value));
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
else if((datafile[1] == ':' && datafile[2] == '\\') ||
|
|
|
|
|
(datafile[0] == '\\' && datafile[1] == '\\') ||
|
|
|
|
|
((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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("File \"{0}\" not found.",
|
2017-12-20 17:15:26 +00:00
|
|
|
matchFile
|
2017-12-19 20:33:03 +00:00
|
|
|
.Groups[1].Value));
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string.Format("File \"{0}\" not found.",
|
2017-12-20 17:15:26 +00:00
|
|
|
matchFile.Groups[1].Value));
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-09-05 17:37:31 +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
|
|
|
|
|
FeatureUnsupportedImageException(string.Format("File \"{0}\" not found.",
|
2017-12-20 17:15:26 +00:00
|
|
|
matchFile.Groups[1].Value));
|
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
|
|
|
|
|
FeatureSupportedButNotImplementedImageException(string
|
|
|
|
|
.Format("Unsupported file type {0}",
|
|
|
|
|
currentfile
|
2017-12-20 17:15:26 +00:00
|
|
|
.Filetype));
|
2014-04-14 01:14:20 +00:00
|
|
|
default:
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new FeatureUnsupportedImageException(string.Format("Unknown file type {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
currentfile.Filetype));
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
currentfile.Offset = 0;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found FLAGS at line {0}", line);
|
2016-04-19 02:11:47 +01:00
|
|
|
if(!intrack)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found FLAGS field in incorrect place at line {0}",
|
|
|
|
|
line));
|
2015-12-23 23:46:31 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
currenttrack.FlagDcp |= matchFile.Groups["dcp"].Value == "DCP";
|
|
|
|
|
currenttrack.Flag4ch |= matchFile.Groups["quad"].Value == "4CH";
|
|
|
|
|
currenttrack.FlagPre |= matchFile.Groups["pre"].Value == "PRE";
|
|
|
|
|
currenttrack.FlagScms |= matchFile.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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found GENRE at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(intrack) currenttrack.Genre = matchGenre.Groups[1].Value;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found INDEX at line {0}", line);
|
2016-04-19 02:11:47 +01:00
|
|
|
if(!intrack)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string.Format("Found INDEX before a track {0}",
|
|
|
|
|
line));
|
2013-12-16 01:04:17 +00:00
|
|
|
else
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
int index = int.Parse(matchIndex.Groups[1].Value);
|
|
|
|
|
ulong offset = CdrWinMsftoLba(matchIndex.Groups[2].Value);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if((index != 0 && index != 1) && currenttrack.Indexes.Count == 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found INDEX {0} before INDEX 00 or INDEX 01",
|
|
|
|
|
index));
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if((index == 0 || (index == 1 && !currenttrack.Indexes.ContainsKey(0))))
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if((int)(currenttrack.Sequence - 2) >= 0 && offset > 1)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
cuetracks[currenttrack.Sequence - 2].Sectors = offset - currentfileoffsetsector;
|
|
|
|
|
currentfile.Offset +=
|
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Sectors *
|
|
|
|
|
cuetracks[currenttrack.Sequence - 2].Bps;
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin",
|
|
|
|
|
"Sets currentfile.offset to {0} at line 553",
|
2017-12-20 17:15:26 +00:00
|
|
|
currentfile.Offset);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin",
|
|
|
|
|
"cuetracks[currenttrack.sequence-2].sectors = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
cuetracks[currenttrack.Sequence - 2].Sectors);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin",
|
|
|
|
|
"cuetracks[currenttrack.sequence-2].bps = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
cuetracks[currenttrack.Sequence - 2].Bps);
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if((index == 0 || (index == 1 && !currenttrack.Indexes.ContainsKey(0))) &&
|
|
|
|
|
currenttrack.Sequence == 1)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin",
|
|
|
|
|
"Sets currentfile.offset to {0} at line 559",
|
2017-12-20 17:15:26 +00:00
|
|
|
offset * currenttrack.Bps);
|
|
|
|
|
currentfile.Offset = offset * currenttrack.Bps;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
currentfileoffsetsector = offset;
|
2017-12-20 17:15:26 +00:00
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found ISRC at line {0}", line);
|
2016-04-19 02:11:47 +01:00
|
|
|
if(!intrack)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string.Format("Found ISRC before a track {0}",
|
|
|
|
|
line));
|
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found CATALOG at line {0}", line);
|
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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found CATALOG field in incorrect place at line {0}",
|
|
|
|
|
line));
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found PERFORMER at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(intrack) currenttrack.Performer = matchPerformer.Groups[1].Value;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found POSTGAP at line {0}", line);
|
2017-12-20 17:15:26 +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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found POSTGAP field before a track at line {0}",
|
|
|
|
|
line));
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found PREGAP at line {0}", line);
|
2017-12-20 17:15:26 +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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found PREGAP field before a track at line {0}",
|
|
|
|
|
line));
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found SONGWRITER at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(intrack) currenttrack.Songwriter = matchSongWriter.Groups[1].Value;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found TITLE at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(intrack) currenttrack.Title = matchTitle.Groups[1].Value;
|
|
|
|
|
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
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Found TRACK at line {0}", line);
|
2017-12-20 17:15:26 +00:00
|
|
|
if(currentfile.Datafilter == null)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found TRACK field before a file is defined at line {0}",
|
|
|
|
|
line));
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(intrack)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(currenttrack.Indexes.ContainsKey(0) && currenttrack.Pregap == 0)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
currenttrack.Indexes.TryGetValue(0, out currenttrack.Pregap);
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
|
|
|
|
currenttrack.Trackfile = currentfile;
|
|
|
|
|
cuetracks[currenttrack.Sequence - 1] = currenttrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
currenttrack = new CdrWinTrack();
|
|
|
|
|
currenttrack.Indexes = new Dictionary<int, ulong>();
|
|
|
|
|
currenttrack.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);
|
|
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
|
|
|
|
currenttrack.Bps = CdrWinTrackTypeToBytesPerSector(matchTrack.Groups[2].Value);
|
|
|
|
|
currenttrack.Tracktype = matchTrack.Groups[2].Value;
|
|
|
|
|
currenttrack.Session = currentsession;
|
2014-04-14 01:14:20 +00:00
|
|
|
intrack = true;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01: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
|
|
|
|
|
FeatureUnsupportedImageException(string
|
|
|
|
|
.Format("Found unknown field defined at line {0}: \"{1}\"",
|
|
|
|
|
line, _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
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
currentfile.Sequence = currenttrack.Sequence;
|
|
|
|
|
currenttrack.Trackfile = currentfile;
|
|
|
|
|
currenttrack.Sectors = ((ulong)currentfile.Datafilter.GetLength() - currentfile.Offset) /
|
|
|
|
|
CdrWinTrackTypeToBytesPerSector(currenttrack.Tracktype);
|
|
|
|
|
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;
|
|
|
|
|
else sessions[s - 1].StartSector = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
ulong sessionSectors = 0;
|
|
|
|
|
int lastSessionTrack = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
for(int i = 0; i < cuetracks.Length; i++)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cuetracks[i].Session == s)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sessionSectors += cuetracks[i].Sectors;
|
|
|
|
|
if(i > lastSessionTrack) lastSessionTrack = i;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
sessions[s - 1].EndTrack = cuetracks[lastSessionTrack].Sequence;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
bool data = false;
|
|
|
|
|
bool cdg = false;
|
|
|
|
|
bool cdi = false;
|
|
|
|
|
bool mode2 = false;
|
|
|
|
|
bool firstaudio = false;
|
|
|
|
|
bool firstdata = false;
|
|
|
|
|
bool audio = false;
|
|
|
|
|
|
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;
|
|
|
|
|
else if(cdg) discimage.Disktype = MediaType.CDG;
|
|
|
|
|
else if(cdi) discimage.Disktype = MediaType.CDI;
|
|
|
|
|
else if(firstaudio && data && discimage.Sessions.Count > 1 && mode2)
|
|
|
|
|
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
|
|
|
|
|
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.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tArranger: {0}", discimage.Arranger);
|
|
|
|
|
if(discimage.Composer == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tComposer is not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tComposer: {0}", discimage.Composer);
|
|
|
|
|
if(discimage.Genre == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tGenre is not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tGenre: {0}", discimage.Genre);
|
|
|
|
|
if(discimage.Performer == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tPerformer is not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tPerformer: {0}", discimage.Performer);
|
|
|
|
|
if(discimage.Songwriter == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tSongwriter is not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tSongwriter: {0}", discimage.Songwriter);
|
|
|
|
|
if(discimage.Title == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tTitle is not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tTitle: {0}", discimage.Title);
|
|
|
|
|
if(discimage.Cdtextfile == null)
|
2015-10-18 22:04:03 +01: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);
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Disc information:");
|
2017-12-20 17:15:26 +00:00
|
|
|
if(discimage.Disktypestr == null)
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tISOBuster disc type not set.");
|
2017-12-20 17:15:26 +00:00
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tISOBuster disc type: {0}", discimage.Disktypestr);
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tGuessed disk type: {0}", discimage.Disktype);
|
|
|
|
|
if(discimage.Barcode == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tBarcode not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tBarcode: {0}", discimage.Barcode);
|
|
|
|
|
if(discimage.DiskId == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc ID not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc ID: {0}", discimage.DiskId);
|
|
|
|
|
if(discimage.Mcn == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tMCN not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tMCN: {0}", discimage.Mcn);
|
|
|
|
|
if(discimage.Comment == null) DicConsole.DebugWriteLine("CDRWin plugin", "\tComment not set.");
|
|
|
|
|
else DicConsole.DebugWriteLine("CDRWin plugin", "\tComment: \"{0}\"", discimage.Comment);
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "Session information:");
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tDisc contains {0} sessions", discimage.Sessions.Count);
|
|
|
|
|
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);
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tPregap: {0} sectors", discimage.Tracks[i].Pregap);
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\t\tData: {0} sectors", discimage.Tracks[i].Sectors);
|
|
|
|
|
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)
|
2015-10-18 22:04:03 +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)
|
2015-10-18 22:04:03 +01: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)
|
2015-10-18 22:04:03 +01: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)
|
2015-10-18 22:04:03 +01: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)
|
2015-10-18 22:04:03 +01: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)
|
2015-10-18 22:04:03 +01: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
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
partitions = new List<Partition>();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
ulong byteOffset = 0;
|
|
|
|
|
ulong sectorOffset = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
ulong partitionSequence = 0;
|
2017-12-20 17:15:26 +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-19 20:33:03 +00:00
|
|
|
throw new ImageNotSupportedException(string.Format("Track {0} lacks index 01",
|
2017-12-20 17:15:26 +00:00
|
|
|
discimage.Tracks[i].Sequence));
|
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-20 17:15:26 +00:00
|
|
|
partition.Description = string.Format("Track {0}.", discimage.Tracks[i].Sequence);
|
|
|
|
|
partition.Name = discimage.Tracks[i].Title;
|
|
|
|
|
partition.Start = sectorOffset;
|
|
|
|
|
partition.Size = (discimage.Tracks[i].Sectors - index0Len) * discimage.Tracks[i].Bps;
|
|
|
|
|
partition.Length = (discimage.Tracks[i].Sectors - index0Len);
|
2017-07-19 16:37:11 +01:00
|
|
|
partition.Sequence = partitionSequence;
|
2017-12-20 17:15:26 +00:00
|
|
|
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;
|
|
|
|
|
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-20 17:15:26 +00:00
|
|
|
ulong oldStart;
|
|
|
|
|
offsetmap.TryGetValue(discimage.Tracks[i].Sequence, out 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partitions.Add(partition);
|
2016-07-28 22:25:26 +01:00
|
|
|
partition = new 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");
|
2016-07-28 22:25:26 +01: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);
|
|
|
|
|
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);
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition starting sector: {0}", partition.Start);
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition sectors: {0}", partition.Length);
|
|
|
|
|
DicConsole.DebugWriteLine("CDRWin plugin", "\tPartition starting offset: {0}", partition.Offset);
|
|
|
|
|
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-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack track in discimage.Tracks) ImageInfo.ImageSize += track.Bps * track.Sectors;
|
|
|
|
|
foreach(CdrWinTrack track in discimage.Tracks) ImageInfo.Sectors += track.Sectors;
|
2014-08-24 17:46:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(discimage.Disktype == MediaType.CDG || discimage.Disktype == MediaType.CDEG ||
|
|
|
|
|
discimage.Disktype == MediaType.CDMIDI)
|
|
|
|
|
ImageInfo.SectorSize = 2448; // CD+G subchannels ARE user data, as CD+G are useless without them
|
|
|
|
|
else if(discimage.Disktype != MediaType.CDROMXA && discimage.Disktype != MediaType.CDDA &&
|
|
|
|
|
discimage.Disktype != MediaType.CDI &&
|
|
|
|
|
discimage.Disktype != MediaType.CDPLUS) ImageInfo.SectorSize = 2048; // Only data tracks
|
|
|
|
|
else ImageInfo.SectorSize = 2352; // All others
|
2014-08-24 17:46:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(discimage.Mcn != null) ImageInfo.ReadableMediaTags.Add(MediaTagType.CD_MCN);
|
|
|
|
|
if(discimage.Cdtextfile != null) ImageInfo.ReadableMediaTags.Add(MediaTagType.CD_TEXT);
|
2014-08-24 17:46:29 +01:00
|
|
|
|
|
|
|
|
// Detect ISOBuster extensions
|
2017-12-20 17:15:26 +00:00
|
|
|
if(discimage.Disktypestr != null || discimage.Comment.ToLower().Contains("isobuster") ||
|
|
|
|
|
discimage.Sessions.Count > 1) ImageInfo.ImageApplication = "ISOBuster";
|
|
|
|
|
else ImageInfo.ImageApplication = "CDRWin";
|
2014-08-24 17:46:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.ImageCreationTime = imageFilter.GetCreationTime();
|
|
|
|
|
ImageInfo.ImageLastModificationTime = imageFilter.GetLastWriteTime();
|
2014-08-24 17:46:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.ImageComments = discimage.Comment;
|
|
|
|
|
ImageInfo.MediaSerialNumber = discimage.Mcn;
|
|
|
|
|
ImageInfo.MediaBarcode = discimage.Barcode;
|
|
|
|
|
ImageInfo.MediaType = discimage.Disktype;
|
2014-08-24 17:46:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +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)
|
2014-08-24 17:46:29 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +00:00
|
|
|
ImageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2015-12-05 17:21:47 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.VerboseWriteLine("CDRWIN image describes a disc of type {0}", ImageInfo.MediaType);
|
|
|
|
|
if(!string.IsNullOrEmpty(ImageInfo.ImageComments))
|
|
|
|
|
DicConsole.VerboseWriteLine("CDRWIN comments: {0}", ImageInfo.ImageComments);
|
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());
|
2015-10-18 22:04:03 +01: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
|
|
|
|
2013-12-14 23:02:04 +00:00
|
|
|
public override bool ImageHasPartitions()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageHasPartitions;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override ulong GetImageSize()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageSize;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override ulong GetSectors()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.Sectors;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override uint GetSectorSize()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.SectorSize;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override 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 17:15:26 +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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override byte[] ReadSectors(ulong sectorAddress, uint length)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(sectorAddress >= kvp.Value)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrwinTrack.Sequence == kvp.Key)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if((sectorAddress - kvp.Value) < cdrwinTrack.Sectors)
|
2014-04-14 01:14:20 +00:00
|
|
|
return ReadSectors((sectorAddress - kvp.Value), length, kvp.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(sectorAddress >= kvp.Value)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrwinTrack.Sequence == kvp.Key)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if((sectorAddress - kvp.Value) < cdrwinTrack.Sectors)
|
2014-04-14 01:14:20 +00:00
|
|
|
return ReadSectorsTag((sectorAddress - kvp.Value), length, kvp.Key, tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
CdrWinTrack _track = new CdrWinTrack();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.Sequence = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrwinTrack.Sequence == track)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
_track = cdrwinTrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.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-20 17:15:26 +00:00
|
|
|
if(length > _track.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-20 17:15:26 +00:00
|
|
|
switch(_track.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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
imageStream = _track.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-20 17:15:26 +00:00
|
|
|
.Seek((long)_track.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
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
for(int i = 0; i < length; i++)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
byte[] sector;
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
|
|
|
|
sector = br.ReadBytes((int)sectorSize);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
CdrWinTrack _track = new CdrWinTrack();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.Sequence = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrwinTrack.Sequence == track)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
_track = cdrwinTrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.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-20 17:15:26 +00:00
|
|
|
if(length > _track.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
|
|
|
{
|
|
|
|
|
byte[] flags = new byte[1];
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.Tracktype != CDRWIN_TRACK_TYPE_AUDIO && _track.Tracktype != CDRWIN_TRACK_TYPE_CDG)
|
2017-12-19 20:33:03 +00:00
|
|
|
flags[0] += 0x40;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.FlagDcp) flags[0] += 0x20;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.FlagPre) flags[0] += 0x10;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.Flag4ch) flags[0] += 0x80;
|
2015-12-23 23:46:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
return flags;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdTrackIsrc: return Encoding.UTF8.GetBytes(_track.Isrc);
|
|
|
|
|
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-20 17:15:26 +00:00
|
|
|
switch(_track.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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
imageStream = _track.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-20 17:15:26 +00:00
|
|
|
.Seek((long)_track.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
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
for(int i = 0; i < length; i++)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
byte[] sector;
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
|
|
|
|
sector = br.ReadBytes((int)sectorSize);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(sectorAddress >= kvp.Value)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrwinTrack.Sequence == kvp.Key)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if((sectorAddress - kvp.Value) < cdrwinTrack.Sectors)
|
2014-04-14 01:14:20 +00:00
|
|
|
return ReadSectorsLong((sectorAddress - kvp.Value), length, kvp.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
CdrWinTrack _track = new CdrWinTrack();
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.Sequence = 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrwinTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrwinTrack.Sequence == track)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
_track = cdrwinTrack;
|
2014-04-14 01:14:20 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(_track.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-20 17:15:26 +00:00
|
|
|
if(length > _track.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-20 17:15:26 +00:00
|
|
|
switch(_track.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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
sectorSize = 2448;
|
|
|
|
|
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
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
imageStream = _track.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-20 17:15:26 +00:00
|
|
|
.Seek((long)_track.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
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
byte[] sector;
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
|
|
|
|
sector = br.ReadBytes((int)sectorSize);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageFormat()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
return "CDRWin CUESheet";
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageVersion()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageVersion;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageApplication()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageApplication;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageApplicationVersion()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageApplicationVersion;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DateTime GetImageCreationTime()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageCreationTime;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DateTime GetImageLastModificationTime()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageLastModificationTime;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageComments()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageComments;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override string GetMediaSerialNumber()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaSerialNumber;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override string GetMediaBarcode()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaBarcode;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override MediaType GetMediaType()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaType;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override List<Partition> GetPartitions()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
return partitions;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Track> GetTracks()
|
|
|
|
|
{
|
2014-04-14 01:14:20 +00:00
|
|
|
List<Track> tracks = new List<Track>();
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
ulong previousStartSector = 0;
|
2014-08-25 05:00:25 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(CdrWinTrack cdrTrack in discimage.Tracks)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
|
|
|
|
Track _track = new Track();
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.Indexes = cdrTrack.Indexes;
|
|
|
|
|
_track.TrackDescription = cdrTrack.Title;
|
|
|
|
|
if(!cdrTrack.Indexes.TryGetValue(0, out _track.TrackStartSector))
|
|
|
|
|
cdrTrack.Indexes.TryGetValue(1, out _track.TrackStartSector);
|
2015-11-09 22:17:45 +00:00
|
|
|
_track.TrackStartSector = previousStartSector;
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.TrackEndSector = _track.TrackStartSector + cdrTrack.Sectors - 1;
|
|
|
|
|
_track.TrackPregap = cdrTrack.Pregap;
|
|
|
|
|
_track.TrackSession = cdrTrack.Session;
|
|
|
|
|
_track.TrackSequence = cdrTrack.Sequence;
|
|
|
|
|
_track.TrackType = CdrWinTrackTypeToTrackType(cdrTrack.Tracktype);
|
|
|
|
|
_track.TrackFile = cdrTrack.Trackfile.Datafilter.GetFilename();
|
|
|
|
|
_track.TrackFilter = cdrTrack.Trackfile.Datafilter;
|
|
|
|
|
_track.TrackFileOffset = cdrTrack.Trackfile.Offset;
|
|
|
|
|
_track.TrackFileType = cdrTrack.Trackfile.Filetype;
|
|
|
|
|
_track.TrackRawBytesPerSector = cdrTrack.Bps;
|
|
|
|
|
_track.TrackBytesPerSector = CdrWinTrackTypeToCookedBytesPerSector(cdrTrack.Tracktype);
|
|
|
|
|
if(cdrTrack.Bps == 2448)
|
2015-12-06 05:09:31 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.TrackSubchannelFilter = cdrTrack.Trackfile.Datafilter;
|
|
|
|
|
_track.TrackSubchannelFile = cdrTrack.Trackfile.Datafilter.GetFilename();
|
|
|
|
|
_track.TrackSubchannelOffset = cdrTrack.Trackfile.Offset;
|
2015-12-06 05:09:31 +00:00
|
|
|
_track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else _track.TrackSubchannelType = TrackSubchannelType.None;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
tracks.Add(_track);
|
2014-08-25 05:00:25 +01:00
|
|
|
previousStartSector = _track.TrackEndSector + 1;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tracks;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
public override List<Track> GetSessionTracks(Session session)
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +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
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override 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)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(cdrTrack.Session == session)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
|
|
|
|
Track _track = new Track();
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.Indexes = cdrTrack.Indexes;
|
|
|
|
|
_track.TrackDescription = cdrTrack.Title;
|
|
|
|
|
if(!cdrTrack.Indexes.TryGetValue(0, out _track.TrackStartSector))
|
|
|
|
|
cdrTrack.Indexes.TryGetValue(1, out _track.TrackStartSector);
|
|
|
|
|
_track.TrackEndSector = _track.TrackStartSector + cdrTrack.Sectors - 1;
|
|
|
|
|
_track.TrackPregap = cdrTrack.Pregap;
|
|
|
|
|
_track.TrackSession = cdrTrack.Session;
|
|
|
|
|
_track.TrackSequence = cdrTrack.Sequence;
|
|
|
|
|
_track.TrackType = CdrWinTrackTypeToTrackType(cdrTrack.Tracktype);
|
|
|
|
|
_track.TrackFile = cdrTrack.Trackfile.Datafilter.GetFilename();
|
|
|
|
|
_track.TrackFilter = cdrTrack.Trackfile.Datafilter;
|
|
|
|
|
_track.TrackFileOffset = cdrTrack.Trackfile.Offset;
|
|
|
|
|
_track.TrackFileType = cdrTrack.Trackfile.Filetype;
|
|
|
|
|
_track.TrackRawBytesPerSector = cdrTrack.Bps;
|
|
|
|
|
_track.TrackBytesPerSector = CdrWinTrackTypeToCookedBytesPerSector(cdrTrack.Tracktype);
|
|
|
|
|
if(cdrTrack.Bps == 2448)
|
2015-12-06 05:09:31 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
_track.TrackSubchannelFilter = cdrTrack.Trackfile.Datafilter;
|
|
|
|
|
_track.TrackSubchannelFile = cdrTrack.Trackfile.Datafilter.GetFilename();
|
|
|
|
|
_track.TrackSubchannelOffset = cdrTrack.Trackfile.Offset;
|
2015-12-06 05:09:31 +00:00
|
|
|
_track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else _track.TrackSubchannelType = TrackSubchannelType.None;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
tracks.Add(_track);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tracks;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Session> GetSessions()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return discimage.Sessions;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override bool? VerifySector(ulong sectorAddress)
|
2014-08-25 05:00:25 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-20 17:15:26 +00:00
|
|
|
return Checksums.CdChecksums.CheckCdSector(buffer);
|
2014-08-25 05:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
public override bool? VerifySector(ulong sectorAddress, uint track)
|
2014-08-25 05:00:25 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress, track);
|
2017-12-20 17:15:26 +00:00
|
|
|
return Checksums.CdChecksums.CheckCdSector(buffer);
|
2014-08-25 05:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
public override 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);
|
|
|
|
|
int bps = (int)(buffer.Length / length);
|
|
|
|
|
byte[] sector = new byte[bps];
|
2017-12-20 17:15:26 +00: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-20 17:15:26 +00:00
|
|
|
bool? sectorStatus = Checksums.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;
|
|
|
|
|
if(failingLbas.Count > 0) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2014-08-25 05:00:25 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
public override 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);
|
|
|
|
|
int bps = (int)(buffer.Length / length);
|
|
|
|
|
byte[] sector = new byte[bps];
|
2017-12-20 17:15:26 +00: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-20 17:15:26 +00:00
|
|
|
bool? sectorStatus = Checksums.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;
|
|
|
|
|
if(failingLbas.Count > 0) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2014-08-25 05:00:25 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override bool? VerifyMediaImage()
|
2014-08-25 05:00:25 +01:00
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private methods
|
2017-12-20 17:15:26 +00:00
|
|
|
static ulong CdrWinMsftoLba(string msf)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
string[] msfElements;
|
2016-07-28 22:25:26 +01:00
|
|
|
ulong minute, second, frame, sectors;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
msfElements = msf.Split(':');
|
|
|
|
|
minute = ulong.Parse(msfElements[0]);
|
|
|
|
|
second = ulong.Parse(msfElements[1]);
|
|
|
|
|
frame = ulong.Parse(msfElements[2]);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
|
|
|
sectors = (minute * 60 * 75) + (second * 75) + frame;
|
|
|
|
|
|
|
|
|
|
return sectors;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
static ushort CdrWinTrackTypeToBytesPerSector(string trackType)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(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: return 2048;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM2: return 2324;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI: return 2336;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_AUDIO:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE1_RAW:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_RAW:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW: return 2352;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG: return 2448;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: return 0;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
static ushort CdrWinTrackTypeToCookedBytesPerSector(string trackType)
|
2015-12-06 05:09:31 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(trackType)
|
2015-12-06 05:09:31 +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_MODE1_RAW: return 2048;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM2: return 2324;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_RAW:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW: return 2336;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_AUDIO: return 2352;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG: return 2448;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: return 0;
|
2015-12-06 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
static TrackType CdrWinTrackTypeToTrackType(string trackType)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(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_MODE1_RAW: return TrackType.CdMode1;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM1: return TrackType.CdMode2Form1;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORM2: return TrackType.CdMode2Form2;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI_RAW:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDI:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_RAW:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_MODE2_FORMLESS: return TrackType.CdMode2Formless;
|
|
|
|
|
case CDRWIN_TRACK_TYPE_AUDIO:
|
|
|
|
|
case CDRWIN_TRACK_TYPE_CDG: return TrackType.Audio;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: return TrackType.Data;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
static MediaType CdrWinIsoBusterDiscTypeToMediaType(string discType)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(discType)
|
2014-04-14 01:14:20 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case CDRWIN_DISK_TYPE_CD: return MediaType.CD;
|
|
|
|
|
case CDRWIN_DISK_TYPE_CDRW:
|
|
|
|
|
case CDRWIN_DISK_TYPE_CDMRW:
|
|
|
|
|
case CDRWIN_DISK_TYPE_CDMRW2: return MediaType.CDRW;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVD: return MediaType.DVDROM;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPRW:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPMRW:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPMRW2: return MediaType.DVDPRW;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPRWDL:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPMRWDL:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPMRWDL2: return MediaType.DVDPRWDL;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPR:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPVR: return MediaType.DVDPR;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDPRDL: return MediaType.DVDPRDL;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDRAM: return MediaType.DVDRAM;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDVR:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDR: return MediaType.DVDR;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDRDL: return MediaType.DVDRDL;
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDRW:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDRWDL:
|
|
|
|
|
case CDRWIN_DISK_TYPE_DVDRW2: return MediaType.DVDRW;
|
|
|
|
|
case CDRWIN_DISK_TYPE_HDDVD: return MediaType.HDDVDROM;
|
|
|
|
|
case CDRWIN_DISK_TYPE_HDDVDRAM: return MediaType.HDDVDRAM;
|
|
|
|
|
case CDRWIN_DISK_TYPE_HDDVDR:
|
|
|
|
|
case CDRWIN_DISK_TYPE_HDDVDRDL: return MediaType.HDDVDR;
|
|
|
|
|
case CDRWIN_DISK_TYPE_HDDVDRW:
|
|
|
|
|
case CDRWIN_DISK_TYPE_HDDVDRWDL: return MediaType.HDDVDRW;
|
|
|
|
|
case CDRWIN_DISK_TYPE_BD: return MediaType.BDROM;
|
|
|
|
|
case CDRWIN_DISK_TYPE_BDR:
|
|
|
|
|
case CDRWIN_DISK_TYPE_BDRDL: return MediaType.BDR;
|
|
|
|
|
case CDRWIN_DISK_TYPE_BDRE:
|
|
|
|
|
case CDRWIN_DISK_TYPE_BDREDL: return MediaType.BDRE;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: return MediaType.Unknown;
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Unsupported features
|
2016-04-19 02:11:47 +01:00
|
|
|
public override int GetMediaSequence()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaSequence;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override int GetLastDiskSequence()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.LastMediaSequence;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDriveManufacturer()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.DriveManufacturer;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDriveModel()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.DriveModel;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDriveSerialNumber()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.DriveSerialNumber;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override string GetMediaPartNumber()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaPartNumber;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override string GetMediaManufacturer()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaManufacturer;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-16 03:54:55 +00:00
|
|
|
public override string GetMediaModel()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaModel;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageName()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageName;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
public override string GetImageCreator()
|
2013-12-14 23:02:04 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageCreator;
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
#endregion
|
2013-12-14 23:02:04 +00:00
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|