1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CHMLib\Header; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use CHMLib\Reader\Reader; |
7
|
|
|
use CHMLib\Exception\UnexpectedHeaderException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The LXZ header of a CHM file. |
11
|
|
|
*/ |
12
|
|
|
class LZXC extends Header |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The header version. |
16
|
|
|
* |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
protected $version; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The LZX reset interval. |
23
|
|
|
* |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
protected $resetInterval; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The window size in 32KB blocks. |
30
|
|
|
* |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $windowSize; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The cache size. |
37
|
|
|
* |
38
|
|
|
* @var int |
39
|
|
|
*/ |
40
|
|
|
protected $cacheSize; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Initializes the instance. |
44
|
|
|
* |
45
|
|
|
* @param Reader $reader The reader that provides the data. |
46
|
|
|
* |
47
|
|
|
* @throws UnexpectedHeaderException Throws an UnexpectedHeaderException if the header signature is not valid. |
48
|
|
|
* @throws Exception Throws an Exception in case of errors. |
49
|
|
|
*/ |
50
|
4 |
|
public function __construct(Reader $reader) |
51
|
|
|
{ |
52
|
4 |
|
$size = $reader->readUInt32(); |
53
|
4 |
|
if ($size < 6) { |
54
|
|
|
throw new Exception('The LZXC entry is too small'); |
55
|
|
|
} |
56
|
4 |
|
parent::__construct($reader); |
57
|
4 |
|
if ($this->headerSignature !== 'LZXC') { |
58
|
|
|
throw UnexpectedHeaderException::create('LZXC', $this->headerSignature); |
59
|
|
|
} |
60
|
4 |
|
$this->version = $reader->readUInt32(); |
61
|
4 |
|
if ($this->version !== 2) { |
62
|
|
|
throw new Exception("Unsupported LZXC header version: {$this->version}"); |
63
|
|
|
} |
64
|
4 |
|
$this->resetInterval = $reader->readUInt32(); |
65
|
4 |
|
$this->windowSize = $reader->readUInt32(); |
66
|
4 |
|
$this->cacheSize = $reader->readUInt32(); |
67
|
4 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the header version. |
71
|
|
|
* |
72
|
|
|
* @return int |
73
|
|
|
*/ |
74
|
|
|
public function getVersion() |
75
|
|
|
{ |
76
|
|
|
return $this->version; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the LZX reset interval. |
81
|
|
|
* |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
4 |
|
public function getResetInterval() |
85
|
|
|
{ |
86
|
4 |
|
return $this->resetInterval; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the window size in 32KB blocks. |
91
|
|
|
* |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
4 |
|
public function getWindowSize() |
95
|
|
|
{ |
96
|
4 |
|
return $this->windowSize; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the cache size. |
101
|
|
|
* |
102
|
|
|
* @return int |
103
|
|
|
*/ |
104
|
4 |
|
public function getCacheSize() |
105
|
|
|
{ |
106
|
4 |
|
return $this->cacheSize; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|