Compare commits

...

5 Commits

Author SHA1 Message Date
semantic-release-bot
368c61c1bf chore(release): 2.7.0 [skip ci]
# [2.7.0](https://github.com/revanced/revanced-patcher/compare/v2.6.0...v2.7.0) (2022-08-01)

### Features

* `Closeable` patches ([bbd40bf](bbd40bf2f6))
2022-08-01 02:15:18 +00:00
oSumAtrIX
bbd40bf2f6 feat: Closeable patches 2022-08-01 04:12:33 +02:00
Sculas
3de999a2d3 refactor: remove ReplaceWith from DependencyType.SOFT 2022-07-31 18:35:02 +02:00
Sculas
83cbb2f110 Merge remote-tracking branch 'origin/main' into main 2022-07-31 18:31:50 +02:00
Sculas
fcc7fa75d0 refactor: deprecate DependencyType.SOFT
Soft dependencies will be removed when Patch Options is implemented.
2022-07-31 18:31:40 +02:00
5 changed files with 56 additions and 17 deletions

View File

@@ -1,3 +1,10 @@
# [2.7.0](https://github.com/revanced/revanced-patcher/compare/v2.6.0...v2.7.0) (2022-08-01)
### Features
* `Closeable` patches ([bbd40bf](https://github.com/revanced/revanced-patcher/commit/bbd40bf2f6ff200705f2bcb272dd1680bb244e3f))
# [2.6.0](https://github.com/revanced/revanced-patcher/compare/v2.5.2...v2.6.0) (2022-07-31)

View File

@@ -1,2 +1,2 @@
kotlin.code.style = official
version = 2.6.0
version = 2.7.0

View File

@@ -32,6 +32,7 @@ import org.jf.dexlib2.Opcodes
import org.jf.dexlib2.iface.ClassDef
import org.jf.dexlib2.iface.DexFile
import org.jf.dexlib2.writer.io.MemoryDataStore
import java.io.Closeable
import java.io.File
import java.nio.file.Files
@@ -247,13 +248,13 @@ class Patcher(private val options: PatcherOptions) {
*/
private fun applyPatch(
patch: Class<out Patch<Data>>,
appliedPatches: MutableMap<String, Boolean>
appliedPatches: LinkedHashMap<String, AppliedPatch>
): PatchResult {
val patchName = patch.patchName
// if the patch has already applied silently skip it
if (appliedPatches.contains(patchName)) {
if (!appliedPatches[patchName]!!)
if (!appliedPatches[patchName]!!.success)
return PatchResultError("'$patchName' did not succeed previously")
logger.trace("Skipping '$patchName' because it has already been applied")
@@ -298,10 +299,10 @@ class Patcher(private val options: PatcherOptions) {
return try {
val result = patchInstance.execute(data)
appliedPatches[patchName] = result.isSuccess()
appliedPatches[patchName] = AppliedPatch(patchInstance, result.isSuccess())
result
} catch (e: Exception) {
appliedPatches[patchName] = false
appliedPatches[patchName] = AppliedPatch(patchInstance, false)
PatchResultError(e)
}
}
@@ -313,23 +314,41 @@ class Patcher(private val options: PatcherOptions) {
*/
fun applyPatches(stopOnError: Boolean = false) = sequence {
logger.trace("Applying all patches")
val appliedPatches = mutableMapOf<String, Boolean>() // first is success, second is name
for (patch in data.patches) {
val patchResult = applyPatch(patch, appliedPatches)
val appliedPatches = LinkedHashMap<String, AppliedPatch>() // first is name
val result = if (patchResult.isSuccess()) {
Result.success(patchResult.success()!!)
} else {
Result.failure(patchResult.error()!!)
try {
for (patch in data.patches) {
val patchResult = applyPatch(patch, appliedPatches)
val result = if (patchResult.isSuccess()) {
Result.success(patchResult.success()!!)
} else {
Result.failure(patchResult.error()!!)
}
yield(patch.patchName to result)
if (stopOnError && patchResult.isError()) break
}
} finally {
// close all closeable patches in order
for ((patch, _) in appliedPatches.values.reversed()) {
if (patch !is Closeable) continue
yield(patch.patchName to result)
if (stopOnError && patchResult.isError()) break
patch.close()
}
}
}
}
/**
* A result of applying a [Patch].
*
* @param patchInstance The instance of the [Patch] that was applied.
* @param success The result of the [Patch].
*/
internal data class AppliedPatch(val patchInstance: Patch<Data>, val success: Boolean)
private fun BuildOptions.setBuildOptions(options: PatcherOptions) {
this.aaptPath = options.aaptPath
this.useAapt2 = true

View File

@@ -3,14 +3,16 @@ package app.revanced.patcher.patch
import app.revanced.patcher.data.Data
import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patcher.patch.impl.ResourcePatch
import java.io.Closeable
/**
* A ReVanced patch.
*
* Can either be a [ResourcePatch] or a [BytecodePatch].
* If it implements [Closeable], it will be closed after all patches have been executed.
* Closing will be done in reverse execution order.
*/
abstract class Patch<out T : Data> {
/**
* The main function of the [Patch] which the patcher will call.
*/

View File

@@ -39,4 +39,15 @@ annotation class DependsOn(
val type: DependencyType = DependencyType.HARD
)
enum class DependencyType { HARD, SOFT }
enum class DependencyType {
/**
* Enforces that the dependency is applied, even if it was not selected.
*/
HARD,
/**
* Applies the dependency only if it was selected.
*/
@Deprecated("Will be removed when Patch Options is implemented.")
SOFT
}