Add interface for writing sector tags that are not included in a long sector.

This commit is contained in:
2018-01-01 22:19:31 +00:00
parent aa493b53e5
commit f407774c7c
17 changed files with 403 additions and 10 deletions

View File

@@ -498,6 +498,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Anex86Header struct Anex86Header
{ {

View File

@@ -177,8 +177,11 @@ namespace DiscImageChef.DiscImages
ImageInfo imageInfo; ImageInfo imageInfo;
Stream imageStream; Stream imageStream;
/// <summary>Dictionary, index is track #, value is TrackFile</summary> /// <summary>Dictionary, index is track #, value is TrackFile</summary>
Dictionary<uint, ulong> offsetmap; Dictionary<uint, ulong> offsetmap;
bool separateTracksWriting; bool separateTracksWriting;
Dictionary<byte, byte> trackFlags;
Dictionary<byte, string> trackIsrcs;
string writingBaseName; string writingBaseName;
Dictionary<uint, FileStream> writingStreams; Dictionary<uint, FileStream> writingStreams;
List<Track> writingTracks; List<Track> writingTracks;
@@ -624,10 +627,10 @@ namespace DiscImageChef.DiscImages
throw new throw new
FeatureUnsupportedImageException($"Found FLAGS field in incorrect place at line {lineNumber}"); FeatureUnsupportedImageException($"Found FLAGS field in incorrect place at line {lineNumber}");
currenttrack.FlagDcp |= matchFile.Groups["dcp"].Value == "DCP"; currenttrack.FlagDcp |= matchFlags.Groups["dcp"].Value == "DCP";
currenttrack.Flag4ch |= matchFile.Groups["quad"].Value == "4CH"; currenttrack.Flag4ch |= matchFlags.Groups["quad"].Value == "4CH";
currenttrack.FlagPre |= matchFile.Groups["pre"].Value == "PRE"; currenttrack.FlagPre |= matchFlags.Groups["pre"].Value == "PRE";
currenttrack.FlagScms |= matchFile.Groups["scms"].Value == "SCMS"; currenttrack.FlagScms |= matchFlags.Groups["scms"].Value == "SCMS";
} }
else if(matchGenre.Success) else if(matchGenre.Success)
{ {
@@ -1451,7 +1454,10 @@ namespace DiscImageChef.DiscImages
return new[] {(byte)flags}; return new[] {(byte)flags};
} }
case SectorTagType.CdTrackIsrc: return Encoding.UTF8.GetBytes(dicTrack.Isrc); case SectorTagType.CdTrackIsrc:
if(dicTrack.Isrc == null) return null;
return Encoding.UTF8.GetBytes(dicTrack.Isrc);
case SectorTagType.CdTrackText: case SectorTagType.CdTrackText:
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented"); throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
default: throw new ArgumentException("Unsupported tag requested", nameof(tag)); default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
@@ -1903,6 +1909,9 @@ namespace DiscImageChef.DiscImages
Tracks = new List<CdrWinTrack>() Tracks = new List<CdrWinTrack>()
}; };
trackFlags = new Dictionary<byte, byte>();
trackIsrcs = new Dictionary<byte, string>();
IsWriting = true; IsWriting = true;
ErrorMessage = null; ErrorMessage = null;
return true; return true;
@@ -2209,6 +2218,20 @@ namespace DiscImageChef.DiscImages
(byte minute, byte second, byte frame) msf = LbaToMsf(track.TrackStartSector); (byte minute, byte second, byte frame) msf = LbaToMsf(track.TrackStartSector);
descriptorStream.WriteLine(" TRACK {0:D2} {1}", track.TrackSequence, GetTrackMode(track)); 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(" FLAGS {0}", isrc);
descriptorStream.WriteLine(" INDEX {0:D2} {1:D2}:{2:D2}:{3:D2}", 1, msf.minute, msf.second, descriptorStream.WriteLine(" INDEX {0:D2} {1:D2}:{2:D2}:{3:D2}", 1, msf.minute, msf.second,
msf.frame); msf.frame);
} }
@@ -2226,6 +2249,53 @@ namespace DiscImageChef.DiscImages
return false; 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)
{
throw new NotImplementedException();
}
public bool SetMetadata(ImageInfo metadata) public bool SetMetadata(ImageInfo metadata)
{ {
discimage.Barcode = metadata.MediaBarcode; discimage.Barcode = metadata.MediaBarcode;

View File

@@ -646,6 +646,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "InconsistentNaming")]
enum DiskType : byte enum DiskType : byte
{ {

View File

@@ -1149,6 +1149,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
// DiskCopy 4.2 header, big-endian, data-fork, start of file, 84 bytes // DiskCopy 4.2 header, big-endian, data-fork, start of file, 84 bytes
struct Dc42Header struct Dc42Header
{ {

View File

@@ -550,6 +550,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DriFooter struct DriFooter
{ {

View File

@@ -107,9 +107,9 @@ namespace DiscImageChef.DiscImages
bool WriteSectors(byte[] data, ulong sectorAddress, uint length); bool WriteSectors(byte[] data, ulong sectorAddress, uint length);
/// <summary> /// <summary>
/// Writes a sector to the image with tags attached /// Writes a sector to the image with main channel tags attached
/// </summary> /// </summary>
/// <param name="data">Sector data with its tags attached</param> /// <param name="data">Sector data with its main channel tags attached</param>
/// <param name="sectorAddress">Sector address</param> /// <param name="sectorAddress">Sector address</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns> /// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool WriteSectorLong(byte[] data, ulong sectorAddress); bool WriteSectorLong(byte[] data, ulong sectorAddress);
@@ -117,7 +117,7 @@ namespace DiscImageChef.DiscImages
/// <summary> /// <summary>
/// Writes several sectors to the image /// Writes several sectors to the image
/// </summary> /// </summary>
/// <param name="data">Sector data with their tags attached</param> /// <param name="data">Sector data with their main channel tags attached</param>
/// <param name="sectorAddress">Sector starting address</param> /// <param name="sectorAddress">Sector starting address</param>
/// <param name="length">How many sectors to write</param> /// <param name="length">How many sectors to write</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns> /// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
@@ -151,5 +151,24 @@ namespace DiscImageChef.DiscImages
/// <param name="sectorsPerTrack">Sectors per track</param> /// <param name="sectorsPerTrack">Sectors per track</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns> /// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack); bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack);
/// <summary>
/// Writes parallel or subchannel sector tag for one sector
/// </summary>
/// <param name="data">Tag data to write</param>
/// <param name="sectorAddress">Sector address</param>
/// <param name="tag">Tag type</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag);
/// <summary>
/// Writes parallel or subchannel sector tag for several sector
/// </summary>
/// <param name="data">Tag data to write</param>
/// <param name="sectorAddress">Starting sector address</param>
/// <param name="length">How many sectors to write</param>
/// <param name="tag">Tag type</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag);
} }
} }

View File

@@ -542,6 +542,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct HdkHeader struct HdkHeader
{ {

View File

@@ -506,6 +506,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Nhdr0Header struct Nhdr0Header
{ {

View File

@@ -464,6 +464,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool Close() public bool Close()
{ {
if(!IsWriting) if(!IsWriting)

View File

@@ -571,6 +571,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
static byte[] ScrambleATAString(string text, int length) static byte[] ScrambleATAString(string text, int length)
{ {
byte[] inbuf = Encoding.ASCII.GetBytes(text); byte[] inbuf = Encoding.ASCII.GetBytes(text);

View File

@@ -544,6 +544,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct SaveDskFHeader struct SaveDskFHeader
{ {

View File

@@ -407,6 +407,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool SetMetadata(ImageInfo metadata) public bool SetMetadata(ImageInfo metadata)
{ {
return true; return true;

View File

@@ -1323,6 +1323,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
static uint VhdChecksum(IEnumerable<byte> data) static uint VhdChecksum(IEnumerable<byte> data)
{ {
uint checksum = data.Aggregate<byte, uint>(0, (current, b) => current + b); uint checksum = data.Aggregate<byte, uint>(0, (current, b) => current + b);

View File

@@ -1145,6 +1145,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct VMwareExtentHeader struct VMwareExtentHeader
{ {

View File

@@ -518,6 +518,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Virtual98Header struct Virtual98Header
{ {

View File

@@ -1000,6 +1000,18 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
{
ErrorMessage = "Unsupported feature";
return false;
}
public bool WriteMediaTag(byte[] data, MediaTagType tag) public bool WriteMediaTag(byte[] data, MediaTagType tag)
{ {
// TODO: Implement // TODO: Implement

View File

@@ -321,6 +321,69 @@ namespace DiscImageChef.Commands
DicConsole.Write("\rConverting sectors {0} to {1} ({2:P2} done)", inputFormat.Info.Sectors, DicConsole.Write("\rConverting sectors {0} to {1} ({2:P2} done)", inputFormat.Info.Sectors,
inputFormat.Info.Sectors, 1.0); inputFormat.Info.Sectors, 1.0);
DicConsole.WriteLine(); DicConsole.WriteLine();
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags)
{
if(!useLong) break;
switch(tag)
{
case SectorTagType.AppleSectorTag:
case SectorTagType.CdSectorSync:
case SectorTagType.CdSectorHeader:
case SectorTagType.CdSectorSubHeader:
case SectorTagType.CdSectorEdc:
case SectorTagType.CdSectorEccP:
case SectorTagType.CdSectorEccQ:
case SectorTagType.CdSectorEcc:
// This tags are inline in long sector
continue;
}
doneSectors = 0;
while(doneSectors < inputFormat.Info.Sectors)
{
byte[] sector;
uint sectorsToDo;
if(inputFormat.Info.Sectors - doneSectors >= (ulong)options.Count)
sectorsToDo = (uint)options.Count;
else sectorsToDo = (uint)(inputFormat.Info.Sectors - doneSectors);
DicConsole.Write("\rConverting tag {2} for sectors {0} to {1} ({2:P2} done)", doneSectors,
doneSectors + sectorsToDo, doneSectors / (double)inputFormat.Info.Sectors,
tag);
bool result;
if(sectorsToDo == 1)
{
sector = inputFormat.ReadSectorTag(doneSectors, tag);
result = outputFormat.WriteSectorTag(sector, doneSectors, tag);
}
else
{
sector = inputFormat.ReadSectorsTag(doneSectors, sectorsToDo, tag);
result = outputFormat.WriteSectorsTag(sector, doneSectors, sectorsToDo, tag);
}
if(!result)
if(options.Force)
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
outputFormat.ErrorMessage, doneSectors);
else
{
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
return;
}
doneSectors += sectorsToDo;
}
DicConsole.Write("\rConverting tag {2} for sectors {0} to {1} ({2:P2} done)",
inputFormat.Info.Sectors, inputFormat.Info.Sectors, 1.0, tag);
DicConsole.WriteLine();
}
} }
else else
foreach(Track track in tracks) foreach(Track track in tracks)
@@ -389,6 +452,79 @@ namespace DiscImageChef.Commands
DicConsole.Write("\rConverting sectors {0} to {1} in track {3} ({2:P2} done)", trackSectors, DicConsole.Write("\rConverting sectors {0} to {1} in track {3} ({2:P2} done)", trackSectors,
trackSectors, 1.0, track.TrackSequence); trackSectors, 1.0, track.TrackSequence);
DicConsole.WriteLine(); DicConsole.WriteLine();
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags)
{
if(!useLong) break;
doneSectors = 0;
byte[] sector;
bool result;
switch(tag)
{
case SectorTagType.AppleSectorTag:
case SectorTagType.CdSectorSync:
case SectorTagType.CdSectorHeader:
case SectorTagType.CdSectorSubHeader:
case SectorTagType.CdSectorEdc:
case SectorTagType.CdSectorEccP:
case SectorTagType.CdSectorEccQ:
case SectorTagType.CdSectorEcc:
// This tags are inline in long sector
continue;
case SectorTagType.CdTrackFlags:
case SectorTagType.CdTrackIsrc:
DicConsole.Write("\rConverting tag {0} in track {1}.", tag, track.TrackSequence);
DicConsole.WriteLine();
sector = inputFormat.ReadSectorTag(track.TrackStartSector, tag);
result = outputFormat.WriteSectorTag(sector, track.TrackStartSector, tag);
continue;
}
while(doneSectors < trackSectors)
{
uint sectorsToDo;
if(trackSectors - doneSectors >= (ulong)options.Count) sectorsToDo = (uint)options.Count;
else
sectorsToDo =
(uint)(trackSectors - doneSectors);
DicConsole.Write("\rConverting tag {4} for sectors {0} to {1} in track {3} ({2:P2} done)",
doneSectors, doneSectors + sectorsToDo, doneSectors / (double)trackSectors,
track.TrackSequence, tag);
if(sectorsToDo == 1)
{
sector = inputFormat.ReadSectorTag(doneSectors + track.TrackStartSector, tag);
result = outputFormat.WriteSectorTag(sector, doneSectors + track.TrackStartSector, tag);
}
else
{
sector = inputFormat.ReadSectorsTag(doneSectors + track.TrackStartSector, sectorsToDo,
tag);
result = outputFormat.WriteSectorsTag(sector, doneSectors + track.TrackStartSector,
sectorsToDo, tag);
}
if(!result)
if(options.Force)
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
outputFormat.ErrorMessage, doneSectors);
else
{
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
return;
}
doneSectors += sectorsToDo;
}
DicConsole.Write("\rConverting tag {4} for sectors {0} to {1} in track {3} ({2:P2} done)",
trackSectors, trackSectors, 1.0, track.TrackSequence, tag);
DicConsole.WriteLine();
}
} }
if(tracks == null) if(tracks == null)