fix: versioning of downloaded components
This commit is contained in:
parent
c50dc12f2e
commit
c6e94d9864
7 changed files with 44 additions and 22 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package com.aliucord.manager.network.dto
|
||||
|
||||
import com.aliucord.manager.network.utils.SemVer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ data class BuildInfo(
|
|||
val discordVersionCode: String,
|
||||
@SerialName("versionName")
|
||||
val discordVersionName: String,
|
||||
@SerialName("aliucordHash")
|
||||
val injectorVersion: String,
|
||||
|
||||
val injectorVersion: SemVer,
|
||||
val patchesVersion: SemVer,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,16 @@
|
|||
package com.aliucord.manager.network.utils
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
/**
|
||||
* Parses a Semantic version in the format of `v1.0.0` (v[major].[minor].[patch])
|
||||
*/
|
||||
@Serializable(SemVer.Serializer::class)
|
||||
data class SemVer(
|
||||
val major: Int,
|
||||
val minor: Int,
|
||||
|
|
@ -43,18 +51,29 @@ data class SemVer(
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun parse(version: String, vPrefix: Boolean = false): SemVer? {
|
||||
if (vPrefix && version.getOrNull(0) != 'v')
|
||||
return null
|
||||
fun parse(version: String): SemVer = parseOrNull(version)
|
||||
?: throw IllegalArgumentException("Invalid semver string $version")
|
||||
|
||||
val str = if (vPrefix) version.substring(1) else version
|
||||
val parts = str
|
||||
fun parseOrNull(version: String): SemVer? {
|
||||
val versionStr = version.removePrefix("v")
|
||||
val parts = versionStr
|
||||
.split(".")
|
||||
.mapNotNull { it.toIntOrNull() }
|
||||
.takeIf { it.size == 3 }
|
||||
?: return null
|
||||
|
||||
return SemVer(parts[0], parts[1], parts[2])
|
||||
return SemVer(parts[0], parts[1], parts[2], version[0] == 'v')
|
||||
}
|
||||
}
|
||||
|
||||
object Serializer : KSerializer<SemVer> {
|
||||
override val descriptor = PrimitiveSerialDescriptor("SemVer", PrimitiveKind.STRING)
|
||||
|
||||
override fun deserialize(decoder: Decoder) =
|
||||
parse(decoder.decodeString())
|
||||
|
||||
override fun serialize(encoder: Encoder, value: SemVer) {
|
||||
encoder.encodeString(value.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.aliucord.manager.patcher
|
||||
|
||||
import com.aliucord.manager.network.utils.SemVer
|
||||
import com.aliucord.manager.ui.screens.patchopts.PatchOptions
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
|
@ -13,23 +14,23 @@ data class InstallMetadata(
|
|||
*/
|
||||
val options: PatchOptions,
|
||||
|
||||
/**
|
||||
* The semver version of this manager that performed the installation.
|
||||
*/
|
||||
val managerVersionName: String,
|
||||
|
||||
/**
|
||||
* Whether the manager is a real release or built from source.
|
||||
*/
|
||||
val customManager: Boolean,
|
||||
|
||||
/**
|
||||
* Version of the Aliucord release build that was injected into the APK.
|
||||
* The semver version of this manager that performed the installation.
|
||||
*/
|
||||
val managerVersion: SemVer,
|
||||
|
||||
/**
|
||||
* Version (commit hash) of the Aliuhook build that was injected into the APK.
|
||||
*/
|
||||
val aliuhookVersion: String,
|
||||
|
||||
/**
|
||||
* Version of the injector build that was injected into the APK.
|
||||
*/
|
||||
val injectorVersion: String,
|
||||
val injectorVersion: SemVer,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class DownloadInjectorStep : DownloadStep(), IDexProvider, KoinComponent {
|
|||
|
||||
override suspend fun execute(container: StepRunner) {
|
||||
targetVersion = container.getStep<FetchInfoStep>()
|
||||
.data.injectorVersion
|
||||
.data.injectorVersion.toString()
|
||||
|
||||
super.execute(container)
|
||||
}
|
||||
|
|
@ -45,6 +45,6 @@ class DownloadInjectorStep : DownloadStep(), IDexProvider, KoinComponent {
|
|||
}
|
||||
|
||||
override val dexCount = 1
|
||||
override val dexPriority = 10
|
||||
override val dexPriority = 3
|
||||
override fun getDexFiles() = listOf(targetFile.readBytes())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.aliucord.manager.patcher.steps.patch
|
|||
|
||||
import com.aliucord.manager.BuildConfig
|
||||
import com.aliucord.manager.R
|
||||
import com.aliucord.manager.network.utils.SemVer
|
||||
import com.aliucord.manager.patcher.InstallMetadata
|
||||
import com.aliucord.manager.patcher.StepRunner
|
||||
import com.aliucord.manager.patcher.steps.StepGroup
|
||||
|
|
@ -33,10 +34,10 @@ class SaveMetadataStep(private val options: PatchOptions) : Step() {
|
|||
|
||||
val metadata = InstallMetadata(
|
||||
options = options,
|
||||
managerVersionName = BuildConfig.VERSION_NAME,
|
||||
customManager = IS_CUSTOM_BUILD,
|
||||
managerVersion = SemVer.parse(BuildConfig.VERSION_NAME),
|
||||
aliuhookVersion = aliuhook.targetVersion,
|
||||
injectorVersion = injector.targetVersion,
|
||||
injectorVersion = SemVer.parse(injector.targetVersion),
|
||||
)
|
||||
|
||||
ZipWriter(apk, /* append = */ true).use {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.aliucord.manager.ui.screens.patching
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.StringRes
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class UpdaterViewModel(
|
|||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val (version, asset) = github.getManagerReleases().getOrNull()
|
||||
?.mapNotNull { release ->
|
||||
val version = SemVer.parse(release.tagName, vPrefix = true)
|
||||
val version = SemVer.parseOrNull(release.tagName)
|
||||
?: return@mapNotNull null
|
||||
|
||||
val asset = release.assets.find { it.name == "aliucord-manager-${release.tagName}.apk" }
|
||||
|
|
@ -73,7 +73,7 @@ class UpdaterViewModel(
|
|||
?.maxByOrNull { it.first }
|
||||
?: return@launch
|
||||
|
||||
val currentVersion = SemVer.parse(BuildConfig.VERSION_NAME)
|
||||
val currentVersion = SemVer.parseOrNull(BuildConfig.VERSION_NAME)
|
||||
?: throw Error("Failed to parse app version")
|
||||
|
||||
if (currentVersion >= version)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue