mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add interface for writing sector tags that are not included in a long sector.
This commit is contained in:
@@ -498,6 +498,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct Anex86Header
|
||||
{
|
||||
|
||||
@@ -177,8 +177,11 @@ namespace DiscImageChef.DiscImages
|
||||
ImageInfo imageInfo;
|
||||
Stream imageStream;
|
||||
/// <summary>Dictionary, index is track #, value is TrackFile</summary>
|
||||
Dictionary<uint, ulong> offsetmap;
|
||||
bool separateTracksWriting;
|
||||
Dictionary<uint, ulong> offsetmap;
|
||||
bool separateTracksWriting;
|
||||
|
||||
Dictionary<byte, byte> trackFlags;
|
||||
Dictionary<byte, string> trackIsrcs;
|
||||
string writingBaseName;
|
||||
Dictionary<uint, FileStream> writingStreams;
|
||||
List<Track> writingTracks;
|
||||
@@ -624,10 +627,10 @@ namespace DiscImageChef.DiscImages
|
||||
throw new
|
||||
FeatureUnsupportedImageException($"Found FLAGS field in incorrect place at line {lineNumber}");
|
||||
|
||||
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";
|
||||
currenttrack.FlagDcp |= matchFlags.Groups["dcp"].Value == "DCP";
|
||||
currenttrack.Flag4ch |= matchFlags.Groups["quad"].Value == "4CH";
|
||||
currenttrack.FlagPre |= matchFlags.Groups["pre"].Value == "PRE";
|
||||
currenttrack.FlagScms |= matchFlags.Groups["scms"].Value == "SCMS";
|
||||
}
|
||||
else if(matchGenre.Success)
|
||||
{
|
||||
@@ -1451,7 +1454,10 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
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:
|
||||
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
|
||||
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
||||
@@ -1903,6 +1909,9 @@ namespace DiscImageChef.DiscImages
|
||||
Tracks = new List<CdrWinTrack>()
|
||||
};
|
||||
|
||||
trackFlags = new Dictionary<byte, byte>();
|
||||
trackIsrcs = new Dictionary<byte, string>();
|
||||
|
||||
IsWriting = true;
|
||||
ErrorMessage = null;
|
||||
return true;
|
||||
@@ -2209,6 +2218,20 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
(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(" FLAGS {0}", isrc);
|
||||
|
||||
descriptorStream.WriteLine(" INDEX {0:D2} {1:D2}:{2:D2}:{3:D2}", 1, msf.minute, msf.second,
|
||||
msf.frame);
|
||||
}
|
||||
@@ -2226,6 +2249,53 @@ namespace DiscImageChef.DiscImages
|
||||
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)
|
||||
{
|
||||
discimage.Barcode = metadata.MediaBarcode;
|
||||
|
||||
@@ -646,6 +646,18 @@ namespace DiscImageChef.DiscImages
|
||||
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")]
|
||||
enum DiskType : byte
|
||||
{
|
||||
|
||||
@@ -1149,6 +1149,18 @@ namespace DiscImageChef.DiscImages
|
||||
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
|
||||
struct Dc42Header
|
||||
{
|
||||
|
||||
@@ -550,6 +550,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct DriFooter
|
||||
{
|
||||
|
||||
@@ -107,9 +107,9 @@ namespace DiscImageChef.DiscImages
|
||||
bool WriteSectors(byte[] data, ulong sectorAddress, uint length);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a sector to the image with tags attached
|
||||
/// Writes a sector to the image with main channel tags attached
|
||||
/// </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>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool WriteSectorLong(byte[] data, ulong sectorAddress);
|
||||
@@ -117,7 +117,7 @@ namespace DiscImageChef.DiscImages
|
||||
/// <summary>
|
||||
/// Writes several sectors to the image
|
||||
/// </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="length">How many sectors to write</param>
|
||||
/// <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>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -542,6 +542,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct HdkHeader
|
||||
{
|
||||
|
||||
@@ -506,6 +506,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct Nhdr0Header
|
||||
{
|
||||
|
||||
@@ -464,6 +464,18 @@ namespace DiscImageChef.DiscImages
|
||||
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()
|
||||
{
|
||||
if(!IsWriting)
|
||||
|
||||
@@ -571,6 +571,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)
|
||||
{
|
||||
byte[] inbuf = Encoding.ASCII.GetBytes(text);
|
||||
|
||||
@@ -544,6 +544,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct SaveDskFHeader
|
||||
{
|
||||
|
||||
@@ -407,6 +407,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -1323,6 +1323,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)
|
||||
{
|
||||
uint checksum = data.Aggregate<byte, uint>(0, (current, b) => current + b);
|
||||
|
||||
@@ -1145,6 +1145,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct VMwareExtentHeader
|
||||
{
|
||||
|
||||
@@ -518,6 +518,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)]
|
||||
struct Virtual98Header
|
||||
{
|
||||
|
||||
@@ -1000,6 +1000,18 @@ namespace DiscImageChef.DiscImages
|
||||
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)
|
||||
{
|
||||
// TODO: Implement
|
||||
|
||||
Reference in New Issue
Block a user