/** * Check if the data is a ZIP / RAR file, extract files, get file info. * * @param string $compressedData * * @return bool */ protected function _processCompressedData(&$compressedData) { $this->_compressedFilesChecked++; // Give the data to archive info so it can check if it's a rar. if ($this->_archiveInfo->setData($compressedData, true) === false) { $this->_debug('Data is probably not RAR or ZIP.' . PHP_EOL); return false; } // Check if there's an error. if ($this->_archiveInfo->error !== '') { $this->_debug('ArchiveInfo Error: ' . $this->_archiveInfo->error); return false; } // Get a summary of the compressed file. $dataSummary = $this->_archiveInfo->getSummary(true); // Check if the compressed file is encrypted. if (!empty($this->_archiveInfo->isEncrypted) || isset($dataSummary['is_encrypted']) && $dataSummary['is_encrypted'] != 0) { $this->_debug('ArchiveInfo: Compressed file has a password.'); $this->_releaseHasPassword = true; $this->_passwordStatus[] = Releases::PASSWD_RAR; return false; } switch ($dataSummary['main_type']) { case \ArchiveInfo::TYPE_RAR: if ($this->_echoCLI) { $this->_echo('r', 'primaryOver', false); } if ($this->_extractUsingRarInfo === false && $this->_unrarPath !== false) { $fileName = $this->tmpPath . uniqid() . '.rar'; file_put_contents($fileName, $compressedData); Misc::runCmd($this->_killString . $this->_unrarPath . '" e -ai -ep -c- -id -inul -kb -or -p- -r -y "' . $fileName . '" "' . $this->tmpPath . 'unrar/"'); unlink($fileName); } break; case \ArchiveInfo::TYPE_ZIP: if ($this->_echoCLI) { $this->_echo('z', 'primaryOver', false); } if ($this->_extractUsingRarInfo === false && $this->_7zipPath !== false) { $fileName = $this->tmpPath . uniqid() . '.zip'; file_put_contents($fileName, $compressedData); Misc::runCmd($this->_killString . $this->_7zipPath . '" x "' . $fileName . '" -bd -y -o"' . $this->tmpPath . 'unzip/"'); unlink($fileName); } break; default: return false; } return $this->_processCompressedFileList(); }
/** * Work out all files contained inside a rar */ public function processReleaseFiles($fetchedBinary, $relid) { $retval = array(); $rar = new \ArchiveInfo(); $rf = new ReleaseFiles(); $rar->setData($fetchedBinary, true); if ($rar->error) { return false; } $files = $rar->getArchiveFileList(); if ($files !== false) { foreach ($files as $file) { if (isset($file['name'])) { $rf->add($relid, utf8_encode($file['name']), isset($file['size']) ? $file['size'] : "", isset($file['date']) ? $file['date'] : "", isset($file['pass']) ? $file['pass'] : ""); $retval[] = $file['name']; } } } unset($fetchedBinary); return $retval; }