From c7ecc073ab43f9e16017719547ffc7c8d1a394f0 Mon Sep 17 00:00:00 2001 From: HapeLee <1321903405@qq.com> Date: Tue, 30 Sep 2025 02:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E8=AF=AD=E4=B9=89=E5=8C=96?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 32 +++++++++++++++---- .../kazusa/help/update/AppUpdateGitHub.kt | 30 ++++++++++++++--- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cb7d71f3d..0bb3db797 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,14 +15,31 @@ plugins { } apply from: 'download.gradle' -static def releaseTime() { - return new Date().format("yy.MMddHH", TimeZone.getTimeZone("GMT+8")) +ext { + versionMajor = 3 + versionMinor = 25 + versionPatch = 9 } def name = "legado" -def version = "3." + releaseTime() def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.trim()) +ext.versionBuild = gitCommits +ext.versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}" + +def getGitCommitHash() { + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--short', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim() + } catch (Exception ignored) { + return "unknown" + } +} + android { compileSdk = compile_sdk_version namespace 'io.legato.kazusa' @@ -52,9 +69,9 @@ android { minSdk 26 targetSdk 36 versionCode 10000 + gitCommits - versionName version + versionName project.ext.versionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - project.ext.set("archivesBaseName", name + "_" + version) + project.ext.set("archivesBaseName", name + "_" + versionName) buildConfigField "String", "Cronet_Version", "\"$CronetVersion\"" buildConfigField "String", "Cronet_Main_Version", "\"$CronetMainVersion\"" @@ -98,7 +115,7 @@ android { manifestPlaceholders.put("app_name", "@string/app_name") //applicationIdSuffix '.debug' - versionNameSuffix 'debug' + versionNameSuffix "_debug-${getGitCommitHash()}" minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'cronet-proguard-rules.pro' } @@ -127,7 +144,8 @@ android { variant.outputs.configureEach { output -> def abi = output.getFilter(com.android.build.OutputFile.ABI) def flavor = variant.productFlavors[0].name - def apkName = "${name}_${flavor}_${defaultConfig.versionName}" + def baseVersionName = variant.versionName + def apkName = "${name}_${flavor}_${baseVersionName}" if (abi != null) { apkName += "_${abi}" } diff --git a/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt b/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt index 0856f06ab..bea1f17aa 100644 --- a/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt +++ b/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt @@ -80,14 +80,34 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface { } fun String.versionCompare(other: String): Int { - val thisParts = this.split(".") - val otherParts = other.split(".") + val regex = Regex("""(\d+)|(\D+)""") + val thisParts = regex.findAll(this).map { it.value }.toList() + val otherParts = regex.findAll(other).map { it.value }.toList() val maxLength = maxOf(thisParts.size, otherParts.size) + for (i in 0 until maxLength) { - val thisPart = thisParts.getOrNull(i)?.toIntOrNull() ?: 0 - val otherPart = otherParts.getOrNull(i)?.toIntOrNull() ?: 0 - if (thisPart != otherPart) return thisPart - otherPart + val a = thisParts.getOrNull(i) + val b = otherParts.getOrNull(i) + + if (a == null) return -1 + if (b == null) return 1 + + val isANum = a.all { it.isDigit() } + val isBNum = b.all { it.isDigit() } + + if (isANum && a.length > 1 && a.startsWith("0")) return -1 + if (isBNum && b.length > 1 && b.startsWith("0")) return 1 + + val cmp = if (isANum && isBNum) { + a.toInt() - b.toInt() + } else { + a.compareTo(b) + } + + if (cmp != 0) return cmp } + return 0 } + }