refactor: cleanup code & fix warnings

This commit is contained in:
Sculas 2022-09-14 23:09:18 +02:00
parent 84813d34c6
commit eef9c2bf31
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
4 changed files with 252 additions and 254 deletions

View File

@ -16,12 +16,12 @@ import dalvik.system.DexClassLoader
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.Result
import java.io.File
private const val PATCHER_CHANNEL = "app.revanced.manager.flutter/patcher"
private const val INSTALLER_CHANNEL = "app.revanced.manager.flutter/installer"
class MainActivity : FlutterActivity() {
private val PATCHER_CHANNEL = "app.revanced.manager.flutter/patcher"
private val INSTALLER_CHANNEL = "app.revanced.manager.flutter/installer"
private val handler = Handler(Looper.getMainLooper())
private lateinit var installerChannel: MethodChannel
@ -73,12 +73,13 @@ class MainActivity : FlutterActivity() {
result.notImplemented()
}
}
else -> result.notImplemented()
}
}
}
fun runPatcher(
private fun runPatcher(
result: MethodChannel.Result,
patchBundleFilePath: String,
originalFilePath: String,
@ -99,8 +100,7 @@ class MainActivity : FlutterActivity() {
val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val patches =
DexPatchBundle(
val patches = DexPatchBundle(
patchBundleFilePath,
DexClassLoader(
patchBundleFilePath,
@ -108,12 +108,9 @@ class MainActivity : FlutterActivity() {
null,
javaClass.classLoader
)
)
.loadPatches()
.filter { patch -> selectedPatches.any { it == patch.patchName } }
).loadPatches().filter { patch -> selectedPatches.any { it == patch.patchName } }
Thread(
Runnable {
Thread {
handler.post {
installerChannel.invokeMethod(
"update",
@ -327,7 +324,6 @@ class MainActivity : FlutterActivity() {
handler.post { result.success(null) }
}
)
.start()
}
}

View File

@ -1,3 +1,5 @@
@file:Suppress("unused")
package app.revanced.manager.flutter.utils.zip
import java.io.DataInput
@ -17,8 +19,8 @@ fun UShort.toBigEndian() = (this.toUInt() shl 16).toBigEndian().toUShort()
fun ByteBuffer.getUShort() = this.short.toUShort()
fun ByteBuffer.getUInt() = this.int.toUInt()
fun ByteBuffer.putUShort(ushort: UShort) = this.putShort(ushort.toShort())
fun ByteBuffer.putUInt(uint: UInt) = this.putInt(uint.toInt())
fun ByteBuffer.putUShort(ushort: UShort): ByteBuffer = this.putShort(ushort.toShort())
fun ByteBuffer.putUInt(uint: UInt): ByteBuffer = this.putInt(uint.toInt())
fun DataInput.readUShort() = this.readShort().toUShort()
fun DataInput.readUInt() = this.readInt().toUInt()

View File

@ -10,7 +10,7 @@ import java.nio.channels.FileChannel
import java.util.zip.CRC32
import java.util.zip.Deflater
class ZipFile(val file: File) : Closeable {
class ZipFile(file: File) : Closeable {
var entries: MutableList<ZipEntry> = mutableListOf()
private val filePointer: RandomAccessFile = RandomAccessFile(file, "rw")
@ -134,8 +134,8 @@ class ZipFile(val file: File) : Closeable {
addEntry(entry, compressedBuffer)
}
fun addEntryCopyData(entry: ZipEntry, data: ByteBuffer, alignment: Int? = null) {
alignment?.let { alignment ->
private fun addEntryCopyData(entry: ZipEntry, data: ByteBuffer, alignment: Int? = null) {
alignment?.let {
//calculate where data would end up
val dataOffset = filePointer.filePointer + entry.LFHSize

View File

@ -76,7 +76,7 @@ data class ZipEntry(
val fileNameLength = input.readUShortLE()
var fileName = ""
val extraFieldLength = input.readUShortLE()
var extraField = ByteArray(extraFieldLength.toInt())
val extraField = ByteArray(extraFieldLength.toInt())
val fileCommentLength = input.readUShortLE()
var fileComment = ""
val diskNumber = input.readUShortLE()