Skip to content

Commit

Permalink
refactor: move code out of try block
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jul 26, 2023
1 parent e0f8e1b commit 1bca84e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/main/kotlin/app/revanced/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ class Patcher(private val options: PatcherOptions) {

when (resourceDecodingMode) {
ResourceDecodingMode.FULL -> {
val cacheDirectory = ExtFile(options.resourceCacheDirectory)
try {
logger.info("Compiling resources")
logger.info("Compiling resources")

val aaptFile = cacheDirectory.resolve("aapt_temp_file").also {
Files.deleteIfExists(it.toPath())
}
val cacheDirectory = ExtFile(options.resourceCacheDirectory)
val aaptFile = cacheDirectory.resolve("aapt_temp_file").also {
Files.deleteIfExists(it.toPath())
}.also { resourceFile = it }

try {
AaptInvoker(
config,
context.packageMetadata.apkInfo
Expand All @@ -111,8 +111,6 @@ class Patcher(private val options: PatcherOptions) {
}.toTypedArray()
}
)

resourceFile = aaptFile
} finally {
cacheDirectory.close()
}
Expand Down Expand Up @@ -183,7 +181,6 @@ class Patcher(private val options: PatcherOptions) {
val extInputFile = ExtFile(options.inputFile)
try {
val resourcesDecoder = ResourcesDecoder(config, extInputFile)
val resourceTable = resourcesDecoder.resTable

when (mode) {
ResourceDecodingMode.FULL -> {
Expand Down Expand Up @@ -213,7 +210,7 @@ class Patcher(private val options: PatcherOptions) {
// use the XmlPullStreamDecoder in order to get necessary information from the manifest
// used below.
XmlPullStreamDecoder(AndroidManifestResourceParser().apply {
attrDecoder = ResAttrDecoder().apply { this.resTable = resourceTable }
attrDecoder = ResAttrDecoder().apply { this.resTable = resourcesDecoder.resTable }
}, ExtMXSerializer().apply {
setProperty(
ExtXmlSerializer.PROPERTY_SERIALIZER_INDENTATION, " "
Expand Down Expand Up @@ -241,7 +238,7 @@ class Patcher(private val options: PatcherOptions) {
context.packageMetadata.let { metadata ->
metadata.apkInfo = resourcesDecoder.apkInfo

metadata.packageName = resourceTable.currentResPackage.name
metadata.packageName = resourcesDecoder.resTable.currentResPackage.name
resourcesDecoder.apkInfo.versionInfo.let {
metadata.packageVersion = it.versionName ?: it.versionCode
}
Expand Down

0 comments on commit 1bca84e

Please sign in to comment.