add version consistency check

This commit is contained in:
chinosk 2025-01-22 16:03:10 +00:00
parent 0218543935
commit ade47131f9
Signed by: chinosk
GPG Key ID: 00610B08C1BF7BE9
4 changed files with 41 additions and 6 deletions

View File

@ -15,8 +15,9 @@ android {
applicationId "io.github.chinosk.gakumas.localify"
minSdk 29
targetSdk 34
versionCode 10
versionName "v2.0.2"
versionCode 11
versionName "v2.1.0"
buildConfigField "String", "VERSION_NAME", "\"${versionName}\""
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@ -1510,10 +1510,6 @@ namespace GakumasLocal::HookMain {
Local::LoadData();
MasterLocal::LoadData();
if (Config::lazyInit) {
UnityResolveProgress::classProgress.current = 1;
// UnityResolveProgress::startInit = false;
}
UnityResolveProgress::startInit = false;
Log::Info("Plugin init finished.");

View File

@ -107,6 +107,7 @@ fun <T> T.onClickStartGame() where T : Activity, T : IHasConfigItems {
getProgramConfigContent(listOf("transRemoteZipUrl", "useAPIAssetsURL",
"localAPIAssetsVersion", "p"), programConfig)
)
putExtra("lVerName", version)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}

View File

@ -248,6 +248,9 @@ class GakumasHookMain : IXposedHookLoadPackage, IXposedHookZygoteInit {
val gkmsData = intent.getStringExtra("gkmsData")
val programData = intent.getStringExtra("localData")
if (gkmsData != null) {
val readVersion = intent.getStringExtra("lVerName")
checkPluginVersion(activity, readVersion)
gkmsDataInited = true
val initConfig = try {
json.decodeFromString<GakumasConfig>(gkmsData)
@ -313,6 +316,40 @@ class GakumasHookMain : IXposedHookLoadPackage, IXposedHookZygoteInit {
}
}
private fun checkPluginVersion(activity: Activity, readVersion: String?) {
val buildVersionName = BuildConfig.VERSION_NAME
Log.i(TAG, "Checking Plugin Version: Build: $buildVersionName, Request: $readVersion")
if (readVersion?.trim() == buildVersionName.trim()) {
return
}
val builder = AlertDialog.Builder(activity)
val infoBuilder = AlertDialog.Builder(activity)
builder.setTitle("Warning")
builder.setCancelable(false)
builder.setMessage(when (getCurrentLanguage(activity)) {
"zh" -> "检测到插件版本不一致\n内置版本: $buildVersionName\n请求版本: $readVersion\n\n这可能是使用了 LSPatch 的集成模式,仅更新了插件本体,未重新修补游戏导致的。请使用 $readVersion 版本的插件重新修补或使用本地模式。"
else -> "Detected plugin version mismatch\nBuilt-in version: $buildVersionName\nRequested version: $readVersion\n\nThis may be caused by using the LSPatch integration mode, where only the plugin itself was updated without re-patching the game. Please re-patch the game using the $readVersion version of the plugin or use the local mode."
})
builder.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
builder.setNegativeButton("Exit") { dialog, _ ->
dialog.dismiss()
activity.finishAffinity()
}
val dialog = builder.create()
infoBuilder.setOnCancelListener {
dialog.show()
}
dialog.show()
}
private fun showGetConfigFailedImpl(activity: Context, title: String, msg: String, infoButton: String, dlButton: String, okButton: String) {
if (getConfigError == null) return
val builder = AlertDialog.Builder(activity)