AARCReader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A readData() 0 20 3
1
<?php
2
/**
3
 * Class AARCReader
4
 *
5
 * @filesource   AARCReader.php
6
 * @created      27.04.2019
7
 * @package      codemasher\WildstarDB\Archive
8
 * @author       smiley <[email protected]>
9
 * @copyright    2019 smiley
10
 * @license      MIT
11
 */
12
13
namespace codemasher\WildstarDB\Archive;
14
15
use codemasher\WildstarDB\WSDBException;
16
17
use function bin2hex, fread, fseek, unpack;
18
19
final class AARCReader extends PACKReaderAbstract{
20
21
	private const AARC_ROOT = 'a4ArchiveType/LVersion/LBlockcount/LIndex';
22
	private const AARC_DATA = 'LIndex/a20Hash/QSizeCompressed';
23
24
	/**
25
	 * @inheritDoc
26
	 */
27
	protected function readData():void{
28
29
		// get the root info block of the AARC file (4+4+4+4 = 16 bytes)
30
		$rootInfo = unpack($this::AARC_ROOT, fread($this->fh, 16));
31
32
		if($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41"){ // CRAA
33
			throw new WSDBException('invalid AARC');
34
		}
35
36
		// get the root data info block
37
		$blockInfo = $this->blocktable[$rootInfo['Index']];
38
39
		fseek($this->fh, $blockInfo['Offset']);
40
41
		// read the data block info (4+20+8 = 32 bytes)
42
		for($i = 0; $i < $rootInfo['Blockcount']; $i++){
43
			$data = unpack($this::AARC_DATA, fread($this->fh, 32));
44
			$hash = bin2hex($data['Hash']);
45
			unset($data['Hash']);
46
			$this->data[$hash] = $data;
47
		}
48
49
	}
50
51
}
52