diff --git a/arsclib-utils/src/main/kotlin/app/revanced/arsc/resource/ResourceContainer.kt b/arsclib-utils/src/main/kotlin/app/revanced/arsc/resource/ResourceContainer.kt index 62bdc80..7a34a4a 100644 --- a/arsclib-utils/src/main/kotlin/app/revanced/arsc/resource/ResourceContainer.kt +++ b/arsclib-utils/src/main/kotlin/app/revanced/arsc/resource/ResourceContainer.kt @@ -76,16 +76,16 @@ class ResourceContainer(private val archive: Archive, internal val tableBlock: T * Create a [ResourceFile.Handle] that can be used to open a [ResourceFile]. * This may involve looking it up in the resource table to find the actual location in the archive. * - * @param resPath The path of the resource. + * @param path The path of the resource. */ - private fun createHandle(resPath: String): ResourceFile.Handle { - if (resPath.startsWith("res/values")) throw ApkResourceException.Decode("Decoding the resource table as a file is not supported") + private fun createHandle(path: String): ResourceFile.Handle { + if (path.startsWith("res/values")) throw ApkResourceException.Decode("Decoding the resource table as a file is not supported") var onClose = {} - var archivePath = resPath + var archivePath = path - if (tableBlock != null && resPath.startsWith("res/") && resPath.count { it == '/' } == 2) { - val file = File(resPath) + if (tableBlock != null && path.startsWith("res/") && path.count { it == '/' } == 2) { + val file = File(path) val qualifiers = EncodeUtil.getQualifiersFromResFile(file) val type = EncodeUtil.getTypeNameFromResFile(file) @@ -93,29 +93,28 @@ class ResourceContainer(private val archive: Archive, internal val tableBlock: T // The resource file names that the app developers used may have been minified, so we have to resolve it with the resource table. // Example: res/drawable-hdpi/icon.png -> res/4a.png - val resolvedPath = getEntry(type, name, qualifiers)?.resValue?.valueAsString - - if (resolvedPath != null) { - archivePath = resolvedPath - } else { + getEntry(type, name, qualifiers)?.resValue?.valueAsString?.let { + archivePath = it + } ?: run { // An entry for this specific resource file was not found in the resource table, so we have to register it after we save. - onClose = { set(type, name, StringResource(archivePath), qualifiers) } + onClose = { getOrCreateResource(type, name, StringResource(archivePath), qualifiers) } } } - return ResourceFile.Handle(resPath, archivePath, onClose) + return ResourceFile.Handle(path, archivePath, onClose) } /** - * Create or update an Android resource. + * Create or update a resource. * * @param type The resource type. * @param name The name of the resource. - * @param value The resource data. - * @param configuration The resource configuration. + * @param resource The resource data. + * @param qualifiers The resource configuration. + * @return The resource ID for the resource. */ - fun set(type: String, name: String, value: Resource, configuration: String? = null) = - getPackageBlock().getOrCreate(configuration, type, name).also { it.setTo(value) }.resourceId + fun getOrCreateResource(type: String, name: String, resource: Resource, qualifiers: String? = null) = + getPackageBlock().getOrCreate(qualifiers, type, name).also { it.setTo(resource) }.resourceId /** * Create or update multiple resources in an ARSC type block. diff --git a/arsclib-utils/src/main/kotlin/app/revanced/arsc/xml/LazyXMLInputSource.kt b/arsclib-utils/src/main/kotlin/app/revanced/arsc/xml/LazyXMLInputSource.kt index 19a228b..2019a64 100644 --- a/arsclib-utils/src/main/kotlin/app/revanced/arsc/xml/LazyXMLInputSource.kt +++ b/arsclib-utils/src/main/kotlin/app/revanced/arsc/xml/LazyXMLInputSource.kt @@ -28,7 +28,7 @@ internal class LazyXMLInputSource( listAttributes().forEach { attr -> if (attr.value.startsWith("@+id/")) { val name = attr.value.split('/').last() - resources.set("id", name, boolean(false)) + resources.getOrCreateResource("id", name, boolean(false)) attr.value = "@id/$name" } } diff --git a/revanced-patcher/src/main/kotlin/app/revanced/patcher/Patcher.kt b/revanced-patcher/src/main/kotlin/app/revanced/patcher/Patcher.kt index f8da01e..566ba8b 100644 --- a/revanced-patcher/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/revanced-patcher/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -147,6 +147,8 @@ class Patcher(private val options: PatcherOptions, patches: Iterable exception = patchException } + // TODO: only emit if the patch is not a closeable. + // If it is a closeable, this should be done when closing the patch. emit(patch.patchName to exception) if (stopOnError && exception != null) return@flow