package com.img.rabbit.utils import com.img.rabbit.bean.response.UniVersionEntity /** 与 weiquan-android 的资源配置、强更和密码规则保持一致。 */ internal object UniMpPolicy { fun releasePassword(wgtPassword: String?, uniPassword: String?): String? { val prefix = wgtPassword.orEmpty().let { if (it.length > 10) it.substring(10) else it } return (prefix + uniPassword.orEmpty()).takeIf { it.isNotEmpty() } } fun downloadUrls(version: UniVersionEntity): List = version.urls?.takeIf { it.isNotEmpty() } ?: listOf(version.url) fun requiresDownload(force: Boolean, hasPackage: Boolean): Boolean = force || !hasPackage fun isNewer(version: String, installedVersion: String): Boolean { val newer = version.split('.') val installed = installedVersion.split('.') if (newer.size != 3 || installed.size != 3) return false for (i in 0..2) { val comparison = (newer[i].toIntOrNull() ?: 0).compareTo(installed[i].toIntOrNull() ?: 0) if (comparison != 0) return comparison > 0 } return false } }