public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length) { if (!IsWriting) { ErrorMessage = "Tried to write on a non-writable image"; return(false); } if (sectorAddress + length > imageInfo.Sectors) { ErrorMessage = "Tried to write past image size"; return(false); } int longSectorSize = imageInfo.MediaType == MediaType.PriamDataTower ? 536 : 532; long givenSectorSize = data.Length / length; switch (givenSectorSize) { case 536: case 532: case 524: case 512: break; default: ErrorMessage = "Incorrect data size"; return(false); } for (uint i = 0; i < length; i++) { byte[] oldTag; byte[] newTag; switch (givenSectorSize - 512) { // Sony tag, convert to Profile case 12 when longSectorSize == 532: oldTag = new byte[12]; Array.Copy(data, givenSectorSize * i + 512, oldTag, 0, 12); newTag = LisaTag.DecodeSonyTag(oldTag)?.ToProfile().GetBytes(); break; // Sony tag, convert to Priam case 12 when longSectorSize == 536: oldTag = new byte[12]; Array.Copy(data, givenSectorSize * i + 512, oldTag, 0, 12); newTag = LisaTag.DecodeSonyTag(oldTag)?.ToPriam().GetBytes(); break; // Profile tag, copy to Profile case 20 when longSectorSize == 532: newTag = new byte[20]; Array.Copy(data, givenSectorSize * i + 512, newTag, 0, 20); break; // Profile tag, convert to Priam case 20 when longSectorSize == 536: oldTag = new byte[20]; Array.Copy(data, givenSectorSize * i + 512, oldTag, 0, 20); newTag = LisaTag.DecodeProfileTag(oldTag)?.ToPriam().GetBytes(); break; // Priam tag, convert to Profile case 24 when longSectorSize == 532: oldTag = new byte[24]; Array.Copy(data, givenSectorSize * i + 512, oldTag, 0, 24); newTag = LisaTag.DecodePriamTag(oldTag)?.ToProfile().GetBytes(); break; // Priam tag, copy to Priam case 12 when longSectorSize == 536: newTag = new byte[24]; Array.Copy(data, givenSectorSize * i + 512, newTag, 0, 24); break; case 0: newTag = null; break; default: ErrorMessage = "Incorrect data size"; return(false); } if (newTag == null) { newTag = new byte[longSectorSize - 512]; } writingStream.Seek(longSectorSize + (long)sectorAddress * longSectorSize, SeekOrigin.Begin); writingStream.Write(data, (int)(givenSectorSize * i), 512); writingStream.Write(newTag, 0, newTag.Length); } ErrorMessage = ""; return(true); }
public bool WriteSectorLong(byte[] data, ulong sectorAddress) { if (!IsWriting) { ErrorMessage = "Tried to write on a non-writable image"; return(false); } if (sectorAddress >= _imageInfo.Sectors) { ErrorMessage = "Tried to write past image size"; return(false); } int longSectorSize = _imageInfo.MediaType == MediaType.PriamDataTower ? 536 : 532; byte[] oldTag; byte[] newTag; switch (data.Length - 512) { // Sony tag, convert to Profile case 12 when longSectorSize == 532: oldTag = new byte[12]; Array.Copy(data, 512, oldTag, 0, 12); newTag = LisaTag.DecodeSonyTag(oldTag)?.ToProfile().GetBytes(); break; // Sony tag, convert to Priam case 12: oldTag = new byte[12]; Array.Copy(data, 512, oldTag, 0, 12); newTag = LisaTag.DecodeSonyTag(oldTag)?.ToPriam().GetBytes(); break; // Profile tag, copy to Profile case 20 when longSectorSize == 532: newTag = new byte[20]; Array.Copy(data, 512, newTag, 0, 20); break; // Profile tag, convert to Priam case 20: oldTag = new byte[20]; Array.Copy(data, 512, oldTag, 0, 20); newTag = LisaTag.DecodeProfileTag(oldTag)?.ToPriam().GetBytes(); break; // Priam tag, convert to Profile case 24 when longSectorSize == 532: oldTag = new byte[24]; Array.Copy(data, 512, oldTag, 0, 24); newTag = LisaTag.DecodePriamTag(oldTag)?.ToProfile().GetBytes(); break; // Priam tag, copy to Priam case 24: newTag = new byte[24]; Array.Copy(data, 512, newTag, 0, 24); break; case 0: newTag = null; break; default: ErrorMessage = "Incorrect data size"; return(false); } newTag ??= new byte[longSectorSize - 512]; _writingStream.Seek(longSectorSize + ((long)sectorAddress * longSectorSize), SeekOrigin.Begin); _writingStream.Write(data, 0, 512); _writingStream.Write(newTag, 0, newTag.Length); ErrorMessage = ""; return(true); }