Skip to content

Commit

Permalink
i love that this app has 4 different systems for downlaoding files an…
Browse files Browse the repository at this point in the history
…d i even mix multiple in one install task
  • Loading branch information
nift4 committed Jul 31, 2024
1 parent 1fe0d4d commit 4226574
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 29 deletions.
49 changes: 43 additions & 6 deletions app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ private class CreatePartDataHolder(val vm: WizardActivityState): ProgressListene
var f = 0L
var t: String? = null
var noobMode: Boolean = false
var scriptInet: String? = null
var scriptShaInet: String? = null

var painter: @Composable (() -> Painter)? = null
var rtype by mutableStateOf("")
var cmdline by mutableStateOf("")
var shName by mutableStateOf("")
val dmaMeta = ArrayMap<String, String>()
val count = mutableIntStateOf(0)
val intVals = mutableStateListOf<Long>()
Expand Down Expand Up @@ -394,11 +395,13 @@ private fun Shop(c: CreatePartDataHolder) {
dmaMeta["name"] =
o.getString("displayname")
dmaMeta["creator"] = o.getString("creator")
c.scriptInet = o.getString("scriptname")
if (o.has("scriptSha256"))
c.scriptShaInet = o.getString("scriptSha256")
dmaMeta["updateJson"] = o.getString("updateJson")
rtype = o.getString("rtype")
cmdline =
o.getString("cmdline")
shName = o.getString("scriptname")
i = 0
val partitionParams = o.getJSONArray("partitions")
while (i < partitionParams.length()) {
Expand Down Expand Up @@ -794,6 +797,39 @@ private fun Download(c: CreatePartDataHolder) {
}
})
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Column {
Text(stringResource(id = R.string.installer_sh))
}
Column {
if (c.vm.flashes.containsKey("InstallShFlashType")) {
Button(onClick = {
c.vm.flashes.remove("InstallShFlashType")
}) {
Text(stringResource(R.string.undo))
}
} else {
if (c.scriptInet != null) {
Button(onClick = {
c.vm.flashes["InstallShFlashType"] = Pair(Uri.parse(c.scriptInet!!), c.scriptShaInet)
}) {
Text(stringResource(R.string.download))
}
}
Button(onClick = {
c.vm.activity.chooseFile("*/*") {
c.vm.flashes["InstallShFlashType"] = Pair(it, null)
}
}) {
Text(stringResource(R.string.choose))
}
}
}
}
for (i in c.idNeeded) {
val inet = c.inetAvailable.containsKey(i)
Row(
Expand Down Expand Up @@ -900,6 +936,9 @@ private fun Flash(c: CreatePartDataHolder) {
val gn = c.t3.value
terminal.add(vm.activity.getString(R.string.term_f_name, fn))
terminal.add(vm.activity.getString(R.string.term_g_name, gn))
val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir)
vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile)
tmpFile.setExecutable(true)
terminal.add(vm.activity.getString(R.string.term_creating_pt))

// After creating partitions:
Expand Down Expand Up @@ -957,17 +996,15 @@ private fun Flash(c: CreatePartDataHolder) {
}

terminal.add(vm.activity.getString(R.string.term_patching_os))
var cmd = "FORMATDATA=true " + File(
c.vm.logic.assetDir,
"Scripts/add_os/${c.vm.deviceInfo!!.codename}/${c.shName}"
).absolutePath + " $fn"
var cmd = "FORMATDATA=true " + tmpFile.absolutePath + " $fn"
for (i in c.extraIdNeeded) {
cmd += " " + c.chosen[i]!!.toFile(vm).absolutePath
}
for (i in parts) {
cmd += " " + i.value
}
val result = vm.logic.runShFileWithArgs(cmd).to(terminal).exec()
tmpFile.delete()
if (!result.isSuccess) {
terminal.add(vm.activity.getString(R.string.term_failure))
return
Expand Down
54 changes: 31 additions & 23 deletions app/src/main/java/org/andbootmgr/app/UpdateFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.*
Expand Down Expand Up @@ -72,7 +71,6 @@ private class UpdateFlowDataHolder(val vm: WizardActivityState) {
val partMapping = HashMap<Int, String>()
var extraParts = ArrayList<String>()
var updateJson: String? = null
var script: String? = null
val sparse = ArrayList<Int>()
}

Expand Down Expand Up @@ -123,7 +121,9 @@ private fun Start(u: UpdateFlowDataHolder) {
extraParts.add(extraIdNeeded.get(i) as String)
i++
}
script = j.getString("script")
vm.flashes["InstallShFlashType"] = Pair(
Uri.parse(j.getString("script")),
if (j.has("scriptSha256")) j.getString("scriptSha256") else null)
}
if (j.has("parts")) {
val sp = u.e!!["xpart"]!!.split(":")
Expand Down Expand Up @@ -158,7 +158,6 @@ private fun Start(u: UpdateFlowDataHolder) {
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun Local(u: UpdateFlowDataHolder) {
Column(verticalArrangement = Arrangement.SpaceEvenly) {
Expand All @@ -168,14 +167,22 @@ private fun Local(u: UpdateFlowDataHolder) {
Text(stringResource(R.string.local_updater_3))
}
Column {
var text by remember { mutableStateOf("") }
var error by remember { mutableStateOf(true) }
TextField(modifier = Modifier.fillMaxWidth(), value = text, isError = error, onValueChange = {
text = it
error = text.isBlank() || !File(u.vm.logic.assetDir, "Scripts/add_os/${u.vm.deviceInfo!!.codename}/${text}").exists()
}, label = {
Text(stringResource(R.string.script_name))
})
Text(stringResource(R.string.script_name))
if (u.vm.flashes.containsKey("InstallShFlashType")) {
Button(onClick = {
u.vm.flashes.remove("InstallShFlashType")
}) {
Text(stringResource(id = R.string.undo))
}
} else {
Button(onClick = {
u.vm.activity.chooseFile("*/*") {
u.vm.flashes["InstallShFlashType"] = Pair(it, null)
}
}) {
Text(stringResource(id = R.string.choose_file))
}
}
for (i in u.sbootfile) {
Row {
Text(stringResource(R.string.file_selected) + " " + (i.lastPathSegment ?: "(null)"))
Expand All @@ -186,12 +193,11 @@ private fun Local(u: UpdateFlowDataHolder) {
}
if (u.sbootfile.isNotEmpty()) {
Button(onClick = {
if (!error) {
if (u.vm.flashes.containsKey("InstallShFlashType")) {
u.hasUpdate = false
u.script = text
u.vm.navigate("flash")
}
}, enabled = !error) {
}, enabled = u.vm.flashes.containsKey("InstallShFlashType")) {
Text(stringResource(R.string.install_update))
}
}
Expand Down Expand Up @@ -282,6 +288,9 @@ private fun Flash(u: UpdateFlowDataHolder) {
}
pmap[p.key] = f
}
val tmpFile = createTempFileSu("abm", ".sh", u.vm.logic.rootTmpDir)
u.vm.copyPriv(u.vm.flashStream("InstallShFlashType"), tmpFile)
tmpFile.setExecutable(true)
u.vm.nextText.value = ""
u.vm.onNext.value = {}

Expand All @@ -307,17 +316,15 @@ private fun Flash(u: UpdateFlowDataHolder) {
}
if (u.extraParts.isNotEmpty()) {
terminal.add(u.vm.activity.getString(R.string.term_patch_update))
var cmd = "FORMATDATA=false " + File(
u.vm.logic.assetDir,
"Scripts/add_os/${u.vm.deviceInfo.codename}/${u.script}"
).absolutePath + " ${u.ef!!.nameWithoutExtension}"
var cmd = "FORMATDATA=false " + tmpFile.absolutePath + " ${u.ef!!.nameWithoutExtension}"
for (i in bootfile) {
cmd += " " + i.absolutePath
}
for (i in sp) {
cmd += " $i"
}
val r = u.vm.logic.runShFileWithArgs(cmd).to(terminal).exec()
tmpFile.delete()
bootfile.forEach { it.delete() }
if (!r.isSuccess) {
throw IllegalStateException(u.vm.activity.getString(R.string.term_script_fail))
Expand All @@ -331,6 +338,9 @@ private fun Flash(u: UpdateFlowDataHolder) {
}
} else if (u.sbootfile.isNotEmpty()) {
val bootfile = ArrayList<File>()
val tmpFile = createTempFileSu("abm", ".sh", u.vm.logic.rootTmpDir)
u.vm.copyPriv(u.vm.flashStream("InstallShFlashType"), tmpFile)
tmpFile.setExecutable(true)
terminal.add(u.vm.activity.getString(R.string.term_patch_update))
u.sbootfile.forEach {
val bootf = File(u.vm.logic.cacheDir, System.currentTimeMillis().toString())
Expand All @@ -340,17 +350,15 @@ private fun Flash(u: UpdateFlowDataHolder) {
)
bootfile.add(bootf)
}
var cmd = "FORMATDATA=false " + File(
u.vm.logic.assetDir,
"Scripts/add_os/${u.vm.deviceInfo!!.codename}/${u.script}"
).absolutePath + " ${u.ef!!.nameWithoutExtension}"
var cmd = "FORMATDATA=false " + tmpFile.absolutePath + " ${u.ef!!.nameWithoutExtension}"
for (i in bootfile) {
cmd += " " + i.absolutePath
}
for (i in sp) {
cmd += " $i"
}
val r = u.vm.logic.runShFileWithArgs(cmd).to(terminal).exec()
tmpFile.delete()
bootfile.forEach { it.delete() }
if (!r.isSuccess) {
throw IllegalStateException(u.vm.activity.getString(R.string.term_script_fail))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,5 @@
<string name="term_created_part">Created partition.</string>
<string name="term_created_pt">-- Created partition layout.</string>
<string name="shop_error">Failed loading list of ROMs from Open ROM Project</string>
<string name="installer_sh">Installer shell script</string>
</resources>

0 comments on commit 4226574

Please sign in to comment.