优化打包

master
ELF 5 years ago
parent 8968223dd2
commit f2765313fd

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

Loading…
Cancel
Save