/** * 解压压缩包 * * step 2 * * @param string $packageFile * @return true PwError */ public function extractPackage($packageFile) { $this->_hash = md5_file($packageFile); $this->tmpPackage = PwApplicationHelper::extract($packageFile, $this->tmpPath); if ($this->tmpPackage === false || !is_dir($this->tmpPackage)) { return new PwError('APPCENTER:install.checkpackage.format.fail', array('{{error}}' => $this->tmpPackage)); } return true; }
/** * 下载 * 1、下载zip包 * 2、单个文件下载 */ public function download($downloadUrl, $hash, $file = '') { if ($this->useZip) { list($bool, $package) = PwSystemHelper::download($downloadUrl, $this->tmpPath . '/' . basename($downloadUrl)); if (!$bool) { return new PwError($package); } if ($hash !== md5_file($package)) { $this->_log('check Package fail. expected hash:' . $hash . 'real hash :' . md5_file($package)); return new PwError('APPCENTER:install.checkpackage.fail'); } $this->_log('download zip success, dir:' . $package); $this->tmpPackage = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target; $r = PwApplicationHelper::extract($package, $this->tmpPath); if ($r === false) { $this->_log('extract Package fail. '); return new PwError('APPCENTER:install.checkpackage.format.fail', array('{{error}}' => $r)); } if ($r != realpath($this->tmpPackage)) { PwApplicationHelper::copyRecursive($r, $this->tmpPackage); } $this->_log('extract zip success, dir:' . $this->tmpPackage); return true; } else { $_file = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target . DIRECTORY_SEPARATOR . $file; $dir = dirname($_file); list($bool, $_file) = PwSystemHelper::download($downloadUrl . '/' . $file . 'wind', $_file); if (!$bool) { return new PwError($_file); } if ($hash !== md5_file($_file)) { $this->_log('check file fail. expected hash:' . $hash . 'real hash :' . md5_file($_file)); return new PwError('APPCENTER:upgrade.check.file.fail'); } $this->_log('download file success, file:' . $_file); return true; } }