@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @property array $dirs |
19 | 19 | */ |
20 | -class AIDXReader extends PACKReaderAbstract{ |
|
20 | +class AIDXReader extends PACKReaderAbstract { |
|
21 | 21 | |
22 | 22 | /** @var array */ |
23 | 23 | protected $dirs; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | \fread($this->fh, 16) |
34 | 34 | ); |
35 | 35 | |
36 | - if($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41"){ // XDIA |
|
36 | + if ($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41") { // XDIA |
|
37 | 37 | throw new WSDBException('invalid AIDX'); |
38 | 38 | } |
39 | 39 | |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | $files = \array_fill(0, $n['files'], null); |
63 | 63 | |
64 | 64 | // create a directory object for each dir (4+4 = 8 bytes) |
65 | - foreach($dirs as $i => $_){ |
|
65 | + foreach ($dirs as $i => $_) { |
|
66 | 66 | $dirs[$i] = new ArchiveDirectory(\unpack('LNameOffset/LBlockIndex', \fread($this->fh, 8)), $parent); |
67 | 67 | } |
68 | 68 | |
69 | 69 | // create a file object for each file (4+4+8+8+8+20+4 = 56 bytes) |
70 | - foreach($files as $i => $_){ |
|
70 | + foreach ($files as $i => $_) { |
|
71 | 71 | $files[$i] = new ArchiveFile( |
72 | 72 | \unpack('LNameOffset/LFlags/QFiletime/QSizeUncompressed/QSizeCompressed/a20Hash/x4', \fread($this->fh, 56)), |
73 | 73 | $parent |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | }; |
83 | 83 | |
84 | 84 | // apply the names to each object in the block |
85 | - foreach($dirs as $i => $e){ |
|
85 | + foreach ($dirs as $i => $e) { |
|
86 | 86 | $dirs[$i]->Name = $getname($e); |
87 | 87 | } |
88 | 88 | |
89 | - foreach($files as $i => $e){ |
|
89 | + foreach ($files as $i => $e) { |
|
90 | 90 | $files[$i]->Name = $getname($e); |
91 | 91 | } |
92 | 92 | |
93 | 93 | // loop through the directory stucture recursively and add the block data |
94 | - foreach($dirs as $i => $info){ |
|
95 | - if(isset($this->blocktable[$info->BlockIndex])){ |
|
94 | + foreach ($dirs as $i => $info) { |
|
95 | + if (isset($this->blocktable[$info->BlockIndex])) { |
|
96 | 96 | $dirs[$i]->Content = $this->getBlock($this->blocktable[$info->BlockIndex], $parent.$info->Name); |
97 | 97 | } |
98 | 98 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -class AARCReader extends PACKReaderAbstract{ |
|
15 | +class AARCReader extends PACKReaderAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @throws \codemasher\WildstarDB\WSDBException |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | \fread($this->fh, 16) |
26 | 26 | ); |
27 | 27 | |
28 | - if($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41"){ // CRAA |
|
28 | + if ($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41") { // CRAA |
|
29 | 29 | throw new WSDBException('invalid AARC'); |
30 | 30 | } |
31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | \fseek($this->fh, $blockInfo['Offset']); |
36 | 36 | |
37 | 37 | // read the data block info (4+20+8 = 32 bytes) |
38 | - for($i = 0; $i < $rootInfo['Blockcount']; $i++){ |
|
38 | + for ($i = 0; $i < $rootInfo['Blockcount']; $i++) { |
|
39 | 39 | $data = unpack('LIndex/a20Hash/QSizeCompressed', \fread($this->fh, 32)); |
40 | 40 | $hash = \bin2hex($data['Hash']); |
41 | 41 | unset($data['Hash']); |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @throws \codemasher\WildstarDB\WSDBException |
80 | 80 | */ |
81 | - public function __construct(LoggerInterface $logger = null){ |
|
81 | + public function __construct(LoggerInterface $logger = null) { |
|
82 | 82 | |
83 | - if(\PHP_INT_SIZE < 8){ |
|
83 | + if (\PHP_INT_SIZE < 8) { |
|
84 | 84 | throw new WSDBException('64-bit PHP required'); |
85 | 85 | } |
86 | 86 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * @return void |
92 | 92 | */ |
93 | - public function __destruct(){ |
|
94 | - $this->logger->info('memory usage: '.round(\memory_get_usage(true)/1048576, 3).'MB'); |
|
95 | - $this->logger->info('peak memory usage: '.round(\memory_get_peak_usage(true)/1048576, 3).'MB'); |
|
93 | + public function __destruct() { |
|
94 | + $this->logger->info('memory usage: '.round(\memory_get_usage(true) / 1048576, 3).'MB'); |
|
95 | + $this->logger->info('peak memory usage: '.round(\memory_get_peak_usage(true) / 1048576, 3).'MB'); |
|
96 | 96 | |
97 | 97 | $this->close(); |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function close():ReaderInterface{ |
104 | 104 | |
105 | - if(\is_resource($this->fh)){ |
|
105 | + if (\is_resource($this->fh)) { |
|
106 | 106 | \fclose($this->fh); |
107 | 107 | |
108 | 108 | $this->fh = null; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @return mixed|null |
124 | 124 | */ |
125 | - public function __get(string $name){ |
|
125 | + public function __get(string $name) { |
|
126 | 126 | return \property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null; |
127 | 127 | } |
128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $this->close(); |
137 | 137 | $filename = \realpath($filename); |
138 | 138 | |
139 | - if(!$filename || !\is_file($filename) || !\is_readable($filename)){ |
|
139 | + if (!$filename || !\is_file($filename) || !\is_readable($filename)) { |
|
140 | 140 | throw new WSDBException('input file not readable'); |
141 | 141 | } |
142 | 142 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | $this->logger->info('loading: '.$this->file); |
148 | 148 | |
149 | - if(\strlen($header) !== $this->headerSize){ |
|
149 | + if (\strlen($header) !== $this->headerSize) { |
|
150 | 150 | throw new WSDBException('cannot read header'); |
151 | 151 | } |
152 | 152 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function checkData():void{ |
170 | 170 | |
171 | - if(empty($this->data)){ |
|
171 | + if (empty($this->data)) { |
|
172 | 172 | throw new WSDBException('empty data, run ReaderInterface::read() first'); |
173 | 173 | } |
174 | 174 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function saveToFile(string $data, string $file):bool{ |
185 | 185 | |
186 | - if(!\is_writable(\dirname($file))){ |
|
186 | + if (!\is_writable(\dirname($file))) { |
|
187 | 187 | throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable'); |
188 | 188 | } |
189 | 189 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | $json = \json_encode($this->data, $jsonOptions); |
205 | 205 | |
206 | - if($file !== null){ |
|
206 | + if ($file !== null) { |
|
207 | 207 | $this->saveToFile($json, $file); |
208 | 208 | } |
209 | 209 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | |
226 | 226 | \fputcsv($mh, \array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar); |
227 | 227 | |
228 | - foreach($this->data as $row){ |
|
228 | + foreach ($this->data as $row) { |
|
229 | 229 | \fputcsv($mh, \array_values($row), $delimiter, $enclosure, $escapeChar); |
230 | 230 | } |
231 | 231 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | |
236 | 236 | \fclose($mh); |
237 | 237 | |
238 | - if($file !== null){ |
|
238 | + if ($file !== null) { |
|
239 | 239 | $this->saveToFile($csv, $file); |
240 | 240 | } |
241 | 241 | |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | $sxe = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>', \LIBXML_BIGLINES); |
256 | 256 | $types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string']; |
257 | 257 | |
258 | - foreach($this->data as $row){ |
|
258 | + foreach ($this->data as $row) { |
|
259 | 259 | $item = $sxe->addChild('item'); |
260 | 260 | |
261 | - foreach(\array_values($row) as $i => $value){ |
|
261 | + foreach (\array_values($row) as $i => $value) { |
|
262 | 262 | $item |
263 | 263 | ->addChild($this->cols[$i]['name'], $value) |
264 | 264 | ->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | |
269 | 269 | $xml = $sxe->asXML(); |
270 | 270 | |
271 | - if($file !== null){ |
|
271 | + if ($file !== null) { |
|
272 | 272 | $this->saveToFile($xml, $file); |
273 | 273 | } |
274 | 274 | |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | ->ifNotExists() |
289 | 289 | ; |
290 | 290 | |
291 | - foreach($this->cols as $i => $col){ |
|
291 | + foreach ($this->cols as $i => $col) { |
|
292 | 292 | |
293 | - switch($col['header']['DataType']){ |
|
293 | + switch ($col['header']['DataType']) { |
|
294 | 294 | case 3: $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break; |
295 | 295 | case 4: $createTable->decimal($col['name'], '7,3', 0); break; |
296 | 296 | case 11: $createTable->field($col['name'], 'BOOLEAN'); break; |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | |
305 | 305 | $createTable->query(); |
306 | 306 | |
307 | - if(\count($this->data) < 1){ |
|
307 | + if (\count($this->data) < 1) { |
|
308 | 308 | $this->logger->notice('no records available for table '.$this->name); |
309 | 309 | return $this; |
310 | 310 | } |
@@ -175,15 +175,12 @@ discard block |
||
175 | 175 | // $Flags is supposed to be a bitmask |
176 | 176 | if($file->Flags === 1){ // no compression |
177 | 177 | // nada |
178 | - } |
|
179 | - elseif($file->Flags === 3){ // deflate (probably unsed) |
|
178 | + } elseif($file->Flags === 3){ // deflate (probably unsed) |
|
180 | 179 | $content = \gzinflate($content); |
181 | - } |
|
182 | - elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
180 | + } elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
183 | 181 | // https://bitbucket.org/mugadr_m/wildstar-studio/issues/23 |
184 | 182 | $content = \xzdecode(\substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5)); |
185 | - } |
|
186 | - else{ |
|
183 | + } else{ |
|
187 | 184 | throw new WSDBException('invalid file flag'); |
188 | 185 | } |
189 | 186 | |
@@ -193,8 +190,7 @@ discard block |
||
193 | 190 | $this->errors[$file->Hash] = $file; |
194 | 191 | $this->logger->error('error writing '.$dest); |
195 | 192 | |
196 | - } |
|
197 | - elseif($bytesWritten !== $file->SizeUncompressed){ |
|
193 | + } elseif($bytesWritten !== $file->SizeUncompressed){ |
|
198 | 194 | $this->warnings[$file->Hash] = $file; |
199 | 195 | // throw new WSDBException |
200 | 196 | $this->logger->warning('size discrepancy for '.$dest.', expected '.$file->SizeUncompressed.' got '.$bytesWritten); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger}; |
22 | 22 | |
23 | -class ArchiveExtractor implements LoggerAwareInterface{ |
|
23 | +class ArchiveExtractor implements LoggerAwareInterface { |
|
24 | 24 | use LoggerAwareTrait; |
25 | 25 | |
26 | 26 | public const ARCHIVES = ['ClientData', 'ClientDataDE', 'ClientDataEN', 'ClientDataFR']; |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @throws \codemasher\WildstarDB\WSDBException |
51 | 51 | */ |
52 | - public function __construct(LoggerInterface $logger){ |
|
52 | + public function __construct(LoggerInterface $logger) { |
|
53 | 53 | |
54 | - if(!\extension_loaded('xz')){ |
|
54 | + if (!\extension_loaded('xz')) { |
|
55 | 55 | throw new WSDBException('required extension xz missing!'); |
56 | 56 | } |
57 | 57 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | public function open(string $index):ArchiveExtractor{ |
71 | 71 | $this->archivename = \str_replace(['.index', '.archive'], '', \basename($index)); |
72 | 72 | |
73 | - if(!in_array($this->archivename, $this::ARCHIVES)){ |
|
73 | + if (!in_array($this->archivename, $this::ARCHIVES)) { |
|
74 | 74 | throw new WSDBException('invalid archive file (Steam Wildstar not supported)'); |
75 | 75 | } |
76 | 76 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | $this->destination = \rtrim($destination ?? $this->archivepath, '\\/'); |
93 | 93 | |
94 | 94 | // does the destination parent exist? |
95 | - if(!$this->destination || !\file_exists(\dirname($this->destination))){ |
|
95 | + if (!$this->destination || !\file_exists(\dirname($this->destination))) { |
|
96 | 96 | throw new WSDBException('invalid destination: '.$this->destination); |
97 | 97 | } |
98 | 98 | |
99 | 99 | // destination does not exist? |
100 | - if(!\file_exists($this->destination)){ |
|
100 | + if (!\file_exists($this->destination)) { |
|
101 | 101 | // is the parent writable? |
102 | - if(!\is_writable(\dirname($this->destination))){ |
|
102 | + if (!\is_writable(\dirname($this->destination))) { |
|
103 | 103 | throw new WSDBException('destination parent is not writable'); |
104 | 104 | } |
105 | 105 | // create it |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | // destination exists but isn't writable? |
110 | - if(!\is_writable($this->destination)){ |
|
110 | + if (!\is_writable($this->destination)) { |
|
111 | 111 | throw new WSDBException('destination is not writable'); |
112 | 112 | } |
113 | 113 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $this->warnings = []; |
116 | 116 | $this->errors = []; |
117 | 117 | |
118 | - foreach($this->AIDX->data as $item){ |
|
118 | + foreach ($this->AIDX->data as $item) { |
|
119 | 119 | $this->read($item); |
120 | 120 | } |
121 | 121 | |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function read(ArchiveItemAbstract $item):void{ |
133 | 133 | |
134 | - if($item instanceof ArchiveDirectory){ |
|
134 | + if ($item instanceof ArchiveDirectory) { |
|
135 | 135 | |
136 | - foreach($item->Content as $dir){ |
|
136 | + foreach ($item->Content as $dir) { |
|
137 | 137 | $dest = $this->destination.$dir->Parent; |
138 | 138 | |
139 | - if(!\file_exists($dest)){ |
|
139 | + if (!\file_exists($dest)) { |
|
140 | 140 | \mkdir($dest, 0777, true); |
141 | 141 | } |
142 | 142 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | protected function extractFile(ArchiveFile $file):void{ |
158 | 158 | $dest = $this->destination.$file->Parent.$file->Name; |
159 | 159 | |
160 | - if(\file_exists($dest)){ // @todo: overwrite option |
|
160 | + if (\file_exists($dest)) { // @todo: overwrite option |
|
161 | 161 | $this->logger->notice('file already exists: '.$dest); |
162 | 162 | return; |
163 | 163 | } |
@@ -169,33 +169,33 @@ discard block |
||
169 | 169 | $content = \fread($this->fh, $block['Size']); |
170 | 170 | |
171 | 171 | // hash the read data |
172 | - if(\sha1($content) !== $file->Hash){ |
|
172 | + if (\sha1($content) !== $file->Hash) { |
|
173 | 173 | throw new WSDBException('corrupt data, invalid hash: '.\sha1($content).' (expected '.$file->Hash.' for '.$file->Name.')'); |
174 | 174 | } |
175 | 175 | |
176 | 176 | // $Flags is supposed to be a bitmask |
177 | - if($file->Flags === 1){ // no compression |
|
177 | + if ($file->Flags === 1) { // no compression |
|
178 | 178 | // nada |
179 | 179 | } |
180 | - elseif($file->Flags === 3){ // deflate (probably unsed) |
|
180 | + elseif ($file->Flags === 3) { // deflate (probably unsed) |
|
181 | 181 | $content = \gzinflate($content); |
182 | 182 | } |
183 | - elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
183 | + elseif ($file->Flags === 5) { // lzma (requires ext-xz) |
|
184 | 184 | // https://bitbucket.org/mugadr_m/wildstar-studio/issues/23 |
185 | 185 | $content = \xzdecode(\substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5)); |
186 | 186 | } |
187 | - else{ |
|
187 | + else { |
|
188 | 188 | throw new WSDBException('invalid file flag'); |
189 | 189 | } |
190 | 190 | |
191 | 191 | $bytesWritten = \file_put_contents($dest, $content); |
192 | 192 | |
193 | - if($bytesWritten === false){ |
|
193 | + if ($bytesWritten === false) { |
|
194 | 194 | $this->errors[$file->Hash] = $file; |
195 | 195 | $this->logger->error('error writing '.$dest); |
196 | 196 | |
197 | 197 | } |
198 | - elseif($bytesWritten !== $file->SizeUncompressed){ |
|
198 | + elseif ($bytesWritten !== $file->SizeUncompressed) { |
|
199 | 199 | $this->warnings[$file->Hash] = $file; |
200 | 200 | // throw new WSDBException |
201 | 201 | $this->logger->warning('size discrepancy for '.$dest.', expected '.$file->SizeUncompressed.' got '.$bytesWritten); |