fix: filtration of patches malfunctioning

Apparently, you were not able to include patches explicitly
This commit is contained in:
oSumAtrIX 2023-08-25 23:47:05 +02:00
parent be5d812dff
commit 2d5a7fdf1e
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -68,11 +68,11 @@ internal object PatchCommand : Runnable {
private var exclusive = false private var exclusive = false
@CommandLine.Option( @CommandLine.Option(
names = ["--experimental"], names = ["-f","--force"],
description = ["Ignore patches incompatibility to versions"], description = ["Force inclusion of patches that are incompatible with the supplied APK file's version"],
showDefaultValue = ALWAYS showDefaultValue = ALWAYS
) )
private var experimental: Boolean = false private var force: Boolean = false
@CommandLine.Option( @CommandLine.Option(
names = ["-o", "--out"], description = ["Path to save the patched APK file to"], required = true names = ["-o", "--out"], description = ["Path to save the patched APK file to"], required = true
@ -225,8 +225,8 @@ internal object PatchCommand : Runnable {
* - [includedPatches] (explicitly included) * - [includedPatches] (explicitly included)
* - [excludedPatches] (explicitly excluded) * - [excludedPatches] (explicitly excluded)
* - [exclusive] (only include patches that are explicitly included) * - [exclusive] (only include patches that are explicitly included)
* - [experimental] (ignore patches incompatibility to versions) * - [force] (ignore patches incompatibility to versions)
* - package name and version of the input APK file (if [experimental] is false) * - Package name and version of the input APK file (if [force] is false)
* *
* @param patches The patches to filter. * @param patches The patches to filter.
* @return The filtered patches. * @return The filtered patches.
@ -238,46 +238,22 @@ internal object PatchCommand : Runnable {
patches.forEach patch@{ patch -> patches.forEach patch@{ patch ->
val formattedPatchName = patch.patchName.lowercase().replace(" ", "-") val formattedPatchName = patch.patchName.lowercase().replace(" ", "-")
/** val explicitlyExcluded = excludedPatches.contains(formattedPatchName)
* Check if the patch is explicitly excluded. if (explicitlyExcluded) return@patch logger.info("Excluding ${patch.patchName}")
*
* Cases:
* 1. -e patch.name
* 2. -i patch.name -e patch.name
*/
/** // If the patch is explicitly included, it will be included if [exclusive] is false.
* Check if the patch is explicitly excluded. val explicitlyIncluded = exclusive && includedPatches.contains(formattedPatchName)
*
* Cases:
* 1. -e patch.name
* 2. -i patch.name -e patch.name
*/
val excluded = excludedPatches.contains(formattedPatchName) // If the patch is implicitly included, it will be only included if [exclusive] is false.
if (excluded) return@patch logger.info("Excluding ${patch.patchName}") val implicitlyIncluded = !exclusive && patch.include
/** val included = implicitlyIncluded || explicitlyIncluded
* Check if the patch is constrained to packages. if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1.
*/
/**
* Check if the patch is constrained to packages.
*/
// At last make sure the patch is compatible with the supplied APK files package name and version.
patch.compatiblePackages?.let { packages -> patch.compatiblePackages?.let { packages ->
packages.singleOrNull { it.name == packageName }?.let { `package` -> packages.singleOrNull { it.name == packageName }?.let { `package` ->
/** val matchesVersion = force || `package`.versions.let {
* Check if the package version matches.
* If experimental is true, version matching will be skipped.
*/
/**
* Check if the package version matches.
* If experimental is true, version matching will be skipped.
*/
val matchesVersion = experimental || `package`.versions.let {
it.isEmpty() || it.any { version -> version == packageVersion } it.isEmpty() || it.any { version -> version == packageVersion }
} }
@ -287,38 +263,13 @@ internal object PatchCommand : Runnable {
"${pkg.name}: ${pkg.versions.joinToString(", ")}" "${pkg.name}: ${pkg.versions.joinToString(", ")}"
}) })
} } ?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. "
?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. " + "This patch is only compatible with " + packages.joinToString( + "This patch is only compatible with "
", " + packages.joinToString(", ") { `package` -> `package`.name })
) { `package` -> `package`.name })
return@let return@let
} ?: logger.fine("$formattedPatchName: No constraint on packages.") } ?: logger.fine("$formattedPatchName: No constraint on packages.")
/**
* Check if the patch is explicitly included.
*
* Cases:
* 1. --exclusive
* 2. --exclusive -i patch.name
*/
/**
* Check if the patch is explicitly included.
*
* Cases:
* 1. --exclusive
* 2. --exclusive -i patch.name
*/
val explicitlyIncluded = includedPatches.contains(formattedPatchName)
val implicitlyIncluded = !exclusive && patch.include // Case 3.
val exclusivelyIncluded = exclusive && explicitlyIncluded // Case 2.
val included = implicitlyIncluded || exclusivelyIncluded
if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1.
logger.fine("Adding $formattedPatchName") logger.fine("Adding $formattedPatchName")
add(patch) add(patch)