1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class PACKReaderAbstract |
4
|
|
|
* |
5
|
|
|
* @filesource PACKReaderAbstract.php |
6
|
|
|
* @created 27.04.2019 |
7
|
|
|
* @package codemasher\WildstarDB |
8
|
|
|
* @author smiley <[email protected]> |
9
|
|
|
* @copyright 2019 smiley |
10
|
|
|
* @license MIT |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace codemasher\WildstarDB; |
14
|
|
|
|
15
|
|
|
use chillerlan\Database\Database; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @property array $blocktable |
19
|
|
|
*/ |
20
|
|
|
abstract class PACKReaderAbstract extends ReaderAbstract{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $FORMAT_HEADER = 'a4Signature/LVersion/x512/QFilesize/x8/QBlockTableOffset/LBlockCount/x4/LRootInfoIndex/x8'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* 4+4+512+8+8+8+4+4+4+8 = 564 bytes |
29
|
|
|
* |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
protected $headerSize = 564; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $blocktable = []; |
38
|
|
|
|
39
|
|
|
abstract protected function readData():void; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $filename |
43
|
|
|
* |
44
|
|
|
* @return \codemasher\WildstarDB\ReaderInterface |
45
|
|
|
* @throws \codemasher\WildstarDB\WSDBException |
46
|
|
|
*/ |
47
|
|
|
public function read(string $filename):ReaderInterface{ |
48
|
|
|
$this->loadFile($filename); |
49
|
|
|
$this->blocktable = []; |
50
|
|
|
|
51
|
|
|
if($this->header['Signature'] !== "\x4b\x43\x41\x50"){ // KCAP |
52
|
|
|
throw new WSDBException('invalid PACK'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// read the block info table |
56
|
|
|
\fseek($this->fh, $this->header['BlockTableOffset']); |
57
|
|
|
|
58
|
|
|
for($i = 0; $i < $this->header['BlockCount']; $i++){ |
59
|
|
|
$this->blocktable[$i] = \unpack('QOffset/QSize', \fread($this->fh, 16)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// seek forward to the root index block for convenience |
63
|
|
|
\fseek($this->fh, $this->blocktable[$this->header['RootInfoIndex']]['Offset']); |
64
|
|
|
|
65
|
|
|
$this->readData(); |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string|null $file |
72
|
|
|
* @param string $delimiter |
73
|
|
|
* @param string $enclosure |
74
|
|
|
* @param string $escapeChar |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function toCSV(string $file = null, string $delimiter = ',', string $enclosure = '"', string $escapeChar = '\\'):string{ |
79
|
|
|
// @todo |
80
|
|
|
throw new WSDBException('not implemented'); |
81
|
|
|
|
82
|
|
|
return ''; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* ugh! |
87
|
|
|
* |
88
|
|
|
* @param string|null $file |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function toXML(string $file = null):string{ |
93
|
|
|
// @todo |
94
|
|
|
throw new WSDBException('not implemented'); |
95
|
|
|
|
96
|
|
|
return ''; |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param \chillerlan\Database\Database $db |
101
|
|
|
* |
102
|
|
|
* @return \codemasher\WildstarDB\ReaderInterface |
103
|
|
|
*/ |
104
|
|
|
public function toDB(Database $db):ReaderInterface{ |
105
|
|
|
// @todo |
106
|
|
|
throw new WSDBException('not implemented'); |
107
|
|
|
|
108
|
|
|
return $this; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.