fixed in app downloader

This commit is contained in:
LagradOst 2021-09-20 21:27:51 +02:00
parent 6a561a35c0
commit 2a325469a5

View file

@ -65,16 +65,16 @@ class InAppUpdater {
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()
private fun Activity.getAppUpdate(): Update {
try {
return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
return if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) {
if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) {
getPreReleaseUpdate()
} else {
getReleaseUpdate()
}
} catch (e: Exception) {
println(e)
return Update(false, null, null, null)
Update(false, null, null, null)
}
}
@ -84,8 +84,8 @@ class InAppUpdater {
val response =
mapper.readValue<List<GithubRelease>>(khttp.get(url, headers = headers).text)
val versionRegex = Regex("""(.*?((\d)\.(\d)\.(\d)).*\.apk)""")
val versionRegex = Regex("""(.*?((\d+)\.(\d+)\.(\d+))\.apk)""")
val versionRegexLocal = Regex("""(.*?((\d+)\.(\d+)\.(\d+)).*)""")
/*
val releases = response.map { it.assets }.flatten()
.filter { it.content_type == "application/vnd.android.package-archive" }
@ -112,10 +112,17 @@ class InAppUpdater {
)
}
val foundVersion = foundAsset?.name?.let { versionRegex.find(it) }
foundAsset?.name?.let { assetName ->
val foundVersion = versionRegex.find(assetName)
val shouldUpdate =
if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo(
foundVersion.groupValues[2]
if (foundAsset.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.let { versionName ->
versionRegexLocal.find(versionName)?.groupValues?.let {
it[3].toInt() * 100_000_000 + it[4].toInt() * 10_000 + it[5].toInt()
}
}?.compareTo(
foundVersion.groupValues.let {
it[3].toInt() * 100_000_000 + it[4].toInt() * 10_000 + it[5].toInt()
}
)!! < 0 else false
return if (foundVersion != null) {
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body)
@ -123,6 +130,8 @@ class InAppUpdater {
Update(false, null, null, null)
}
}
return Update(false, null, null, null)
}
private fun Activity.getPreReleaseUpdate(): Update {
val tagUrl = "https://api.github.com/repos/LagradOst/CloudStream-3/git/ref/tags/pre-release"