1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+
5+ namespace TotalImage . FileSystems . ISO
6+ {
7+ /// <summary>
8+ /// Represents a directory on an ISO 9660 file system
9+ /// </summary>
10+ public class IsoDirectory : Directory
11+ {
12+ /// <summary>
13+ /// The internal file system record for the directory
14+ /// </summary>
15+ protected IsoFileSystemObject Record { get ; }
16+
17+ /// <inheritdoc />
18+ public override string Name { get => Record . FileIdentifier ; set => throw new NotImplementedException ( ) ; }
19+
20+ /// <inheritdoc />
21+ public override FileAttributes Attributes { get => FileAttributes . Directory ; set => throw new NotImplementedException ( ) ; }
22+
23+ /// <inheritdoc />
24+ public override DateTime ? LastAccessTime { get => null ; set => throw new NotImplementedException ( ) ; }
25+
26+ /// <inheritdoc />
27+ public override DateTime ? LastWriteTime { get => Record . RecordingDate ? . LocalDateTime . ToLocalTime ( ) ; set => throw new NotImplementedException ( ) ; }
28+
29+ /// <inheritdoc />
30+ public override DateTime ? CreationTime { get => null ; set => throw new NotImplementedException ( ) ; }
31+
32+ /// <inheritdoc />
33+ public override ulong Length { get => Record . DataLength ; set => throw new NotImplementedException ( ) ; }
34+
35+ /// <inheritdoc />
36+ public override Directory CreateSubdirectory ( string path )
37+ {
38+ throw new NotImplementedException ( ) ;
39+ }
40+
41+ /// <inheritdoc />
42+ public override void Delete ( )
43+ {
44+ throw new NotImplementedException ( ) ;
45+ }
46+
47+ /// <inheritdoc />
48+ public override IEnumerable < FileSystemObject > EnumerateFileSystemObjects ( bool showHidden , bool showDeleted )
49+ {
50+ var fileSystem = ( Iso9660FileSystem ) FileSystem ;
51+ var stream = FileSystem . GetStream ( ) ;
52+
53+ stream . Seek ( fileSystem . PrimaryVolumeDescriptor . LogicalBlockSize * Record . ExtentOffset , SeekOrigin . Begin ) ;
54+
55+ byte [ ] records = new byte [ Record . DataLength ] ;
56+ stream . Read ( records ) ;
57+
58+ int nextRecord = 0 ;
59+ while ( nextRecord < Record . DataLength )
60+ {
61+ byte recordLength = records [ nextRecord ] ;
62+ var record = new IsoFileSystemObject ( records [ nextRecord .. ( nextRecord + recordLength ) ] ) ;
63+ if ( record . FileIdentifier != "" && record . FileIdentifier [ 0 ] != ( char ) 1 )
64+ {
65+ if ( record . FileFlags . HasFlag ( IsoFileFlags . Directory ) )
66+ {
67+ yield return new IsoDirectory ( record , fileSystem , this ) ;
68+ }
69+ else
70+ {
71+ yield return new IsoFile ( record , fileSystem , this ) ;
72+ }
73+ }
74+ nextRecord += recordLength ;
75+ }
76+ }
77+
78+ /// <inheritdoc />
79+ public override void MoveTo ( string path )
80+ {
81+ throw new NotImplementedException ( ) ;
82+ }
83+
84+ /// <summary>
85+ /// Create a directory on an ISO 9660 file system from a file record
86+ /// </summary>
87+ /// <param name="fso">The file system record</param>
88+ /// <param name="fileSystem">The file system containing the directory</param>
89+ /// <param name="parent">The parent directory, if any</param>
90+ public IsoDirectory ( IsoFileSystemObject fso , FileSystem fileSystem , Directory ? parent = null ) : base ( fileSystem , parent )
91+ {
92+ Record = fso ;
93+ }
94+ }
95+ }
0 commit comments