Passed
Push — master ( bdfaf8...931c46 )
by smiley
01:33
created

AARCReader::readData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 0
dl 0
loc 23
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class AARCReader
4
 *
5
 * @filesource   AARCReader.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
class AARCReader extends PACKReaderAbstract{
16
17
	/**
18
	 * @throws \codemasher\WildstarDB\WSDBException
19
	 */
20
	protected function readData():void{
21
22
		// get the root info block of the AARC file (4+4+4+4 = 16 bytes)
23
		$rootInfo = \unpack(
24
			'a4ArchiveType/LVersion/LBlockcount/LIndex',
25
			\fread($this->fh, $this->blocktable[$this->header['RootInfoIndex']]['Size'])
26
		);
27
28
		if($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41"){ // CRAA
29
			throw new WSDBException('invalid AARC');
30
		}
31
32
		// get the root data info block
33
		$blockInfo = $this->blocktable[$rootInfo['Index']];
34
35
		\fseek($this->fh, $blockInfo['Offset']);
36
37
		// read the data block info (4+20+8 = 32 bytes)
38
		for($i = 0; $i < $rootInfo['Blockcount']; $i++){
39
			$data = unpack('LIndex/a20Hash/QSizeUncompressed', \fread($this->fh, 32));
40
			$hash = \bin2hex($data['Hash']);
41
			unset($data['Hash']);
42
			$this->data[$hash] = $data;
43
		}
44
45
	}
46
47
}
48