feat: 32位组件安装插件

This commit is contained in:
yangfei
2024-03-01 09:13:26 +08:00
parent ee8748a954
commit 2edbfc505c

View File

@ -559,7 +559,12 @@ object VHelper {
/**
* 在执行 callback 前先检查组件是否已安装,是否可下载
*/
fun validateVSpaceBeforeAction(context: Context, packageName: String?, gameEntity: GameEntity?, callback: () -> Unit) {
fun validateVSpaceBeforeAction(
context: Context,
packageName: String?,
gameEntity: GameEntity?,
callback: () -> Unit
) {
if (isLegacyInstalled(packageName)) {
oldCwValidateVSpaceBeforeAction(context, gameEntity, callback)
} else {
@ -1194,7 +1199,7 @@ object VHelper {
logLaunchButtonClicked(packageName, gameId, gameName, gameType, location)
}
validateVSpaceBeforeAction(context,packageName, GameEntity().apply {
validateVSpaceBeforeAction(context, packageName, GameEntity().apply {
id = gameId
name = gameName
downloadStatus = Constants.V_GAME
@ -1981,63 +1986,43 @@ object VHelper {
fun preparePluginUpdate() {
Config.vNewSettingSubject.debounce(2, TimeUnit.SECONDS).doOnNext {
it?.vaPlugin?.let { vaPlugin ->
if (!vaPlugin.id.isNullOrEmpty() && !vaPlugin.url64.isNullOrEmpty()) {
val installedPluginVersion = HostUtils.getPluginVersion()
// 因为服务端下发的插件都是release版本的所以开发者要调试插件更新暂时先push文件到手机更新吧
if (!vaPlugin.id.isNullOrEmpty()) {
Utils.log(LOG_TAG, "开发者需要插件更新功能请push文件到手机或者【修改插件打包的配置为debug版本然后上传推送】")
if(com.gh.gamecenter.BuildConfig.DEBUG) {
val file = File("/data/local/tmp/gh-plugins/artifacts.zip")
if(file.exists()) {
Utils.log(LOG_TAG, "有本地更新文件")
PluginHelper.getInstance().updatePlugin(file)
}
} else {
if (installedPluginVersion?.isNotEmpty() == true
&& !Version(vaPlugin.versionName).isEqual(installedPluginVersion)
) {
val pluginFileName = "${vaPlugin.id}.zip"
val currentPluginFile = File(HaloApp.getInstance().cacheDir, pluginFileName)
if (currentPluginFile.exists() && PluginFileUtils.isZipFile(currentPluginFile)) {
// 已经下载好了
PluginHelper.getInstance().updatePlugin(currentPluginFile)
} else {
val currentDownloadEntity = DownloadMessageHandler.findEntity(vaPlugin.id)
if (currentDownloadEntity != null) {
SimpleDownloadManager.cancel(vaPlugin.id)
if (!vaPlugin.url64.isNullOrEmpty()) {
val installedPluginVersion = HostUtils.getPluginVersion()
// 因为服务端下发的插件都是release版本的所以开发者要调试插件更新暂时先push文件到手机更新吧
if (com.gh.gamecenter.BuildConfig.DEBUG) {
val file = File("/data/local/tmp/gh-plugins/artifacts.zip")
if (file.exists()) {
Utils.log(LOG_TAG, "有本地更新文件: 64位插件")
PluginHelper.getInstance().updatePlugin(file)
}
} else {
if (installedPluginVersion?.isNotEmpty() == true
&& !Version(vaPlugin.versionName).isEqual(installedPluginVersion)
) {
downloadPlugin(id = "${vaPlugin.id}64", url = vaPlugin.url64) {
PluginHelper.getInstance().updatePlugin(it)
}
SimpleDownloadManager.download(
DownloadConfigBuilder()
.setUniqueId(vaPlugin.id)
.setFileName(pluginFileName)
.setUrl(vaPlugin.url64)
.setPathToStore(HaloApp.getInstance().cacheDir.absolutePath + File.separator)
.setHttpClient(DefaultHttpClient())
.setDownloadThreadSize(2)
.setDownloadListener(DownloadMessageHandler)
.setDownloadExecutor(AppExecutor.ioExecutor)
.build()
)
DownloadMessageHandler.registerListener(vaPlugin.id, object : DownloadListener {
override fun onError(error: DownloadError) {
}
}
}
}
override fun onProgress(progress: Float) {
}
override fun onSizeReceived(fileSize: Long) {
}
override fun onStatusChanged(status: DownloadStatus) {
if (status == DownloadStatus.COMPLETED) {
PluginHelper.getInstance().updatePlugin(currentPluginFile)
DownloadMessageHandler.unregisterListener(vaPlugin.id, this)
}
}
override fun onSpeedChanged(speed: Float) {
}
})
if (!vaPlugin.url32.isNullOrEmpty()) {
if (com.gh.gamecenter.BuildConfig.DEBUG) {
val file = File("/data/local/tmp/gh-plugins/artifacts32.zip")
if (file.exists()) {
Utils.log(LOG_TAG, "有本地更新文件: 32位插件")
VaApp.get().appManager.updatePlugin(file.absolutePath, "${vaPlugin.id}32.zip")
}
} else {
val installedPluginVersion = VaApp.get().appManager.extPluginVersion
if (installedPluginVersion?.isNotEmpty() == true
&& !Version(vaPlugin.versionName).isEqual(installedPluginVersion)
) {
downloadPlugin(id = "${vaPlugin.id}32", url = vaPlugin.url32) {
VaApp.get().appManager.updatePlugin(it.absolutePath, "${vaPlugin.id}32.zip")
}
}
}
}
@ -2045,4 +2030,51 @@ object VHelper {
}
}.subscribeOn(Schedulers.io()).subscribe({}, {})
}
private fun downloadPlugin(id: String, url: String, fn: (File) -> Unit) {
val pluginFileName = "${id}.zip"
val currentPluginFile = File(HaloApp.getInstance().cacheDir, pluginFileName)
if (currentPluginFile.exists() && PluginFileUtils.isZipFile(currentPluginFile)) {
// 已经下载好了
fn(currentPluginFile)
} else {
val currentDownloadEntity = DownloadMessageHandler.findEntity(id)
if (currentDownloadEntity != null) {
SimpleDownloadManager.cancel(id)
}
SimpleDownloadManager.download(
DownloadConfigBuilder()
.setUniqueId(id)
.setFileName(pluginFileName)
.setUrl(url)
.setPathToStore(HaloApp.getInstance().cacheDir.absolutePath + File.separator)
.setHttpClient(DefaultHttpClient())
.setDownloadThreadSize(2)
.setDownloadListener(DownloadMessageHandler)
.setDownloadExecutor(AppExecutor.ioExecutor)
.build()
)
DownloadMessageHandler.registerListener(id, object : DownloadListener {
override fun onError(error: DownloadError) {
}
override fun onProgress(progress: Float) {
}
override fun onSizeReceived(fileSize: Long) {
}
override fun onStatusChanged(status: DownloadStatus) {
if (status == DownloadStatus.COMPLETED) {
fn(currentPluginFile)
DownloadMessageHandler.unregisterListener(id, this)
}
}
override fun onSpeedChanged(speed: Float) {
}
})
}
}
}