mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-05-02 23:04:25 +02:00
refactor: cleanup code & fix warnings
This commit is contained in:
parent
84813d34c6
commit
eef9c2bf31
@ -16,12 +16,12 @@ import dalvik.system.DexClassLoader
|
|||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import io.flutter.plugin.common.MethodChannel.Result
|
|
||||||
import java.io.File
|
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() {
|
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 val handler = Handler(Looper.getMainLooper())
|
||||||
private lateinit var installerChannel: MethodChannel
|
private lateinit var installerChannel: MethodChannel
|
||||||
|
|
||||||
@ -73,12 +73,13 @@ class MainActivity : FlutterActivity() {
|
|||||||
result.notImplemented()
|
result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> result.notImplemented()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runPatcher(
|
private fun runPatcher(
|
||||||
result: MethodChannel.Result,
|
result: MethodChannel.Result,
|
||||||
patchBundleFilePath: String,
|
patchBundleFilePath: String,
|
||||||
originalFilePath: String,
|
originalFilePath: String,
|
||||||
@ -99,8 +100,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
val integrations = File(integrationsPath)
|
val integrations = File(integrationsPath)
|
||||||
val keyStoreFile = File(keyStoreFilePath)
|
val keyStoreFile = File(keyStoreFilePath)
|
||||||
|
|
||||||
val patches =
|
val patches = DexPatchBundle(
|
||||||
DexPatchBundle(
|
|
||||||
patchBundleFilePath,
|
patchBundleFilePath,
|
||||||
DexClassLoader(
|
DexClassLoader(
|
||||||
patchBundleFilePath,
|
patchBundleFilePath,
|
||||||
@ -108,12 +108,9 @@ class MainActivity : FlutterActivity() {
|
|||||||
null,
|
null,
|
||||||
javaClass.classLoader
|
javaClass.classLoader
|
||||||
)
|
)
|
||||||
)
|
).loadPatches().filter { patch -> selectedPatches.any { it == patch.patchName } }
|
||||||
.loadPatches()
|
|
||||||
.filter { patch -> selectedPatches.any { it == patch.patchName } }
|
|
||||||
|
|
||||||
Thread(
|
Thread {
|
||||||
Runnable {
|
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel.invokeMethod(
|
||||||
"update",
|
"update",
|
||||||
@ -327,7 +324,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
|
|
||||||
handler.post { result.success(null) }
|
handler.post { result.success(null) }
|
||||||
}
|
}
|
||||||
)
|
|
||||||
.start()
|
.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
package app.revanced.manager.flutter.utils.zip
|
package app.revanced.manager.flutter.utils.zip
|
||||||
|
|
||||||
import java.io.DataInput
|
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.getUShort() = this.short.toUShort()
|
||||||
fun ByteBuffer.getUInt() = this.int.toUInt()
|
fun ByteBuffer.getUInt() = this.int.toUInt()
|
||||||
|
|
||||||
fun ByteBuffer.putUShort(ushort: UShort) = this.putShort(ushort.toShort())
|
fun ByteBuffer.putUShort(ushort: UShort): ByteBuffer = this.putShort(ushort.toShort())
|
||||||
fun ByteBuffer.putUInt(uint: UInt) = this.putInt(uint.toInt())
|
fun ByteBuffer.putUInt(uint: UInt): ByteBuffer = this.putInt(uint.toInt())
|
||||||
|
|
||||||
fun DataInput.readUShort() = this.readShort().toUShort()
|
fun DataInput.readUShort() = this.readShort().toUShort()
|
||||||
fun DataInput.readUInt() = this.readInt().toUInt()
|
fun DataInput.readUInt() = this.readInt().toUInt()
|
||||||
|
@ -10,7 +10,7 @@ import java.nio.channels.FileChannel
|
|||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
import java.util.zip.Deflater
|
import java.util.zip.Deflater
|
||||||
|
|
||||||
class ZipFile(val file: File) : Closeable {
|
class ZipFile(file: File) : Closeable {
|
||||||
var entries: MutableList<ZipEntry> = mutableListOf()
|
var entries: MutableList<ZipEntry> = mutableListOf()
|
||||||
|
|
||||||
private val filePointer: RandomAccessFile = RandomAccessFile(file, "rw")
|
private val filePointer: RandomAccessFile = RandomAccessFile(file, "rw")
|
||||||
@ -134,8 +134,8 @@ class ZipFile(val file: File) : Closeable {
|
|||||||
addEntry(entry, compressedBuffer)
|
addEntry(entry, compressedBuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEntryCopyData(entry: ZipEntry, data: ByteBuffer, alignment: Int? = null) {
|
private fun addEntryCopyData(entry: ZipEntry, data: ByteBuffer, alignment: Int? = null) {
|
||||||
alignment?.let { alignment ->
|
alignment?.let {
|
||||||
//calculate where data would end up
|
//calculate where data would end up
|
||||||
val dataOffset = filePointer.filePointer + entry.LFHSize
|
val dataOffset = filePointer.filePointer + entry.LFHSize
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ data class ZipEntry(
|
|||||||
val fileNameLength = input.readUShortLE()
|
val fileNameLength = input.readUShortLE()
|
||||||
var fileName = ""
|
var fileName = ""
|
||||||
val extraFieldLength = input.readUShortLE()
|
val extraFieldLength = input.readUShortLE()
|
||||||
var extraField = ByteArray(extraFieldLength.toInt())
|
val extraField = ByteArray(extraFieldLength.toInt())
|
||||||
val fileCommentLength = input.readUShortLE()
|
val fileCommentLength = input.readUShortLE()
|
||||||
var fileComment = ""
|
var fileComment = ""
|
||||||
val diskNumber = input.readUShortLE()
|
val diskNumber = input.readUShortLE()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user