mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Refactor image classes and split them to smaller files.
This commit is contained in:
83
DiscImageChef.DiscImages/CDRWin/CDRWin.cs
Normal file
83
DiscImageChef.DiscImages/CDRWin/CDRWin.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
// /***************************************************************************
|
||||
// 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
// TODO: Implement track flags
|
||||
public partial class CdrWin : IWritableImage
|
||||
{
|
||||
IFilter cdrwinFilter;
|
||||
StreamReader cueStream;
|
||||
StreamWriter descriptorStream;
|
||||
CdrWinDisc discimage;
|
||||
ImageInfo imageInfo;
|
||||
Stream imageStream;
|
||||
/// <summary>Dictionary, index is track #, value is TrackFile</summary>
|
||||
Dictionary<uint, ulong> offsetmap;
|
||||
bool separateTracksWriting;
|
||||
Dictionary<byte, byte> trackFlags;
|
||||
Dictionary<byte, string> trackIsrcs;
|
||||
string writingBaseName;
|
||||
Dictionary<uint, FileStream> writingStreams;
|
||||
List<Track> writingTracks;
|
||||
|
||||
public CdrWin()
|
||||
{
|
||||
imageInfo = new ImageInfo
|
||||
{
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = true,
|
||||
HasSessions = true,
|
||||
Version = null,
|
||||
ApplicationVersion = null,
|
||||
MediaTitle = null,
|
||||
Creator = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
161
DiscImageChef.DiscImages/CDRWin/Constants.cs
Normal file
161
DiscImageChef.DiscImages/CDRWin/Constants.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Constants.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains constants for 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
// Type for FILE entity
|
||||
/// <summary>Data as-is in little-endian</summary>
|
||||
const string CDRWIN_DISK_TYPE_LITTLE_ENDIAN = "BINARY";
|
||||
/// <summary>Data as-is in big-endian</summary>
|
||||
const string CDRWIN_DISK_TYPE_BIG_ENDIAN = "MOTOROLA";
|
||||
/// <summary>Audio in Apple AIF file</summary>
|
||||
const string CDRWIN_DISK_TYPE_AIFF = "AIFF";
|
||||
/// <summary>Audio in Microsoft WAV file</summary>
|
||||
const string CDRWIN_DISK_TYPE_RIFF = "WAVE";
|
||||
/// <summary>Audio in MP3 file</summary>
|
||||
const string CDRWIN_DISK_TYPE_MP3 = "MP3";
|
||||
|
||||
// Type for TRACK entity
|
||||
/// <summary>Audio track, 2352 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_AUDIO = "AUDIO";
|
||||
/// <summary>CD+G track, 2448 bytes/sector (audio+subchannel)</summary>
|
||||
const string CDRWIN_TRACK_TYPE_CDG = "CDG";
|
||||
/// <summary>Mode 1 track, cooked, 2048 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_MODE1 = "MODE1/2048";
|
||||
/// <summary>Mode 1 track, raw, 2352 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_MODE1_RAW = "MODE1/2352";
|
||||
/// <summary>Mode 2 form 1 track, cooked, 2048 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_MODE2_FORM1 = "MODE2/2048";
|
||||
/// <summary>Mode 2 form 2 track, cooked, 2324 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_MODE2_FORM2 = "MODE2/2324";
|
||||
/// <summary>Mode 2 formless track, cooked, 2336 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_MODE2_FORMLESS = "MODE2/2336";
|
||||
/// <summary>Mode 2 track, raw, 2352 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_MODE2_RAW = "MODE2/2352";
|
||||
/// <summary>CD-i track, cooked, 2336 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_CDI = "CDI/2336";
|
||||
/// <summary>CD-i track, raw, 2352 bytes/sector</summary>
|
||||
const string CDRWIN_TRACK_TYPE_CDI_RAW = "CDI/2352";
|
||||
|
||||
// Type for REM ORIGINAL MEDIA-TYPE entity
|
||||
/// <summary>DiskType.CD</summary>
|
||||
const string CDRWIN_DISK_TYPE_CD = "CD";
|
||||
/// <summary>DiskType.CDRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_CDRW = "CD-RW";
|
||||
/// <summary>DiskType.CDMRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_CDMRW = "CD-MRW";
|
||||
/// <summary>DiskType.CDMRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_CDMRW2 = "CD-(MRW)";
|
||||
/// <summary>DiskType.DVDROM</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVD = "DVD";
|
||||
/// <summary>DiskType.DVDPRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPMRW = "DVD+MRW";
|
||||
/// <summary>DiskType.DVDPRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPMRW2 = "DVD+(MRW)";
|
||||
/// <summary>DiskType.DVDPRWDL</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPMRWDL = "DVD+MRW DL";
|
||||
/// <summary>DiskType.DVDPRWDL</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPMRWDL2 = "DVD+(MRW) DL";
|
||||
/// <summary>DiskType.DVDPR</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPR = "DVD+R";
|
||||
/// <summary>DiskType.DVDPRDL</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPRDL = "DVD+R DL";
|
||||
/// <summary>DiskType.DVDPRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPRW = "DVD+RW";
|
||||
/// <summary>DiskType.DVDPRWDL</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPRWDL = "DVD+RW DL";
|
||||
/// <summary>DiskType.DVDPR</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDPVR = "DVD+VR";
|
||||
/// <summary>DiskType.DVDRAM</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDRAM = "DVD-RAM";
|
||||
/// <summary>DiskType.DVDR</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDR = "DVD-R";
|
||||
/// <summary>DiskType.DVDRDL</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDRDL = "DVD-R DL";
|
||||
/// <summary>DiskType.DVDRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDRW = "DVD-RW";
|
||||
/// <summary>DiskType.DVDRWDL</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDRWDL = "DVD-RW DL";
|
||||
/// <summary>DiskType.DVDR</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDVR = "DVD-VR";
|
||||
/// <summary>DiskType.DVDRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_DVDRW2 = "DVDRW";
|
||||
/// <summary>DiskType.HDDVDROM</summary>
|
||||
const string CDRWIN_DISK_TYPE_HDDVD = "HD DVD";
|
||||
/// <summary>DiskType.HDDVDRAM</summary>
|
||||
const string CDRWIN_DISK_TYPE_HDDVDRAM = "HD DVD-RAM";
|
||||
/// <summary>DiskType.HDDVDR</summary>
|
||||
const string CDRWIN_DISK_TYPE_HDDVDR = "HD DVD-R";
|
||||
/// <summary>DiskType.HDDVDR</summary>
|
||||
const string CDRWIN_DISK_TYPE_HDDVDRDL = "HD DVD-R DL";
|
||||
/// <summary>DiskType.HDDVDRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_HDDVDRW = "HD DVD-RW";
|
||||
/// <summary>DiskType.HDDVDRW</summary>
|
||||
const string CDRWIN_DISK_TYPE_HDDVDRWDL = "HD DVD-RW DL";
|
||||
/// <summary>DiskType.BDROM</summary>
|
||||
const string CDRWIN_DISK_TYPE_BD = "BD";
|
||||
/// <summary>DiskType.BDR</summary>
|
||||
const string CDRWIN_DISK_TYPE_BDR = "BD-R";
|
||||
/// <summary>DiskType.BDRE</summary>
|
||||
const string CDRWIN_DISK_TYPE_BDRE = "BD-RE";
|
||||
/// <summary>DiskType.BDR</summary>
|
||||
const string CDRWIN_DISK_TYPE_BDRDL = "BD-R DL";
|
||||
/// <summary>DiskType.BDRE</summary>
|
||||
const string CDRWIN_DISK_TYPE_BDREDL = "BD-RE DL";
|
||||
|
||||
const string REGEX_SESSION = @"\bREM\s+SESSION\s+(?<number>\d+).*$";
|
||||
const string REGEX_MEDIA_TYPE = @"\bREM\s+ORIGINAL MEDIA-TYPE:\s+(?<mediatype>.+)$";
|
||||
const string REGEX_LEAD_OUT = @"\bREM\s+LEAD-OUT\s+(?<msf>[\d]+:[\d]+:[\d]+)$";
|
||||
// Not checked
|
||||
const string REGEX_LBA = @"\bREM MSF:\s+(?<msf>[\d]+:[\d]+:[\d]+)\s+=\s+LBA:\s+(?<lba>[\d]+)$";
|
||||
const string REGEX_DISC_ID = @"\bDISC_ID\s+(?<diskid>[\da-f]{8})$";
|
||||
const string REGEX_BARCODE = @"\bUPC_EAN\s+(?<barcode>[\d]{12,13})$";
|
||||
const string REGEX_COMMENT = @"\bREM\s+(?<comment>.+)$";
|
||||
const string REGEX_CDTEXT = @"\bCDTEXTFILE\s+(?<filename>.+)$";
|
||||
const string REGEX_MCN = @"^\s*CATALOG\s*(?<catalog>[\x21-\x7F]{13})$";
|
||||
const string REGEX_TITLE = @"\bTITLE\s+(?<title>.+)$";
|
||||
const string REGEX_GENRE = @"\bGENRE\s+(?<genre>.+)$";
|
||||
const string REGEX_ARRANGER = @"\bARRANGER\s+(?<arranger>.+)$";
|
||||
const string REGEX_COMPOSER = @"\bCOMPOSER\s+(?<composer>.+)$";
|
||||
const string REGEX_PERFORMER = @"\bPERFORMER\s+(?<performer>.+)$";
|
||||
const string REGEX_SONGWRITER = @"\bSONGWRITER\s+(?<songwriter>.+)$";
|
||||
const string REGEX_FILE = @"\bFILE\s+(?<filename>.+)\s+(?<type>\S+)$";
|
||||
const string REGEX_TRACK = @"\bTRACK\s+(?<number>\d+)\s+(?<type>\S+)$";
|
||||
const string REGEX_ISRC = @"\bISRC\s+(?<isrc>\w{12})$";
|
||||
const string REGEX_INDEX = @"\bINDEX\s+(?<index>\d+)\s+(?<msf>[\d]+:[\d]+:[\d]+)$";
|
||||
const string REGEX_PREGAP = @"\bPREGAP\s+(?<msf>[\d]+:[\d]+:[\d]+)$";
|
||||
const string REGEX_POSTGAP = @"\bPOSTGAP\s+(?<msf>[\d]+:[\d]+:[\d]+)$";
|
||||
const string REGEX_FLAGS = @"\bFLAGS\s+(((?<dcp>DCP)|(?<quad>4CH)|(?<pre>PRE)|(?<scms>SCMS))\s*)+$";
|
||||
}
|
||||
}
|
||||
242
DiscImageChef.DiscImages/CDRWin/Helpers.cs
Normal file
242
DiscImageChef.DiscImages/CDRWin/Helpers.cs
Normal file
@@ -0,0 +1,242 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Helpers.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains helpers for 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
static ulong CdrWinMsftoLba(string msf)
|
||||
{
|
||||
string[] msfElements = msf.Split(':');
|
||||
ulong minute = ulong.Parse(msfElements[0]);
|
||||
ulong second = ulong.Parse(msfElements[1]);
|
||||
ulong frame = ulong.Parse(msfElements[2]);
|
||||
|
||||
ulong sectors = minute * 60 * 75 + second * 75 + frame;
|
||||
|
||||
return sectors;
|
||||
}
|
||||
|
||||
static ushort CdrWinTrackTypeToBytesPerSector(string trackType)
|
||||
{
|
||||
switch(trackType)
|
||||
{
|
||||
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_CDG:
|
||||
case CDRWIN_TRACK_TYPE_CDI_RAW: return 2352;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ushort CdrWinTrackTypeToCookedBytesPerSector(string trackType)
|
||||
{
|
||||
switch(trackType)
|
||||
{
|
||||
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_CDG:
|
||||
case CDRWIN_TRACK_TYPE_AUDIO: return 2352;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static TrackType CdrWinTrackTypeToTrackType(string trackType)
|
||||
{
|
||||
switch(trackType)
|
||||
{
|
||||
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;
|
||||
default: return TrackType.Data;
|
||||
}
|
||||
}
|
||||
|
||||
static MediaType CdrWinIsoBusterDiscTypeToMediaType(string discType)
|
||||
{
|
||||
switch(discType)
|
||||
{
|
||||
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;
|
||||
default: return MediaType.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
static (byte minute, byte second, byte frame) LbaToMsf(ulong sector)
|
||||
{
|
||||
return ((byte)(sector / 75 / 60), (byte)(sector / 75 % 60), (byte)(sector % 75));
|
||||
}
|
||||
|
||||
static string GetTrackMode(Track track)
|
||||
{
|
||||
switch(track.TrackType)
|
||||
{
|
||||
case TrackType.Audio when track.TrackRawBytesPerSector == 2352: return CDRWIN_TRACK_TYPE_AUDIO;
|
||||
case TrackType.Data: return CDRWIN_TRACK_TYPE_MODE1;
|
||||
case TrackType.CdMode1 when track.TrackRawBytesPerSector == 2352: return CDRWIN_TRACK_TYPE_MODE1_RAW;
|
||||
case TrackType.CdMode2Formless
|
||||
when track.TrackRawBytesPerSector != 2352: return CDRWIN_TRACK_TYPE_MODE2_FORMLESS;
|
||||
case TrackType.CdMode2Form1
|
||||
when track.TrackRawBytesPerSector != 2352: return CDRWIN_TRACK_TYPE_MODE2_FORM1;
|
||||
case TrackType.CdMode2Form2
|
||||
when track.TrackRawBytesPerSector != 2352: return CDRWIN_TRACK_TYPE_MODE2_FORM2;
|
||||
case TrackType.CdMode2Formless when track.TrackRawBytesPerSector == 2352:
|
||||
case TrackType.CdMode2Form1 when track.TrackRawBytesPerSector == 2352:
|
||||
case TrackType.CdMode2Form2
|
||||
when track.TrackRawBytesPerSector == 2352: return CDRWIN_TRACK_TYPE_MODE2_RAW;
|
||||
default: return CDRWIN_TRACK_TYPE_MODE1;
|
||||
}
|
||||
}
|
||||
|
||||
static string MediaTypeToCdrwinType(MediaType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case MediaType.BDRXL:
|
||||
case MediaType.BDR: return CDRWIN_DISK_TYPE_BDR;
|
||||
case MediaType.BDREXL:
|
||||
case MediaType.BDRE: return CDRWIN_DISK_TYPE_BDRE;
|
||||
case MediaType.BDROM:
|
||||
case MediaType.CBHD:
|
||||
case MediaType.PS3BD:
|
||||
case MediaType.PS4BD:
|
||||
case MediaType.UDO:
|
||||
case MediaType.UDO2:
|
||||
case MediaType.UDO2_WORM: return CDRWIN_DISK_TYPE_BD;
|
||||
case MediaType.CDV:
|
||||
case MediaType.DDCD:
|
||||
case MediaType.DDCDR:
|
||||
case MediaType.DDCDRW:
|
||||
case MediaType.CDPLUS:
|
||||
case MediaType.CDR:
|
||||
case MediaType.CDROM:
|
||||
case MediaType.CDROMXA:
|
||||
case MediaType.CD:
|
||||
case MediaType.CDDA:
|
||||
case MediaType.CDEG:
|
||||
case MediaType.CDG:
|
||||
case MediaType.CDI:
|
||||
case MediaType.CDMIDI:
|
||||
case MediaType.DTSCD:
|
||||
case MediaType.JaguarCD:
|
||||
case MediaType.MEGACD:
|
||||
case MediaType.PD650:
|
||||
case MediaType.PD650_WORM:
|
||||
case MediaType.PS1CD:
|
||||
case MediaType.PS2CD:
|
||||
case MediaType.SuperCDROM2:
|
||||
case MediaType.SVCD:
|
||||
case MediaType.SVOD:
|
||||
case MediaType.SATURNCD:
|
||||
case MediaType.ThreeDO:
|
||||
case MediaType.VCD:
|
||||
case MediaType.VCDHD: return CDRWIN_DISK_TYPE_CD;
|
||||
case MediaType.CDMRW: return CDRWIN_DISK_TYPE_CDMRW;
|
||||
case MediaType.CDRW: return CDRWIN_DISK_TYPE_CDRW;
|
||||
case MediaType.DVDPR: return CDRWIN_DISK_TYPE_DVDPR;
|
||||
case MediaType.DVDPRDL: return CDRWIN_DISK_TYPE_DVDPRDL;
|
||||
case MediaType.DVDPRW: return CDRWIN_DISK_TYPE_DVDPRW;
|
||||
case MediaType.DVDPRWDL: return CDRWIN_DISK_TYPE_DVDPRWDL;
|
||||
case MediaType.DVDR: return CDRWIN_DISK_TYPE_DVDR;
|
||||
case MediaType.DVDRAM: return CDRWIN_DISK_TYPE_DVDRAM;
|
||||
case MediaType.DVDRDL: return CDRWIN_DISK_TYPE_DVDRDL;
|
||||
case MediaType.DVDDownload:
|
||||
case MediaType.DVDROM:
|
||||
case MediaType.UMD:
|
||||
case MediaType.PS2DVD:
|
||||
case MediaType.PS3DVD: return CDRWIN_DISK_TYPE_DVD;
|
||||
case MediaType.DVDRW: return CDRWIN_DISK_TYPE_DVDRW;
|
||||
case MediaType.DVDRWDL: return CDRWIN_DISK_TYPE_DVDRWDL;
|
||||
case MediaType.HDDVDR: return CDRWIN_DISK_TYPE_HDDVDR;
|
||||
case MediaType.HDDVDRAM: return CDRWIN_DISK_TYPE_HDDVDRAM;
|
||||
case MediaType.HDDVDRDL: return CDRWIN_DISK_TYPE_HDDVDRDL;
|
||||
case MediaType.HDDVDROM: return CDRWIN_DISK_TYPE_HDDVD;
|
||||
case MediaType.HDDVDRW: return CDRWIN_DISK_TYPE_HDDVDRW;
|
||||
case MediaType.HDDVDRWDL: return CDRWIN_DISK_TYPE_HDDVDRWDL;
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
105
DiscImageChef.DiscImages/CDRWin/Identify.cs
Normal file
105
DiscImageChef.DiscImages/CDRWin/Identify.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Identify.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Identifies 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
// Due to .cue format, this method must parse whole file, ignoring errors (those will be thrown by OpenImage()).
|
||||
public bool Identify(IFilter imageFilter)
|
||||
{
|
||||
cdrwinFilter = imageFilter;
|
||||
|
||||
try
|
||||
{
|
||||
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(cdrwinFilter.GetDataForkStream());
|
||||
|
||||
while(cueStream.Peek() >= 0)
|
||||
{
|
||||
string line = cueStream.ReadLine();
|
||||
|
||||
Regex sr = new Regex(REGEX_SESSION);
|
||||
Regex rr = new Regex(REGEX_COMMENT);
|
||||
Regex cr = new Regex(REGEX_MCN);
|
||||
Regex fr = new Regex(REGEX_FILE);
|
||||
Regex tr = new Regex(REGEX_CDTEXT);
|
||||
|
||||
// First line must be SESSION, REM, CATALOG, FILE or CDTEXTFILE.
|
||||
Match sm = sr.Match(line ?? throw new InvalidOperationException());
|
||||
Match rm = rr.Match(line);
|
||||
Match cm = cr.Match(line);
|
||||
Match fm = fr.Match(line);
|
||||
Match tm = tr.Match(line);
|
||||
|
||||
return sm.Success || rm.Success || cm.Success || fm.Success || tm.Success;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Exception trying to identify image file {0}", cdrwinFilter);
|
||||
DicConsole.ErrorWriteLine("Exception: {0}", ex.Message);
|
||||
DicConsole.ErrorWriteLine("Stack trace: {0}", ex.StackTrace);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
129
DiscImageChef.DiscImages/CDRWin/Properties.cs
Normal file
129
DiscImageChef.DiscImages/CDRWin/Properties.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Properties.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains properties for 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
using Schemas;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
public ImageInfo Info => imageInfo;
|
||||
public string Name => "CDRWin cuesheet";
|
||||
public Guid Id => new Guid("664568B2-15D4-4E64-8A7A-20BDA8B8386F");
|
||||
public string Format => "CDRWin CUESheet";
|
||||
public List<Partition> Partitions { get; private set; }
|
||||
public List<Track> Tracks
|
||||
{
|
||||
get
|
||||
{
|
||||
List<Track> tracks = new List<Track>();
|
||||
|
||||
ulong previousStartSector = 0;
|
||||
|
||||
foreach(CdrWinTrack cdrTrack in discimage.Tracks)
|
||||
{
|
||||
Track dicTrack = new Track
|
||||
{
|
||||
Indexes = cdrTrack.Indexes,
|
||||
TrackDescription = cdrTrack.Title,
|
||||
TrackStartSector = previousStartSector,
|
||||
TrackPregap = cdrTrack.Pregap,
|
||||
TrackSession = cdrTrack.Session,
|
||||
TrackSequence = cdrTrack.Sequence,
|
||||
TrackType = CdrWinTrackTypeToTrackType(cdrTrack.Tracktype),
|
||||
TrackFile = cdrTrack.Trackfile.Datafilter.GetFilename(),
|
||||
TrackFilter = cdrTrack.Trackfile.Datafilter,
|
||||
TrackFileOffset = cdrTrack.Trackfile.Offset,
|
||||
TrackFileType = cdrTrack.Trackfile.Filetype,
|
||||
TrackRawBytesPerSector = cdrTrack.Bps,
|
||||
TrackBytesPerSector = CdrWinTrackTypeToCookedBytesPerSector(cdrTrack.Tracktype)
|
||||
};
|
||||
dicTrack.TrackEndSector = dicTrack.TrackStartSector + cdrTrack.Sectors - 1;
|
||||
|
||||
/*if(!cdrTrack.Indexes.TryGetValue(0, out dicTrack.TrackStartSector))
|
||||
cdrTrack.Indexes.TryGetValue(1, out dicTrack.TrackStartSector);*/
|
||||
if(cdrTrack.Tracktype == CDRWIN_TRACK_TYPE_CDG)
|
||||
{
|
||||
dicTrack.TrackSubchannelFilter = cdrTrack.Trackfile.Datafilter;
|
||||
dicTrack.TrackSubchannelFile = cdrTrack.Trackfile.Datafilter.GetFilename();
|
||||
dicTrack.TrackSubchannelOffset = cdrTrack.Trackfile.Offset;
|
||||
dicTrack.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
||||
}
|
||||
else dicTrack.TrackSubchannelType = TrackSubchannelType.None;
|
||||
|
||||
tracks.Add(dicTrack);
|
||||
previousStartSector = dicTrack.TrackEndSector + 1;
|
||||
}
|
||||
|
||||
return tracks;
|
||||
}
|
||||
}
|
||||
public List<Session> Sessions => discimage.Sessions;
|
||||
public List<DumpHardwareType> DumpHardware => null;
|
||||
public CICMMetadataType CicmMetadata => null;
|
||||
public IEnumerable<MediaTagType> SupportedMediaTags => new[] {MediaTagType.CD_MCN, MediaTagType.CD_TEXT};
|
||||
public IEnumerable<SectorTagType> SupportedSectorTags =>
|
||||
new[]
|
||||
{
|
||||
SectorTagType.CdSectorEcc, SectorTagType.CdSectorEccP, SectorTagType.CdSectorEccQ,
|
||||
SectorTagType.CdSectorEdc, SectorTagType.CdSectorHeader, SectorTagType.CdSectorSubHeader,
|
||||
SectorTagType.CdSectorSync, SectorTagType.CdTrackFlags, SectorTagType.CdTrackIsrc
|
||||
};
|
||||
public IEnumerable<MediaType> SupportedMediaTypes =>
|
||||
new[]
|
||||
{
|
||||
MediaType.BDR, MediaType.BDRE, MediaType.BDREXL, MediaType.BDROM, MediaType.BDRXL, MediaType.CBHD,
|
||||
MediaType.CD, MediaType.CDDA, MediaType.CDEG, MediaType.CDG, MediaType.CDI, MediaType.CDMIDI,
|
||||
MediaType.CDMRW, MediaType.CDPLUS, MediaType.CDR, MediaType.CDROM, MediaType.CDROMXA, MediaType.CDRW,
|
||||
MediaType.CDV, MediaType.DDCD, MediaType.DDCDR, MediaType.DDCDRW, MediaType.DVDDownload,
|
||||
MediaType.DVDPR, MediaType.DVDPRDL, MediaType.DVDPRW, MediaType.DVDPRWDL, MediaType.DVDR,
|
||||
MediaType.DVDRAM, MediaType.DVDRDL, MediaType.DVDROM, MediaType.DVDRW, MediaType.DVDRWDL, MediaType.EVD,
|
||||
MediaType.FDDVD, MediaType.DTSCD, MediaType.FVD, MediaType.HDDVDR, MediaType.HDDVDRAM,
|
||||
MediaType.HDDVDRDL, MediaType.HDDVDROM, MediaType.HDDVDRW, MediaType.HDDVDRWDL, MediaType.HDVMD,
|
||||
MediaType.HVD, MediaType.JaguarCD, MediaType.MEGACD, MediaType.PD650, MediaType.PD650_WORM,
|
||||
MediaType.PS1CD, MediaType.PS2CD, MediaType.PS2DVD, MediaType.PS3BD, MediaType.PS3DVD, MediaType.PS4BD,
|
||||
MediaType.SuperCDROM2, MediaType.SVCD, MediaType.SVOD, MediaType.SATURNCD, MediaType.ThreeDO,
|
||||
MediaType.UDO, MediaType.UDO2, MediaType.UDO2_WORM, MediaType.UMD, MediaType.VCD, MediaType.VCDHD,
|
||||
MediaType.NeoGeoCD, MediaType.PCFX
|
||||
};
|
||||
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
||||
new[] {("separate", typeof(bool), "Write each track to a separate file.")};
|
||||
public IEnumerable<string> KnownExtensions => new[] {".cue"};
|
||||
public bool IsWriting { get; private set; }
|
||||
public string ErrorMessage { get; private set; }
|
||||
}
|
||||
}
|
||||
1522
DiscImageChef.DiscImages/CDRWin/Read.cs
Normal file
1522
DiscImageChef.DiscImages/CDRWin/Read.cs
Normal file
File diff suppressed because it is too large
Load Diff
132
DiscImageChef.DiscImages/CDRWin/Structs.cs
Normal file
132
DiscImageChef.DiscImages/CDRWin/Structs.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Structs.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains structures for 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
struct CdrWinTrackFile
|
||||
{
|
||||
/// <summary>Track #</summary>
|
||||
public uint Sequence;
|
||||
/// <summary>Filter of file containing track</summary>
|
||||
public IFilter Datafilter;
|
||||
/// <summary>Offset of track start in file</summary>
|
||||
public ulong Offset;
|
||||
/// <summary>Type of file</summary>
|
||||
public string Filetype;
|
||||
}
|
||||
|
||||
struct CdrWinTrack
|
||||
{
|
||||
/// <summary>Track #</summary>
|
||||
public uint Sequence;
|
||||
/// <summary>Track title (from CD-Text)</summary>
|
||||
public string Title;
|
||||
/// <summary>Track genre (from CD-Text)</summary>
|
||||
public string Genre;
|
||||
/// <summary>Track arranger (from CD-Text)</summary>
|
||||
public string Arranger;
|
||||
/// <summary>Track composer (from CD-Text)</summary>
|
||||
public string Composer;
|
||||
/// <summary>Track performer (from CD-Text)</summary>
|
||||
public string Performer;
|
||||
/// <summary>Track song writer (from CD-Text)</summary>
|
||||
public string Songwriter;
|
||||
/// <summary>Track ISRC</summary>
|
||||
public string Isrc;
|
||||
/// <summary>File struct for this track</summary>
|
||||
public CdrWinTrackFile Trackfile;
|
||||
/// <summary>Indexes on this track</summary>
|
||||
public Dictionary<int, ulong> Indexes;
|
||||
/// <summary>Track pre-gap in sectors</summary>
|
||||
public ulong Pregap;
|
||||
/// <summary>Track post-gap in sectors</summary>
|
||||
public ulong Postgap;
|
||||
/// <summary>Digical Copy Permitted</summary>
|
||||
public bool FlagDcp;
|
||||
/// <summary>Track is quadraphonic</summary>
|
||||
public bool Flag4ch;
|
||||
/// <summary>Track has preemphasis</summary>
|
||||
public bool FlagPre;
|
||||
/// <summary>Track has SCMS</summary>
|
||||
public bool FlagScms;
|
||||
/// <summary>Bytes per sector</summary>
|
||||
public ushort Bps;
|
||||
/// <summary>Sectors in track</summary>
|
||||
public ulong Sectors;
|
||||
/// <summary>Track type</summary>
|
||||
public string Tracktype;
|
||||
/// <summary>Track session</summary>
|
||||
public ushort Session;
|
||||
}
|
||||
|
||||
struct CdrWinDisc
|
||||
{
|
||||
/// <summary>Disk title (from CD-Text)</summary>
|
||||
public string Title;
|
||||
/// <summary>Disk genre (from CD-Text)</summary>
|
||||
public string Genre;
|
||||
/// <summary>Disk arranger (from CD-Text)</summary>
|
||||
public string Arranger;
|
||||
/// <summary>Disk composer (from CD-Text)</summary>
|
||||
public string Composer;
|
||||
/// <summary>Disk performer (from CD-Text)</summary>
|
||||
public string Performer;
|
||||
/// <summary>Disk song writer (from CD-Text)</summary>
|
||||
public string Songwriter;
|
||||
/// <summary>Media catalog number</summary>
|
||||
public string Mcn;
|
||||
/// <summary>Disk type</summary>
|
||||
public MediaType Disktype;
|
||||
/// <summary>Disk type string</summary>
|
||||
public string Disktypestr;
|
||||
/// <summary>Disk CDDB ID</summary>
|
||||
public string DiskId;
|
||||
/// <summary>Disk UPC/EAN</summary>
|
||||
public string Barcode;
|
||||
/// <summary>Sessions</summary>
|
||||
public List<Session> Sessions;
|
||||
/// <summary>Tracks</summary>
|
||||
public List<CdrWinTrack> Tracks;
|
||||
/// <summary>Disk comment</summary>
|
||||
public string Comment;
|
||||
/// <summary>File containing CD-Text</summary>
|
||||
public string Cdtextfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
DiscImageChef.DiscImages/CDRWin/Unsupported.cs
Normal file
42
DiscImageChef.DiscImages/CDRWin/Unsupported.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Unsupported.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains features unsupported by 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
public bool? VerifyMediaImage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
508
DiscImageChef.DiscImages/CDRWin/Write.cs
Normal file
508
DiscImageChef.DiscImages/CDRWin/Write.cs
Normal file
@@ -0,0 +1,508 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Write.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Writes 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
using Schemas;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
public partial class CdrWin
|
||||
{
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
||||
uint sectorSize)
|
||||
{
|
||||
if(options != null)
|
||||
{
|
||||
if(options.TryGetValue("separate", out string tmpValue))
|
||||
{
|
||||
if(!bool.TryParse(tmpValue, out separateTracksWriting))
|
||||
{
|
||||
ErrorMessage = "Invalid value for split option";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(separateTracksWriting)
|
||||
{
|
||||
ErrorMessage = "Separate tracksnot yet implemented";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else separateTracksWriting = false;
|
||||
|
||||
if(!SupportedMediaTypes.Contains(mediaType))
|
||||
{
|
||||
ErrorMessage = $"Unsupport media format {mediaType}";
|
||||
return false;
|
||||
}
|
||||
|
||||
imageInfo = new ImageInfo {MediaType = mediaType, SectorSize = sectorSize, Sectors = sectors};
|
||||
|
||||
// TODO: Separate tracks
|
||||
try
|
||||
{
|
||||
writingBaseName = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));
|
||||
descriptorStream = new StreamWriter(path, false, Encoding.ASCII);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
ErrorMessage = $"Could not create new image file, exception {e.Message}";
|
||||
return false;
|
||||
}
|
||||
|
||||
discimage = new CdrWinDisc
|
||||
{
|
||||
Disktype = mediaType,
|
||||
Sessions = new List<Session>(),
|
||||
Tracks = new List<CdrWinTrack>()
|
||||
};
|
||||
|
||||
trackFlags = new Dictionary<byte, byte>();
|
||||
trackIsrcs = new Dictionary<byte, string>();
|
||||
|
||||
IsWriting = true;
|
||||
ErrorMessage = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WriteMediaTag(byte[] data, MediaTagType tag)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(tag)
|
||||
{
|
||||
case MediaTagType.CD_MCN:
|
||||
discimage.Mcn = Encoding.ASCII.GetString(data);
|
||||
return true;
|
||||
case MediaTagType.CD_TEXT:
|
||||
FileStream cdTextStream = new FileStream(writingBaseName + "_cdtext.bin", FileMode.Create,
|
||||
FileAccess.ReadWrite, FileShare.None);
|
||||
cdTextStream.Write(data, 0, data.Length);
|
||||
discimage.Cdtextfile = Path.GetFileName(cdTextStream.Name);
|
||||
cdTextStream.Close();
|
||||
return true;
|
||||
default:
|
||||
ErrorMessage = $"Unsupported media tag {tag}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
Track track =
|
||||
writingTracks.FirstOrDefault(trk => sectorAddress >= trk.TrackStartSector &&
|
||||
sectorAddress <= trk.TrackEndSector);
|
||||
|
||||
if(track.TrackSequence == 0)
|
||||
{
|
||||
ErrorMessage = $"Can't found track containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
FileStream trackStream = writingStreams.FirstOrDefault(kvp => kvp.Key == track.TrackSequence).Value;
|
||||
|
||||
if(trackStream == null)
|
||||
{
|
||||
ErrorMessage = $"Can't found file containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(track.TrackBytesPerSector != track.TrackRawBytesPerSector)
|
||||
{
|
||||
ErrorMessage = "Invalid write mode for this sector";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(data.Length != track.TrackRawBytesPerSector)
|
||||
{
|
||||
ErrorMessage = "Incorrect data size";
|
||||
return false;
|
||||
}
|
||||
|
||||
trackStream.Seek((long)(track.TrackFileOffset + (sectorAddress - track.TrackStartSector) * (ulong)track.TrackRawBytesPerSector),
|
||||
SeekOrigin.Begin);
|
||||
trackStream.Write(data, 0, data.Length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
Track track =
|
||||
writingTracks.FirstOrDefault(trk => sectorAddress >= trk.TrackStartSector &&
|
||||
sectorAddress <= trk.TrackEndSector);
|
||||
|
||||
if(track.TrackSequence == 0)
|
||||
{
|
||||
ErrorMessage = $"Can't found track containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
FileStream trackStream = writingStreams.FirstOrDefault(kvp => kvp.Key == track.TrackSequence).Value;
|
||||
|
||||
if(trackStream == null)
|
||||
{
|
||||
ErrorMessage = $"Can't found file containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(track.TrackBytesPerSector != track.TrackRawBytesPerSector)
|
||||
{
|
||||
ErrorMessage = "Invalid write mode for this sector";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(sectorAddress + length > track.TrackEndSector + 1)
|
||||
{
|
||||
ErrorMessage = "Can't cross tracks";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(data.Length % track.TrackRawBytesPerSector != 0)
|
||||
{
|
||||
ErrorMessage = "Incorrect data size";
|
||||
return false;
|
||||
}
|
||||
|
||||
trackStream.Seek((long)(track.TrackFileOffset + (sectorAddress - track.TrackStartSector) * (ulong)track.TrackRawBytesPerSector),
|
||||
SeekOrigin.Begin);
|
||||
trackStream.Write(data, 0, data.Length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
Track track =
|
||||
writingTracks.FirstOrDefault(trk => sectorAddress >= trk.TrackStartSector &&
|
||||
sectorAddress <= trk.TrackEndSector);
|
||||
|
||||
if(track.TrackSequence == 0)
|
||||
{
|
||||
ErrorMessage = $"Can't found track containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
FileStream trackStream = writingStreams.FirstOrDefault(kvp => kvp.Key == track.TrackSequence).Value;
|
||||
|
||||
if(trackStream == null)
|
||||
{
|
||||
ErrorMessage = $"Can't found file containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(data.Length != track.TrackRawBytesPerSector)
|
||||
{
|
||||
ErrorMessage = "Incorrect data size";
|
||||
return false;
|
||||
}
|
||||
|
||||
trackStream.Seek((long)(track.TrackFileOffset + (sectorAddress - track.TrackStartSector) * (ulong)track.TrackRawBytesPerSector),
|
||||
SeekOrigin.Begin);
|
||||
trackStream.Write(data, 0, data.Length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
Track track =
|
||||
writingTracks.FirstOrDefault(trk => sectorAddress >= trk.TrackStartSector &&
|
||||
sectorAddress <= trk.TrackEndSector);
|
||||
|
||||
if(track.TrackSequence == 0)
|
||||
{
|
||||
ErrorMessage = $"Can't found track containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
FileStream trackStream = writingStreams.FirstOrDefault(kvp => kvp.Key == track.TrackSequence).Value;
|
||||
|
||||
if(trackStream == null)
|
||||
{
|
||||
ErrorMessage = $"Can't found file containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(sectorAddress + length > track.TrackEndSector + 1)
|
||||
{
|
||||
ErrorMessage = "Can't cross tracks";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(data.Length % track.TrackRawBytesPerSector != 0)
|
||||
{
|
||||
ErrorMessage = "Incorrect data size";
|
||||
return false;
|
||||
}
|
||||
|
||||
trackStream.Seek((long)(track.TrackFileOffset + (sectorAddress - track.TrackStartSector) * (ulong)track.TrackRawBytesPerSector),
|
||||
SeekOrigin.Begin);
|
||||
trackStream.Write(data, 0, data.Length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SetTracks(List<Track> tracks)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tracks == null || tracks.Count == 0)
|
||||
{
|
||||
ErrorMessage = "Invalid tracks sent";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(writingTracks != null && writingStreams != null)
|
||||
foreach(FileStream oldTrack in writingStreams.Select(t => t.Value).Distinct())
|
||||
oldTrack.Close();
|
||||
|
||||
ulong currentOffset = 0;
|
||||
writingTracks = new List<Track>();
|
||||
foreach(Track track in tracks.OrderBy(t => t.TrackSequence))
|
||||
{
|
||||
Track newTrack = track;
|
||||
newTrack.TrackFile = separateTracksWriting
|
||||
? writingBaseName + $"_track{track.TrackSequence:D2}.bin"
|
||||
: writingBaseName + ".bin";
|
||||
newTrack.TrackFileOffset = separateTracksWriting ? 0 : currentOffset;
|
||||
writingTracks.Add(newTrack);
|
||||
currentOffset += (ulong)newTrack.TrackRawBytesPerSector *
|
||||
(newTrack.TrackEndSector - newTrack.TrackStartSector + 1);
|
||||
}
|
||||
|
||||
writingStreams = new Dictionary<uint, FileStream>();
|
||||
if(separateTracksWriting)
|
||||
foreach(Track track in writingTracks)
|
||||
writingStreams.Add(track.TrackSequence,
|
||||
new FileStream(track.TrackFile, FileMode.OpenOrCreate, FileAccess.ReadWrite,
|
||||
FileShare.None));
|
||||
else
|
||||
{
|
||||
FileStream jointstream = new FileStream(writingBaseName + ".bin", FileMode.OpenOrCreate,
|
||||
FileAccess.ReadWrite, FileShare.None);
|
||||
foreach(Track track in writingTracks) writingStreams.Add(track.TrackSequence, jointstream);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Close()
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Image is not opened for writing";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(separateTracksWriting)
|
||||
foreach(FileStream writingStream in writingStreams.Values)
|
||||
{
|
||||
writingStream.Flush();
|
||||
writingStream.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
writingStreams.First().Value.Flush();
|
||||
writingStreams.First().Value.Close();
|
||||
}
|
||||
|
||||
int currentSession = 0;
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(discimage.Comment))
|
||||
{
|
||||
string[] commentLines = discimage.Comment.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach(string line in commentLines) descriptorStream.WriteLine("REM {0}", line);
|
||||
}
|
||||
|
||||
descriptorStream.WriteLine("REM ORIGINAL MEDIA-TYPE {0}", MediaTypeToCdrwinType(imageInfo.MediaType));
|
||||
|
||||
if(!string.IsNullOrEmpty(discimage.Cdtextfile))
|
||||
descriptorStream.WriteLine("CDTEXTFILE \"{0}\"", Path.GetFileName(discimage.Cdtextfile));
|
||||
|
||||
if(!string.IsNullOrEmpty(discimage.Title)) descriptorStream.WriteLine("TITLE {0}", discimage.Title);
|
||||
|
||||
if(!string.IsNullOrEmpty(discimage.Mcn)) descriptorStream.WriteLine("CATALOG {0}", discimage.Mcn);
|
||||
|
||||
if(!string.IsNullOrEmpty(discimage.Barcode)) descriptorStream.WriteLine("UPC_EAN {0}", discimage.Barcode);
|
||||
|
||||
if(!separateTracksWriting)
|
||||
descriptorStream.WriteLine("FILE \"{0}\" BINARY", Path.GetFileName(writingStreams.First().Value.Name));
|
||||
|
||||
foreach(Track track in writingTracks)
|
||||
{
|
||||
if(track.TrackSession > currentSession) descriptorStream.WriteLine("REM SESSION {0}", ++currentSession);
|
||||
|
||||
if(separateTracksWriting)
|
||||
descriptorStream.WriteLine("FILE \"{0}\" BINARY", Path.GetFileName(track.TrackFile));
|
||||
|
||||
(byte minute, byte second, byte frame) msf = LbaToMsf(track.TrackStartSector);
|
||||
descriptorStream.WriteLine(" TRACK {0:D2} {1}", track.TrackSequence, GetTrackMode(track));
|
||||
|
||||
if(trackFlags.TryGetValue((byte)track.TrackSequence, out byte flagsByte))
|
||||
if(flagsByte != 0 && flagsByte != (byte)CdFlags.DataTrack)
|
||||
{
|
||||
CdFlags flags = (CdFlags)flagsByte;
|
||||
descriptorStream.WriteLine(" FLAGS{0}{1}{2}",
|
||||
flags.HasFlag(CdFlags.CopyPermitted) ? " DCP" : "",
|
||||
flags.HasFlag(CdFlags.FourChannel) ? " 4CH" : "",
|
||||
flags.HasFlag(CdFlags.PreEmphasis) ? " PRE" : "");
|
||||
}
|
||||
|
||||
if(trackIsrcs.TryGetValue((byte)track.TrackSequence, out string isrc))
|
||||
descriptorStream.WriteLine(" ISRC {0}", isrc);
|
||||
|
||||
descriptorStream.WriteLine(" INDEX {0:D2} {1:D2}:{2:D2}:{3:D2}", 1, msf.minute, msf.second,
|
||||
msf.frame);
|
||||
}
|
||||
|
||||
descriptorStream.Flush();
|
||||
descriptorStream.Close();
|
||||
|
||||
IsWriting = false;
|
||||
ErrorMessage = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack)
|
||||
{
|
||||
ErrorMessage = "Unsupported feature";
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
ErrorMessage = "Tried to write on a non-writable image";
|
||||
return false;
|
||||
}
|
||||
|
||||
Track track =
|
||||
writingTracks.FirstOrDefault(trk => sectorAddress >= trk.TrackStartSector &&
|
||||
sectorAddress <= trk.TrackEndSector);
|
||||
|
||||
if(track.TrackSequence == 0)
|
||||
{
|
||||
ErrorMessage = $"Can't found track containing {sectorAddress}";
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(tag)
|
||||
{
|
||||
case SectorTagType.CdTrackFlags:
|
||||
{
|
||||
if(data.Length != 1)
|
||||
{
|
||||
ErrorMessage = "Incorrect data size for track flags";
|
||||
return false;
|
||||
}
|
||||
|
||||
trackFlags.Add((byte)track.TrackSequence, data[0]);
|
||||
return true;
|
||||
}
|
||||
case SectorTagType.CdTrackIsrc:
|
||||
{
|
||||
if(data != null) trackIsrcs.Add((byte)track.TrackSequence, Encoding.UTF8.GetString(data));
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
ErrorMessage = $"Unsupported tag type {tag}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
|
||||
{
|
||||
return WriteSectorTag(data, sectorAddress, tag);
|
||||
}
|
||||
|
||||
public bool SetDumpHardware(List<DumpHardwareType> dumpHardware)
|
||||
{
|
||||
// Not supported
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetCicmMetadata(CICMMetadataType metadata)
|
||||
{
|
||||
// Not supported
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetMetadata(ImageInfo metadata)
|
||||
{
|
||||
discimage.Barcode = metadata.MediaBarcode;
|
||||
discimage.Comment = metadata.Comments;
|
||||
discimage.Title = metadata.MediaTitle;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user