Files
Aaru/Aaru.Images/CloneCD/Write.cs

651 lines
21 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Write.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Writes CloneCD disc images.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes;
using Aaru.CommonTypes.AaruMetadata;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Structs;
using Aaru.Decoders.CD;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
using Aaru.Logging;
using Track = Aaru.CommonTypes.Structs.Track;
2020-02-27 00:33:26 +00:00
using TrackType = Aaru.CommonTypes.Enums.TrackType;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class CloneCd
{
2023-10-03 23:34:59 +01:00
#region IWritableOpticalImage Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize)
{
2022-03-06 13:29:38 +00:00
if(!SupportedMediaTypes.Contains(mediaType))
{
ErrorMessage = string.Format(Localization.Unsupported_media_format_0, mediaType);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
if(negativeSectors != 0)
{
ErrorMessage = Localization.Negative_sectors_are_not_supported;
return false;
}
if(overflowSectors != 0)
{
ErrorMessage = Localization.Overflow_sectors_are_not_supported;
return false;
}
2022-03-06 13:29:38 +00:00
_imageInfo = new ImageInfo
{
MediaType = mediaType,
SectorSize = sectorSize,
Sectors = sectors
};
2022-03-06 13:29:38 +00:00
try
{
2022-03-07 07:36:44 +00:00
_writingBaseName = Path.Combine(Path.GetDirectoryName(path) ?? "", Path.GetFileNameWithoutExtension(path));
2020-07-22 13:20:25 +01:00
2022-03-06 13:29:38 +00:00
_descriptorStream = new StreamWriter(path, false, Encoding.ASCII);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
_dataStream = new FileStream(_writingBaseName + ".img",
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
2022-03-06 13:29:38 +00:00
FileShare.None);
}
catch(IOException ex)
2022-03-06 13:29:38 +00:00
{
ErrorMessage = string.Format(Localization.Could_not_create_new_image_file_exception_0, ex.Message);
AaruLogging.Exception(ex, Localization.Could_not_create_new_image_file_exception_0, ex.Message);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
_imageInfo.MediaType = mediaType;
2022-03-06 13:29:38 +00:00
_trackFlags = new Dictionary<byte, byte>();
2022-03-06 13:29:38 +00:00
IsWriting = true;
ErrorMessage = null;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return true;
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool WriteMediaTag(byte[] data, MediaTagType tag)
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
switch(tag)
{
case MediaTagType.CD_MCN:
_catalog = Encoding.ASCII.GetString(data);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return true;
case MediaTagType.CD_FullTOC:
_fullToc = data;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return true;
default:
ErrorMessage = string.Format(Localization.Unsupported_media_tag_0, tag);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool WriteSector(byte[] data, ulong sectorAddress, bool negative, SectorStatus sectorStatus)
2022-03-06 13:29:38 +00:00
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
if(negative)
{
ErrorMessage = Localization.Unsupported_feature;
return false;
}
2022-03-06 13:29:38 +00:00
// TODO: Implement ECC generation
ErrorMessage = Localization.This_format_requires_sectors_to_be_raw_Generating_ECC_is_not_yet_implemented;
2022-03-06 13:29:38 +00:00
return false;
}
/// <inheritdoc />
public bool WriteSectors(byte[] data, ulong sectorAddress, bool negative, uint length, SectorStatus[] sectorStatus)
2022-03-06 13:29:38 +00:00
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2020-02-29 18:03:35 +00:00
return false;
}
if(negative)
{
ErrorMessage = Localization.Unsupported_feature;
return false;
}
2022-03-06 13:29:38 +00:00
// TODO: Implement ECC generation
ErrorMessage = Localization.This_format_requires_sectors_to_be_raw_Generating_ECC_is_not_yet_implemented;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool WriteSectorLong(byte[] data, ulong sectorAddress, bool negative, SectorStatus sectorStatus)
2022-03-06 13:29:38 +00:00
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2020-02-29 18:03:35 +00:00
return false;
}
if(negative)
{
ErrorMessage = Localization.Unsupported_feature;
return false;
}
2022-03-07 07:36:44 +00:00
Track track = Tracks.FirstOrDefault(trk => sectorAddress >= trk.StartSector && sectorAddress <= trk.EndSector);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(track is null)
{
ErrorMessage = string.Format(Localization.Cant_find_track_containing_0, sectorAddress);
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
if(data.Length != track.RawBytesPerSector)
{
ErrorMessage = Localization.Incorrect_data_size;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2024-05-01 04:05:22 +01:00
_dataStream.Seek((long)(track.FileOffset +
(sectorAddress - track.StartSector) * (ulong)track.RawBytesPerSector),
SeekOrigin.Begin);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
_dataStream.Write(data, 0, data.Length);
2022-03-06 13:29:38 +00:00
return true;
}
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, bool negative, uint length,
SectorStatus[] sectorStatus)
2022-03-06 13:29:38 +00:00
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2022-03-06 13:29:38 +00:00
return false;
}
if(negative)
{
ErrorMessage = Localization.Unsupported_feature;
return false;
}
2022-03-07 07:36:44 +00:00
Track track = Tracks.FirstOrDefault(trk => sectorAddress >= trk.StartSector && sectorAddress <= trk.EndSector);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(track is null)
{
ErrorMessage = string.Format(Localization.Cant_find_track_containing_0, sectorAddress);
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
if(sectorAddress + length > track.EndSector + 1)
{
ErrorMessage = Localization.Cant_cross_tracks;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
if(data.Length % track.RawBytesPerSector != 0)
{
ErrorMessage = Localization.Incorrect_data_size;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2024-05-01 04:05:22 +01:00
_dataStream.Seek((long)(track.FileOffset +
(sectorAddress - track.StartSector) * (ulong)track.RawBytesPerSector),
SeekOrigin.Begin);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
_dataStream.Write(data, 0, data.Length);
2022-03-06 13:29:38 +00:00
return true;
}
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool SetTracks(List<Track> tracks)
{
ulong currentDataOffset = 0;
ulong currentSubchannelOffset = 0;
2024-05-01 04:39:38 +01:00
Tracks = [];
2022-03-06 13:29:38 +00:00
foreach(Track track in tracks.OrderBy(t => t.Sequence))
{
2022-03-06 13:29:38 +00:00
Track newTrack = track;
2022-03-06 13:29:38 +00:00
if(newTrack.Session > 1)
{
2022-03-06 13:29:38 +00:00
Track firstSessionTrack = tracks.FirstOrDefault(t => t.Session == newTrack.Session);
2020-02-29 18:03:35 +00:00
if(firstSessionTrack?.Sequence == newTrack.Sequence && newTrack.Pregap >= 150)
{
2022-03-06 13:29:38 +00:00
newTrack.Pregap -= 150;
newTrack.StartSector += 150;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
uint subchannelSize;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
switch(newTrack.SubchannelType)
{
case TrackSubchannelType.None:
subchannelSize = 0;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
break;
case TrackSubchannelType.Raw:
case TrackSubchannelType.RawInterleaved:
subchannelSize = 96;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
break;
default:
ErrorMessage = string.Format(Localization.Unsupported_subchannel_type_0, newTrack.SubchannelType);
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
newTrack.FileOffset = currentDataOffset;
newTrack.SubchannelOffset = currentSubchannelOffset;
2020-02-29 18:03:35 +00:00
2022-03-07 07:36:44 +00:00
currentDataOffset += (ulong)newTrack.RawBytesPerSector * (newTrack.EndSector - newTrack.StartSector + 1);
2022-03-06 13:29:38 +00:00
currentSubchannelOffset += subchannelSize * (newTrack.EndSector - newTrack.StartSector + 1);
2022-03-06 13:29:38 +00:00
Tracks.Add(newTrack);
}
2022-03-06 13:29:38 +00:00
return true;
}
/// <inheritdoc />
public bool Close()
{
if(!IsWriting)
{
ErrorMessage = Localization.Image_is_not_opened_for_writing;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
_dataStream.Flush();
_dataStream.Close();
2022-03-06 13:29:38 +00:00
_subStream?.Flush();
_subStream?.Close();
2022-03-06 13:29:38 +00:00
FullTOC.CDFullTOC? nullableToc = null;
2022-03-06 13:29:38 +00:00
// Easy, just decode the real toc
if(_fullToc != null)
{
var tmp = new byte[_fullToc.Length + 2];
2022-03-06 13:29:38 +00:00
Array.Copy(BigEndianBitConverter.GetBytes((ushort)_fullToc.Length), 0, tmp, 0, 2);
2023-10-03 23:34:59 +01:00
Array.Copy(_fullToc, 0, tmp, 2, _fullToc.Length);
2022-03-06 13:29:38 +00:00
nullableToc = FullTOC.Decode(tmp);
}
2022-03-06 13:29:38 +00:00
// Not easy, create a toc from scratch
FullTOC.CDFullTOC toc = nullableToc ?? FullTOC.Create(Tracks, _trackFlags, true);
2022-03-06 13:29:38 +00:00
_descriptorStream.WriteLine("[CloneCD]");
_descriptorStream.WriteLine("Version=2");
_descriptorStream.WriteLine("[Disc]");
_descriptorStream.WriteLine("TocEntries={0}", toc.TrackDescriptors.Length);
2023-10-03 23:34:59 +01:00
_descriptorStream.WriteLine("Sessions={0}", toc.LastCompleteSession);
2022-03-06 13:29:38 +00:00
_descriptorStream.WriteLine("DataTracksScrambled=0");
_descriptorStream.WriteLine("CDTextLength=0");
2024-05-01 04:05:22 +01:00
if(!string.IsNullOrEmpty(_catalog)) _descriptorStream.WriteLine("CATALOG={0}", _catalog);
2022-03-06 13:29:38 +00:00
for(var i = 1; i <= toc.LastCompleteSession; i++)
2022-03-06 13:29:38 +00:00
{
_descriptorStream.WriteLine("[Session {0}]", i);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
Track firstSessionTrack = Tracks.FirstOrDefault(t => t.Session == i);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
switch(firstSessionTrack?.Type)
{
2022-03-06 13:29:38 +00:00
case TrackType.Audio:
// CloneCD always writes this value for first track in disc, however the Rainbow Books
// say the first track pregap is no different from other session pregaps, same mode as
// the track they belong to.
_descriptorStream.WriteLine("PreGapMode=0");
break;
case TrackType.Data:
case TrackType.CdMode1:
_descriptorStream.WriteLine("PreGapMode=1");
break;
case TrackType.CdMode2Formless:
case TrackType.CdMode2Form1:
case TrackType.CdMode2Form2:
_descriptorStream.WriteLine("PreGapMode=2");
break;
default:
ErrorMessage = string.Format(Localization.Unexpected_first_session_track_type_0,
firstSessionTrack?.Type.ToString() ?? "null");
2020-06-15 19:19:45 +01:00
2022-03-06 13:29:38 +00:00
return false;
}
2020-06-15 19:19:45 +01:00
2022-03-06 13:29:38 +00:00
_descriptorStream.WriteLine("PreGapSubC=0");
}
2021-09-21 04:55:28 +01:00
for(var i = 0; i < toc.TrackDescriptors.Length; i++)
2022-03-06 13:29:38 +00:00
{
long alba = MsfToLba((toc.TrackDescriptors[i].Min, toc.TrackDescriptors[i].Sec,
toc.TrackDescriptors[i].Frame));
long plba = MsfToLba((toc.TrackDescriptors[i].PMIN, toc.TrackDescriptors[i].PSEC,
toc.TrackDescriptors[i].PFRAME));
2024-05-01 04:05:22 +01:00
if(alba > 405000) alba = (alba - 405000 + 300) * -1;
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
if(plba > 405000) plba = (plba - 405000 + 300) * -1;
2022-03-06 13:29:38 +00:00
2023-10-03 23:34:59 +01:00
_descriptorStream.WriteLine("[Entry {0}]", i);
_descriptorStream.WriteLine("Session={0}", toc.TrackDescriptors[i].SessionNumber);
_descriptorStream.WriteLine("Point=0x{0:x2}", toc.TrackDescriptors[i].POINT);
_descriptorStream.WriteLine("ADR=0x{0:x2}", toc.TrackDescriptors[i].ADR);
2022-03-06 13:29:38 +00:00
_descriptorStream.WriteLine("Control=0x{0:x2}", toc.TrackDescriptors[i].CONTROL);
2023-10-03 23:34:59 +01:00
_descriptorStream.WriteLine("TrackNo={0}", toc.TrackDescriptors[i].TNO);
_descriptorStream.WriteLine("AMin={0}", toc.TrackDescriptors[i].Min);
_descriptorStream.WriteLine("ASec={0}", toc.TrackDescriptors[i].Sec);
_descriptorStream.WriteLine("AFrame={0}", toc.TrackDescriptors[i].Frame);
_descriptorStream.WriteLine("ALBA={0}", alba);
2022-03-06 13:29:38 +00:00
_descriptorStream.WriteLine("Zero={0}",
((toc.TrackDescriptors[i].HOUR & 0x0F) << 4) +
(toc.TrackDescriptors[i].PHOUR & 0x0F));
2023-10-03 23:34:59 +01:00
_descriptorStream.WriteLine("PMin={0}", toc.TrackDescriptors[i].PMIN);
_descriptorStream.WriteLine("PSec={0}", toc.TrackDescriptors[i].PSEC);
2022-03-06 13:29:38 +00:00
_descriptorStream.WriteLine("PFrame={0}", toc.TrackDescriptors[i].PFRAME);
2023-10-03 23:34:59 +01:00
_descriptorStream.WriteLine("PLBA={0}", plba);
2022-03-06 13:29:38 +00:00
}
2020-06-15 19:19:45 +01:00
2022-03-06 13:29:38 +00:00
_descriptorStream.Flush();
_descriptorStream.Close();
2022-03-06 13:29:38 +00:00
IsWriting = false;
ErrorMessage = "";
2022-03-06 13:29:38 +00:00
return true;
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool SetImageInfo(ImageInfo imageInfo) => true;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack)
{
ErrorMessage = Localization.Unsupported_feature;
2022-03-06 13:29:38 +00:00
return false;
}
/// <inheritdoc />
public bool WriteSectorTag(byte[] data, ulong sectorAddress, bool negative, SectorTagType tag)
2022-03-06 13:29:38 +00:00
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
if(negative)
{
ErrorMessage = Localization.Unsupported_feature;
return false;
}
2022-03-07 07:36:44 +00:00
Track track = Tracks.FirstOrDefault(trk => sectorAddress >= trk.StartSector && sectorAddress <= trk.EndSector);
2022-03-06 13:29:38 +00:00
if(track is null)
{
ErrorMessage = string.Format(Localization.Cant_find_track_containing_0, sectorAddress);
2020-02-29 18:03:35 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
switch(tag)
{
2022-03-06 13:29:38 +00:00
case SectorTagType.CdTrackFlags:
{
2022-03-06 13:29:38 +00:00
if(data.Length != 1)
{
ErrorMessage = Localization.Incorrect_data_size_for_track_flags;
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
_trackFlags[(byte)sectorAddress] = data[0];
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return true;
}
2022-03-06 13:29:38 +00:00
case SectorTagType.CdSectorSubchannel:
{
2022-03-06 13:29:38 +00:00
if(track.SubchannelType == 0)
{
ErrorMessage =
string.Format(Localization.Trying_to_write_subchannel_to_track_0_that_does_not_have_subchannel,
track.Sequence);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
if(data.Length != 96)
{
ErrorMessage = Localization.Incorrect_data_size_for_subchannel;
2022-03-06 13:29:38 +00:00
return false;
}
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(_subStream == null)
2023-10-03 23:34:59 +01:00
{
2022-03-06 13:29:38 +00:00
try
{
2024-05-01 04:05:22 +01:00
_subStream = new FileStream(_writingBaseName + ".sub",
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.None);
}
catch(IOException ex)
{
ErrorMessage = string.Format(Localization.Could_not_create_subchannel_file_exception_0,
ex.Message);
2024-05-01 04:05:22 +01:00
AaruLogging.Exception(ex,
Localization.Could_not_create_subchannel_file_exception_0,
ex.Message);
2020-02-29 18:03:35 +00:00
return false;
}
2023-10-03 23:34:59 +01:00
}
2023-10-03 23:34:59 +01:00
_subStream.Seek((long)(track.SubchannelOffset + (sectorAddress - track.StartSector) * 96),
2022-03-06 13:29:38 +00:00
SeekOrigin.Begin);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
_subStream.Write(Subchannel.Deinterleave(data), 0, data.Length);
2022-03-06 13:29:38 +00:00
return true;
}
default:
ErrorMessage = string.Format(Localization.Unsupported_tag_type_0, tag);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, bool negative, uint length, SectorTagType tag)
2022-03-06 13:29:38 +00:00
{
if(!IsWriting)
{
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
if(negative)
{
ErrorMessage = Localization.Unsupported_feature;
return false;
}
2022-03-07 07:36:44 +00:00
Track track = Tracks.FirstOrDefault(trk => sectorAddress >= trk.StartSector && sectorAddress <= trk.EndSector);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(track is null)
{
ErrorMessage = string.Format(Localization.Cant_find_track_containing_0, sectorAddress);
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
switch(tag)
{
case SectorTagType.CdTrackFlags:
2023-10-03 23:34:59 +01:00
case SectorTagType.CdTrackIsrc:
return WriteSectorTag(data, sectorAddress, false, tag);
2022-03-06 13:29:38 +00:00
case SectorTagType.CdSectorSubchannel:
{
2022-03-06 13:29:38 +00:00
if(track.SubchannelType == 0)
{
ErrorMessage =
string.Format(Localization.Trying_to_write_subchannel_to_track_0_that_does_not_have_subchannel,
track.Sequence);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
if(data.Length % 96 != 0)
{
ErrorMessage = Localization.Incorrect_data_size_for_subchannel;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
if(_subStream == null)
2023-10-03 23:34:59 +01:00
{
2022-03-06 13:29:38 +00:00
try
{
2024-05-01 04:05:22 +01:00
_subStream = new FileStream(_writingBaseName + ".sub",
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.None);
2022-03-06 13:29:38 +00:00
}
catch(IOException ex)
{
ErrorMessage = string.Format(Localization.Could_not_create_subchannel_file_exception_0,
ex.Message);
2024-05-01 04:05:22 +01:00
AaruLogging.Exception(ex,
Localization.Could_not_create_subchannel_file_exception_0,
ex.Message);
2020-02-29 18:03:35 +00:00
return false;
}
2023-10-03 23:34:59 +01:00
}
2023-10-03 23:34:59 +01:00
_subStream.Seek((long)(track.SubchannelOffset + (sectorAddress - track.StartSector) * 96),
2022-03-06 13:29:38 +00:00
SeekOrigin.Begin);
2022-03-06 13:29:38 +00:00
_subStream.Write(Subchannel.Deinterleave(data), 0, data.Length);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return true;
}
2022-03-06 13:29:38 +00:00
default:
ErrorMessage = string.Format(Localization.Unsupported_tag_type_0, tag);
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool SetDumpHardware(List<DumpHardware> dumpHardware) => false;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool SetMetadata(Metadata metadata) => false;
2023-10-03 23:34:59 +01:00
#endregion
}