public void Write(BinaryWriter writer, VolumeType type) { DirectoryRecordWrapper record; UInt32 extent = (type == VolumeType.Primary) ? Extent1 : Extent2; UInt32 size = (type == VolumeType.Primary) ? Size1 : Size2; UInt32 parentExtent = (type == VolumeType.Primary) ? Parent.Extent1 : Parent.Extent2; UInt32 parentSize = (type == VolumeType.Primary) ? Parent.Size1 : Parent.Size2; // First write the current directory and the parent. ("." and "..") record = new DirectoryRecordWrapper(extent, size, Date, IsDirectory, "."); record.Write(writer); record = new DirectoryRecordWrapper(parentExtent, parentSize, Parent.Date, Parent.IsDirectory, ".."); record.Write(writer); // Everything else is written after the first two sectors (current dir and parent). int position = 2 * IsoAlgorithm.DefaultDirectoryRecordLength; foreach (IsoFolderElement child in Children) { UInt32 childExtent = (type == VolumeType.Primary) ? child.Extent1 : child.Extent2; UInt32 childSize = (type == VolumeType.Primary) ? child.Size1 : child.Size2; string childName = (type == VolumeType.Primary) ? child.ShortName : child.LongName; record = new DirectoryRecordWrapper(childExtent, childSize, child.Date, child.IsDirectory, childName) { VolumeDescriptorType = type }; if (record.Length + position > IsoAlgorithm.SectorSize) { writer.Write(new byte[IsoAlgorithm.SectorSize - position]); position = 0; } position += record.Write(writer); } writer.Write(new byte[IsoAlgorithm.SectorSize - position]); }
public void WriteDemoImage(BinaryWriter writer) { int currentSector; for (currentSector = 0; currentSector < 16; currentSector++) { IsoAlgorithm.WriteEmptySector(writer); } DirectoryRecordWrapper rootDir = new DirectoryRecordWrapper(19, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); VolumeDescriptorWrapper volumeDescriptor = new VolumeDescriptorWrapper("EPURASU", 28, 26, 21, 22, rootDir, DateTime.Now, DateTime.Now.Subtract(TimeSpan.FromDays(2)), 8); //rootDir.SetDirectoryRecord( 19, ISO9660.SectorSize, DateTime.Now, true, "." ); // [ Sect 16 ] Primary volume descriptor volumeDescriptor.VolumeDescriptorType = VolumeType.Primary; // volumeDescriptor.SetVolumeDescriptor( "EPURASU", 28, 26, 21, 22, rootDir, DateTime.Now, DateTime.Now.Subtract( TimeSpan.FromDays( 2 ) ), 8 ); volumeDescriptor.Write(writer); // [ Sect 17 ] Suplementary volume descriptor (in care scriem cu unicode) rootDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); volumeDescriptor.VolumeDescriptorType = VolumeType.Suplementary; volumeDescriptor.SetVolumeDescriptor("Epurasu", 28, 38, 25, 26, rootDir, DateTime.Now, DateTime.Now.Subtract(TimeSpan.FromDays(2)), 8); volumeDescriptor.Write(writer); // [ Sect 18 ] Volume descriptor set termnator volumeDescriptor.VolumeDescriptorType = VolumeType.SetTerminator; volumeDescriptor.Write(writer); // [ Sect 19 ] Continutul directorului radacina: // Directorul curent: "." rootDir.SetDirectoryRecord(19, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); rootDir.Write(writer); // Directorul parinte: "..". Fiind vorba de radacina, directorul parinte e o referinta la directorul curent. rootDir.SetDirectoryRecord(19, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); rootDir.Write(writer); // Director copil: "Director" DirectoryRecordWrapper childDir = new DirectoryRecordWrapper(20, IsoAlgorithm.SectorSize, DateTime.Now, true, "DIRECTOR"); //childDir.SetDirectoryRecord( 20, ISO9660.SectorSize, DateTime.Now, true, "DIRECTOR" ); int bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 20 ] Continutul directorului "Director" childDir.SetDirectoryRecord(20, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); childDir.Write(writer); childDir.SetDirectoryRecord(19, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); childDir.Write(writer); childDir.SetDirectoryRecord(27, 45, DateTime.Now, false, "NUMELEFI.TXT"); bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 21 ] Pathtable pt little endian // Root: PathTableRecordWrapper record = new PathTableRecordWrapper(); record.Endian = Endian.LittleEndian; record.SetPathTableRecord(19, 1, "."); bytesWritten = record.Write(writer); // "Director": record.SetPathTableRecord(20, 1, "DIRECTOR"); bytesWritten += record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 22 ] Pathtable pt big endian // Root: record = new PathTableRecordWrapper(); record.Endian = Endian.BigEndian; record.SetPathTableRecord(19, 1, "."); record.Write(writer); // "Director": record.SetPathTableRecord(20, 1, "DIRECTOR"); record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 23 ] Continutul directorului radacina: rootDir.VolumeDescriptorType = VolumeType.Suplementary; // Directorul curent: "." rootDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); rootDir.Write(writer); // Directorul parinte: "..". Fiind vorba de radacina, directorul parinte e o referinta la directorul curent. rootDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); rootDir.Write(writer); // Director copil: "Director" childDir = new DirectoryRecordWrapper(24, IsoAlgorithm.SectorSize, DateTime.Now, true, "Directorul"); //childDir.SetDirectoryRecord( 24, ISO9660.SectorSize, DateTime.Now, true, "Directorul" ); childDir.VolumeDescriptorType = VolumeType.Suplementary; bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 24 ] Continutul directorului "Director" childDir.SetDirectoryRecord(24, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); childDir.Write(writer); childDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); childDir.Write(writer); childDir.SetDirectoryRecord(27, 45, DateTime.Now, false, "numeleFisierului.txt"); bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 25 ] Pathtable pt little endian // Root: record = new PathTableRecordWrapper(); record.Endian = Endian.LittleEndian; record.VolumeDescriptorType = VolumeType.Suplementary; record.SetPathTableRecord(23, 1, "."); bytesWritten = record.Write(writer); // "Director": record.SetPathTableRecord(24, 1, "Directorul"); bytesWritten += record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 26 ] Pathtable pt big endian // Root: record = new PathTableRecordWrapper(); record.Endian = Endian.BigEndian; record.VolumeDescriptorType = VolumeType.Suplementary; record.SetPathTableRecord(23, 1, "."); record.Write(writer); // "Director": record.SetPathTableRecord(24, 1, "Directorul"); record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 27 ] Continutul fisierului (45 B): writer.Write(IsoAlgorithm.StringToByteArray("Catelus cu parul cretz fura ratza din cotetz.")); writer.Write(new byte[2048 - 45]); }