Rename stuffs

This commit is contained in:
topjohnwu 2023-06-30 03:03:51 -07:00
parent 92f980601c
commit 46770db18b

View File

@ -11,9 +11,13 @@ import androidx.core.os.postDelayed
import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.StubApk
import com.topjohnwu.magisk.core.* import com.topjohnwu.magisk.core.AppApkPath
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.di.ServiceLocator
import com.topjohnwu.magisk.core.ktx.copyAndClose as copyAndCloseBoth import com.topjohnwu.magisk.core.isRunningAsStub
import com.topjohnwu.magisk.core.ktx.copyAndClose
import com.topjohnwu.magisk.core.ktx.reboot import com.topjohnwu.magisk.core.ktx.reboot
import com.topjohnwu.magisk.core.ktx.toast import com.topjohnwu.magisk.core.ktx.toast
import com.topjohnwu.magisk.core.ktx.withStreams import com.topjohnwu.magisk.core.ktx.withStreams
@ -172,7 +176,7 @@ abstract class MagiskInstallImpl protected constructor(
return true return true
} }
private fun InputStream.copyAndClose(out: OutputStream) = out.use { copyTo(it) } private fun InputStream.copyAndCloseOut(out: OutputStream) = out.use { copyTo(it) }
private fun newTarEntry(name: String, size: Long): TarEntry { private fun newTarEntry(name: String, size: Long): TarEntry {
console.add("-- Writing: $name") console.add("-- Writing: $name")
@ -203,7 +207,7 @@ abstract class MagiskInstallImpl protected constructor(
console.add("-- Extracting: $name") console.add("-- Extracting: $name")
val extract = installDir.getChildFile(name) val extract = installDir.getChildFile(name)
decompressedStream().copyAndClose(extract.newOutputStream()) decompressedStream().copyAndCloseOut(extract.newOutputStream())
} else if (entry.name.contains("vbmeta.img")) { } else if (entry.name.contains("vbmeta.img")) {
val rawData = decompressedStream().readBytes() val rawData = decompressedStream().readBytes()
// Valid vbmeta.img should be at least 256 bytes // Valid vbmeta.img should be at least 256 bytes
@ -273,12 +277,12 @@ abstract class MagiskInstallImpl protected constructor(
} }
"init_boot.img" -> { "init_boot.img" -> {
console.add("- Extracting init_boot.img") console.add("- Extracting init_boot.img")
zipIn.copyAndClose(initBoot.newOutputStream()) zipIn.copyAndCloseOut(initBoot.newOutputStream())
return initBoot return initBoot
} }
"boot.img" -> { "boot.img" -> {
console.add("- Extracting boot.img") console.add("- Extracting boot.img")
zipIn.copyAndClose(boot.newOutputStream()) zipIn.copyAndCloseOut(boot.newOutputStream())
// Don't return here since there might be an init_boot.img // Don't return here since there might be an init_boot.img
} }
} }
@ -407,7 +411,7 @@ abstract class MagiskInstallImpl protected constructor(
} else { } else {
console.add("- Copying image to cache") console.add("- Copying image to cache")
installDir.getChildFile("boot.img").also { installDir.getChildFile("boot.img").also {
src.copyAndClose(it.newOutputStream()) src.copyAndCloseOut(it.newOutputStream())
} }
} }
} catch (e: IOException) { } catch (e: IOException) {
@ -444,7 +448,7 @@ abstract class MagiskInstallImpl protected constructor(
} }
outStream.putNextEntry(newTarEntry(name, newBoot.length())) outStream.putNextEntry(newTarEntry(name, newBoot.length()))
} }
newBoot.newInputStream().copyAndCloseBoth(outStream) newBoot.newInputStream().copyAndClose(outStream)
newBoot.delete() newBoot.delete()
console.add("") console.add("")