|
|
|
|
@ -18,6 +18,7 @@ import com.cyb3rko.techniklogger.logE
|
|
|
|
|
import com.cyb3rko.techniklogger.showErrorToast
|
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
|
import es.dmoral.toasty.Toasty
|
|
|
|
|
import java.nio.charset.StandardCharsets
|
|
|
|
|
|
|
|
|
|
internal object Updater {
|
|
|
|
|
internal fun updateCheck(activity: Activity, feedback: Boolean) {
|
|
|
|
|
@ -32,21 +33,21 @@ internal object Updater {
|
|
|
|
|
.getAsString(object : StringRequestListener {
|
|
|
|
|
override fun onResponse(response: String?) {
|
|
|
|
|
try {
|
|
|
|
|
val rawContent = Regex("content\":\"([a-zA-Z\\d]+=)")
|
|
|
|
|
.find(response!!)!!
|
|
|
|
|
.groups[1]!!.value
|
|
|
|
|
val content = Base64.decode(rawContent, Base64.DEFAULT).decodeToString()
|
|
|
|
|
val version = Regex("versionName \"(.+)\"")
|
|
|
|
|
.find(content)!!
|
|
|
|
|
.groups[1]!!.value
|
|
|
|
|
val versionCode = Regex("versionCode (\\d+)")
|
|
|
|
|
.find(content)!!
|
|
|
|
|
.groups[1]!!.value.toInt()
|
|
|
|
|
var parts = response!!.split("content\":\"")
|
|
|
|
|
var parts2 = parts[1].split("\",\"target")
|
|
|
|
|
val content = String(Base64.decode(parts2[0], Base64.DEFAULT), StandardCharsets.UTF_8)
|
|
|
|
|
|
|
|
|
|
parts = content.split("versionCode ")
|
|
|
|
|
parts2 = parts[1].split("\n")
|
|
|
|
|
val neuesterVersionCode = parts2[0].toInt()
|
|
|
|
|
parts = parts2[1].split("\"")
|
|
|
|
|
parts2 = parts[1].split("\"")
|
|
|
|
|
val newestVersion = parts2[0]
|
|
|
|
|
|
|
|
|
|
dialog?.cancel()
|
|
|
|
|
if (BuildConfig.VERSION_CODE < versionCode) {
|
|
|
|
|
logD("App-Update verfügbar: $version")
|
|
|
|
|
showDownloadDialog(activity, version)
|
|
|
|
|
if (BuildConfig.VERSION_CODE != neuesterVersionCode) {
|
|
|
|
|
logD("App-Update verfügbar: $newestVersion")
|
|
|
|
|
showDownloadDialog(activity, newestVersion)
|
|
|
|
|
|
|
|
|
|
ActivityCompat.requestPermissions(
|
|
|
|
|
activity, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1
|
|
|
|
|
|