|
6 | 6 |
|
7 | 7 | use PhpIso\Descriptor\Reader; |
8 | 8 | use PhpIso\Descriptor\Type; |
| 9 | +use PhpIso\Descriptor\UdfDescriptor; |
| 10 | +use PhpIso\Descriptor\UdfType; |
9 | 11 |
|
10 | 12 | class IsoFile |
11 | 13 | { |
@@ -86,11 +88,46 @@ protected function processFile(): bool |
86 | 88 |
|
87 | 89 | $reader = new Reader($this); |
88 | 90 |
|
89 | | - while (($descriptor = $reader->read()) !== null) { |
90 | | - $this->descriptors[$descriptor->getType()] = $descriptor; |
| 91 | + $foundTerminator = false; |
| 92 | + while (true) { |
| 93 | + try { |
| 94 | + $descriptor = $reader->read(); |
| 95 | + |
| 96 | + if ($descriptor === null) { |
| 97 | + throw new Exception('Finished reading'); |
| 98 | + } |
| 99 | + |
| 100 | + if (isset($this->descriptors[$descriptor->getType()])) { |
| 101 | + throw new Exception('Descriptor already exists'); |
| 102 | + } |
| 103 | + |
| 104 | + $this->descriptors[$descriptor->getType()] = $descriptor; |
| 105 | + } catch (Exception $ex) { |
| 106 | + if ($foundTerminator) { |
| 107 | + break; |
| 108 | + } |
| 109 | + throw $ex; |
| 110 | + } |
| 111 | + |
| 112 | + // If it's a UDF descriptor, handle it separately |
| 113 | + if ($descriptor instanceof UdfDescriptor) { |
| 114 | + if ($descriptor->udfType === UdfType::TEA01) { |
| 115 | + break; // Stop at Terminating Extended Area Descriptor |
| 116 | + } |
| 117 | + } else { |
| 118 | + if ($foundTerminator) { |
| 119 | + break; |
| 120 | + } |
| 121 | + } |
91 | 122 |
|
92 | 123 | if ($descriptor->getType() === Type::TERMINATOR_DESC) { |
93 | | - break; |
| 124 | + if ($foundTerminator) { |
| 125 | + break; |
| 126 | + } |
| 127 | + |
| 128 | + $foundTerminator = true; |
| 129 | + // Keep going if UDF might still be present |
| 130 | + continue; |
94 | 131 | } |
95 | 132 | } |
96 | 133 |
|
|
0 commit comments