|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CHMLib\Header; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use CHMLib\Reader\Reader; |
|
7
|
|
|
use CHMLib\Exception\UnexpectedHeaderException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* A PMGL (directory listing) header of a CHM file. |
|
11
|
|
|
*/ |
|
12
|
|
|
class PMGL extends Header |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* The length of the free space and/or the QuickRef area at the end of the directory chunk. |
|
16
|
|
|
* |
|
17
|
|
|
* @var int |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $freeSpace; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The chunk number of the previous listing chunk when reading directory in sequence (-1 if this is the first listing chunk). |
|
23
|
|
|
* |
|
24
|
|
|
* @var int |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $previousChunk; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The chunk number of the next listing chunk when reading directory in sequence (-1 if this is the last listing chunk). |
|
30
|
|
|
* |
|
31
|
|
|
* @var int |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $nextChunk; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Initializes the instance. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \CHMLib\Reader\Reader $reader The reader that provides the data. |
|
39
|
|
|
* |
|
40
|
|
|
* @throws \CHMLib\Exception\UnexpectedHeaderException Throws an UnexpectedHeaderException if the header signature is not valid. |
|
41
|
|
|
* @throws \Exception Throws an Exception in case of errors. |
|
42
|
|
|
*/ |
|
43
|
4 |
|
public function __construct(Reader $reader) |
|
44
|
|
|
{ |
|
45
|
4 |
|
parent::__construct($reader); |
|
46
|
4 |
|
if ($this->headerSignature !== 'PMGL') { |
|
47
|
|
|
throw UnexpectedHeaderException::create('PMGL', $this->headerSignature); |
|
48
|
|
|
} |
|
49
|
4 |
|
$this->freeSpace = $reader->readUInt32(); |
|
50
|
4 |
|
/* Unknown (0) */ $reader->readUInt32(); |
|
51
|
4 |
|
$this->previousChunk = $reader->readInt32(); |
|
52
|
4 |
|
$this->nextChunk = $reader->readInt32(); |
|
53
|
4 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the length of the free space and/or the QuickRef area at the end of the directory chunk. |
|
57
|
|
|
* |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public function getFreeSpace() |
|
61
|
|
|
{ |
|
62
|
4 |
|
return $this->freeSpace; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the chunk number of the previous listing chunk when reading directory in sequence (-1 if this is the first listing chunk). |
|
67
|
|
|
* |
|
68
|
|
|
* @return int |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getPreviousChunk() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->previousChunk; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the chunk number of the next listing chunk when reading directory in sequence (-1 if this is the last listing chunk). |
|
77
|
|
|
* |
|
78
|
|
|
* @return int |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getNextChunk() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->nextChunk; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|