@@ -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']; |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @throws \codemasher\WildstarDB\WSDBException |
49 | 49 | */ |
50 | - public function __construct(LoggerInterface $logger){ |
|
50 | + public function __construct(LoggerInterface $logger) { |
|
51 | 51 | |
52 | - if(!\extension_loaded('xz')){ |
|
52 | + if (!\extension_loaded('xz')) { |
|
53 | 53 | throw new WSDBException('required extension xz missing!'); |
54 | 54 | } |
55 | 55 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function open(string $index):ArchiveExtractor{ |
69 | 69 | $this->archivename = \str_replace(['.index', '.archive'], '', \basename($index)); |
70 | 70 | |
71 | - if(!in_array($this->archivename, $this::ARCHIVES)){ |
|
71 | + if (!in_array($this->archivename, $this::ARCHIVES)) { |
|
72 | 72 | throw new WSDBException('invalid archive file (Steam Wildstar not supported)'); |
73 | 73 | } |
74 | 74 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | $this->destination = \rtrim($destination ?? $this->archivepath, '\\/'); |
91 | 91 | |
92 | 92 | // does the destination parent exist? |
93 | - if(!$this->destination || !\file_exists(\dirname($this->destination))){ |
|
93 | + if (!$this->destination || !\file_exists(\dirname($this->destination))) { |
|
94 | 94 | throw new WSDBException('invalid destination: '.$this->destination); |
95 | 95 | } |
96 | 96 | |
97 | 97 | // destination does not exist? |
98 | - if(!\file_exists($this->destination)){ |
|
98 | + if (!\file_exists($this->destination)) { |
|
99 | 99 | // is the parent writable? |
100 | - if(!\is_writable(\dirname($this->destination))){ |
|
100 | + if (!\is_writable(\dirname($this->destination))) { |
|
101 | 101 | throw new WSDBException('destination parent is not writable'); |
102 | 102 | } |
103 | 103 | // create it |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | // destination exists but isn't writable? |
108 | - if(!\is_writable($this->destination)){ |
|
108 | + if (!\is_writable($this->destination)) { |
|
109 | 109 | throw new WSDBException('destination is not writable'); |
110 | 110 | } |
111 | 111 | |
112 | 112 | $this->fh = \fopen($this->archivepath.'.archive', 'rb'); |
113 | 113 | $this->warnings = []; |
114 | 114 | |
115 | - foreach($this->AIDX->data as $item){ |
|
115 | + foreach ($this->AIDX->data as $item) { |
|
116 | 116 | $this->read($item); |
117 | 117 | } |
118 | 118 | |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function read(ArchiveItemAbstract $item):void{ |
130 | 130 | |
131 | - if($item instanceof ArchiveDirectory){ |
|
131 | + if ($item instanceof ArchiveDirectory) { |
|
132 | 132 | |
133 | - foreach($item->Content as $dir){ |
|
133 | + foreach ($item->Content as $dir) { |
|
134 | 134 | $dest = $this->destination.$dir->Parent; |
135 | 135 | |
136 | - if(!\file_exists($dest)){ |
|
136 | + if (!\file_exists($dest)) { |
|
137 | 137 | \mkdir($dest, 0777, true); |
138 | 138 | } |
139 | 139 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | protected function extractFile(ArchiveFile $file):void{ |
155 | 155 | $dest = $this->destination.$file->Parent.$file->Name; |
156 | 156 | |
157 | - if(\file_exists($dest)){ // @todo: overwrite option |
|
157 | + if (\file_exists($dest)) { // @todo: overwrite option |
|
158 | 158 | $this->logger->notice('file already exists: '.$dest); |
159 | 159 | return; |
160 | 160 | } |
@@ -166,27 +166,27 @@ discard block |
||
166 | 166 | $content = \fread($this->fh, $block['Size']); |
167 | 167 | |
168 | 168 | // hash the read data |
169 | - if(\sha1($content) !== $file->Hash){ |
|
169 | + if (\sha1($content) !== $file->Hash) { |
|
170 | 170 | throw new WSDBException('corrupt data, invalid hash: '.\sha1($content).' (expected '.$file->Hash.' for '.$file->Name.')'); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // $Flags is supposed to be a bitmask |
174 | - if($file->Flags === 1){ // no compression |
|
174 | + if ($file->Flags === 1) { // no compression |
|
175 | 175 | $bytesWritten = \file_put_contents($dest, $content); |
176 | 176 | } |
177 | - elseif($file->Flags === 3){ // deflate (probably unsed) |
|
177 | + elseif ($file->Flags === 3) { // deflate (probably unsed) |
|
178 | 178 | $bytesWritten = \file_put_contents($dest, \gzinflate($content)); |
179 | 179 | } |
180 | - elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
180 | + elseif ($file->Flags === 5) { // lzma (requires ext-xz) |
|
181 | 181 | // https://bitbucket.org/mugadr_m/wildstar-studio/issues/23 |
182 | 182 | $content = \substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5); |
183 | 183 | $bytesWritten = \file_put_contents($dest, \xzdecode($content)); |
184 | 184 | } |
185 | - else{ |
|
185 | + else { |
|
186 | 186 | throw new WSDBException('invalid file flag'); |
187 | 187 | } |
188 | 188 | |
189 | - if($bytesWritten !== $file->SizeUncompressed){ |
|
189 | + if ($bytesWritten !== $file->SizeUncompressed) { |
|
190 | 190 | $this->warnings[$file->Hash] = $file; |
191 | 191 | // throw new WSDBException |
192 | 192 | $this->logger->warning('size discrepancy for '.$dest.', expected '.$file->SizeUncompressed.' got '.$bytesWritten); |
@@ -173,16 +173,13 @@ |
||
173 | 173 | // $Flags is supposed to be a bitmask |
174 | 174 | if($file->Flags === 1){ // no compression |
175 | 175 | $bytesWritten = \file_put_contents($dest, $content); |
176 | - } |
|
177 | - elseif($file->Flags === 3){ // deflate (probably unsed) |
|
176 | + } elseif($file->Flags === 3){ // deflate (probably unsed) |
|
178 | 177 | $bytesWritten = \file_put_contents($dest, \gzinflate($content)); |
179 | - } |
|
180 | - elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
178 | + } elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
181 | 179 | // https://bitbucket.org/mugadr_m/wildstar-studio/issues/23 |
182 | 180 | $content = \substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5); |
183 | 181 | $bytesWritten = \file_put_contents($dest, \xzdecode($content)); |
184 | - } |
|
185 | - else{ |
|
182 | + } else{ |
|
186 | 183 | throw new WSDBException('invalid file flag'); |
187 | 184 | } |
188 | 185 |