优化打包

master
ELF 5 years ago
parent 8968223dd2
commit f2765313fd

@ -18,38 +18,44 @@ class GameSourceService {
/** /**
* 获取IPA中的.app后缀目录 * 获取IPA中的.app后缀目录
*/ */
public function getIpaAppPath($ipaPath) public function getIpaAppPath($zip)
{ {
$appPath = ''; $appPath = '';
$zipGameSource = zip_open($ipaPath); for ($i = 0; $i < $zip->numFiles; $i++) {
if ($zipGameSource) { $name = $zip->getNameIndex($i);
while ($zipEntry = zip_read($zipGameSource)) { if (preg_match("/^Payload.*?\.app/", $name, $matches)) {
if (preg_match("/^Payload.*?\.app/", zip_entry_name($zipEntry), $matches)) { $appPath = $matches[0];
$appPath = $matches[0]; break;
break;
}
} }
zip_close($zipGameSource);
} }
return $appPath; return $appPath;
} }
public function getChannelConfigFile($gameSource) public function deleteOldChannelConfigFolder($zip, $txChannelFolder)
{
for ($i = 0; $i < $zip->numFiles; $i++) {
$name = $zip->getNameIndex($i);
if (strpos($name, $txChannelFolder) === 0) {
$zip->deleteName($name);
}
}
}
public function getChannelConfigFile($zip, $sdkVersion)
{ {
$configUrl = ''; $configUrl = '';
if ($gameSource['sdk_version'] == 1) { if ($sdkVersion == 1) {
$configUrl = "META-INF/mch.properties"; $configUrl = "META-INF/mch.properties";
} else { } else {
$appPath = $this->getIpaAppPath($this->getGameSourceUrl($gameSource)); $appPath = $this->getIpaAppPath($zip);
$configUrl = $appPath . '/_CodeSignature/TXChannel'; $configUrl = $appPath . '/_CodeSignature/TXChannel';
} }
return $configUrl; return $configUrl;
} }
public function getChannelConfigFolder($gameSource, array $packData) public function getChannelConfigFolder($zip, array $packData)
{ {
$gameSourceUrl = $this->getGameSourceUrl($gameSource); $appPath = $this->getIpaAppPath($zip);
$appPath = $this->getIpaAppPath($this->getGameSourceUrl($gameSource));
return $appPath . '/TXChannel/' . Base62::encode(json_encode($packData)); return $appPath . '/TXChannel/' . Base62::encode(json_encode($packData));
} }
@ -79,53 +85,51 @@ class GameSourceService {
'source_version' => $gameSource['source_version'], 'source_version' => $gameSource['source_version'],
]; ];
$zip = new \ZipArchive();
if (!$zip->open($localPath, \ZipArchive::CREATE)) {
return false;
}
if (self::IS_FIXED_IOS13 && $game['sdk_version'] == 2) { if (self::IS_FIXED_IOS13 && $game['sdk_version'] == 2) {
$channelFolder = $this->getChannelConfigFolder($gameSource, $packData); $channelFolder = $this->getChannelConfigFolder($zip, $packData);
return $this->packChannelFolder($localPath, $channelFolder); return $this->packChannelFolder($zip, $channelFolder);
} else { } else {
$channelFile = $this->getChannelConfigFile($gameSource); $channelFile = $this->getChannelConfigFile($zip, $gameSource['sdk_version']);
return $this->packChannelFile($localPath, $channelFile, $packData); return $this->packChannelFile($zip, $channelFile, $packData);
} }
$zip->close();
return false; return false;
} }
/** /**
* 打入渠道信息文件 * 打入渠道信息文件
* @param string $zipFile 包文件地址 * @param string $zip 包文件
* @param string $distFile 打入文件名 * @param string $distFile 打入文件名
* @param array $packData 打入信息 * @param array $packData 打入信息
* @return boolean 是否成功 * @return boolean 是否成功
*/ */
public function packChannelFile($zipFile, $distFile, array $packData) public function packChannelFile($zip, $distFile, array $packData)
{ {
$zip = new \ZipArchive(); $zip->addFromString($distFile, json_encode($packData));
if ($zip->open($zipFile, \ZipArchive::CREATE)) { return true;
$zip->addFromString($distFile, json_encode($packData));
$zip->close();
return true;
}
return false;
} }
/** /**
* 打入渠道信息目录用于IOS主要为了解决IOS13问题 * 打入渠道信息目录用于IOS主要为了解决IOS13问题
* @param string $zipFile 包文件地址 * @param string $zip 包文件
* @param string $distFolder 打入文件夹 * @param string $distFolder 打入文件夹
* @return boolean 是否成功 * @return boolean 是否成功
*/ */
public function packChannelFolder($zipFile, $distFolder) public function packChannelFolder($zip, $distFolder)
{ {
$zip = new \ZipArchive(); $rows = explode('/' , $distFolder);
if ($zip->open($zipFile, \ZipArchive::CREATE)) {
$rows = explode('/' . $distFolder);
unset($rows[count($rows) -1]); unset($rows[count($rows) -1]);
$txChannelFolder = implode('/', $rows); $txChannelFolder = implode('/', $rows) . '/';
$zip->deleteName($txChannelFolder); $this->deleteOldChannelConfigFolder($zip, $txChannelFolder);
$zip->addEmptyDir($distFolder); $zip->addEmptyDir($distFolder);
$zip->close();
return true; return true;
}
return false;
} }
/** /**

Loading…
Cancel
Save