use correct version in root installs

This commit is contained in:
Ax333l 2024-12-10 17:47:38 +01:00
parent a85ad4ea0e
commit fd013ab5d7
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23

View File

@ -76,19 +76,20 @@ class PatcherViewModel(
private val installedAppRepository: InstalledAppRepository by inject() private val installedAppRepository: InstalledAppRepository by inject()
private val rootInstaller: RootInstaller by inject() private val rootInstaller: RootInstaller by inject()
val installerStatusDialogModel : InstallerStatusDialogModel = object : InstallerStatusDialogModel { val installerStatusDialogModel: InstallerStatusDialogModel =
override var packageInstallerStatus: Int? by mutableStateOf(null) object : InstallerStatusDialogModel {
override var packageInstallerStatus: Int? by mutableStateOf(null)
override fun reinstall() { override fun reinstall() {
this@PatcherViewModel.reinstall() this@PatcherViewModel.reinstall()
} }
override fun install() { override fun install() {
// Since this is a package installer status dialog, // Since this is a package installer status dialog,
// InstallType.MOUNT is never used here. // InstallType.MOUNT is never used here.
install(InstallType.DEFAULT) install(InstallType.DEFAULT)
}
} }
}
private var installedApp: InstalledApp? = null private var installedApp: InstalledApp? = null
val packageName: String = input.selectedApp.packageName val packageName: String = input.selectedApp.packageName
@ -341,7 +342,8 @@ class PatcherViewModel(
// Check if the app version is less than the installed version // Check if the app version is less than the installed version
if (pm.getVersionCode(currentPackageInfo) < pm.getVersionCode(existingPackageInfo)) { if (pm.getVersionCode(currentPackageInfo) < pm.getVersionCode(existingPackageInfo)) {
// Exit if the selected app version is less than the installed version // Exit if the selected app version is less than the installed version
installerStatusDialogModel.packageInstallerStatus = PackageInstaller.STATUS_FAILURE_CONFLICT installerStatusDialogModel.packageInstallerStatus =
PackageInstaller.STATUS_FAILURE_CONFLICT
return@launch return@launch
} }
} }
@ -377,20 +379,23 @@ class PatcherViewModel(
} }
} }
val inputVersion = input.selectedApp.version
?: inputFile?.let(pm::getPackageInfo)?.versionName
?: throw Exception("Failed to determine input APK version")
// Install as root // Install as root
rootInstaller.install( rootInstaller.install(
outputFile, outputFile,
inputFile, inputFile,
packageName, packageName,
// input.selectedApp.version? inputVersion,
packageInfo.versionName!!,
label label
) )
installedAppRepository.addOrUpdate( installedAppRepository.addOrUpdate(
packageInfo.packageName, packageInfo.packageName,
packageName, packageName,
packageInfo.versionName!!, inputVersion,
InstallType.MOUNT, InstallType.MOUNT,
input.selectedPatches input.selectedPatches
) )
@ -410,7 +415,7 @@ class PatcherViewModel(
} }
} }
} }
} catch(e: Exception) { } catch (e: Exception) {
Log.e(tag, "Failed to install", e) Log.e(tag, "Failed to install", e)
app.toast(app.getString(R.string.install_app_fail, e.simpleMessage())) app.toast(app.getString(R.string.install_app_fail, e.simpleMessage()))
} finally { } finally {