@@ -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); |