mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(xbox): mount external storage for downloads
This commit is contained in:
1 parent
fcfbb74068
commit
2c8ae3753c
5 files changed
+48
-6
No files matched your search
@@ -104,6 +104,15 @@ object StoreInstallRoot {
|
||||
.map { it to guestFor(context, it) }
|
||||
}
|
||||
|
||||
fun externalBindSpecs(context: Context): List<String> = externalBindSpecs(externalRoots(context), LinuxRuntime.rootDir(context))
|
||||
|
||||
internal fun externalBindSpecs(roots: List<Pair<File, String>>, guestRoot: File): List<String> =
|
||||
roots.mapNotNull { (host, guest) ->
|
||||
if (!host.isDirectory || !host.canRead()) return@mapNotNull null
|
||||
val target = File(guestRoot, guest.removePrefix("/"))
|
||||
if (target.isDirectory || target.mkdirs()) "${host.path}:$guest" else null
|
||||
}
|
||||
|
||||
private fun guestFor(context: Context, root: File): String {
|
||||
val sm = context.getSystemService(StorageManager::class.java)
|
||||
val uuid = runCatching { sm?.getStorageVolume(root)?.uuid }.getOrNull()?.takeIf { it.isNotBlank() }?.replace(Regex("[^A-Za-z0-9-]"), "")
|
||||
@@ -114,11 +123,18 @@ object StoreInstallRoot {
|
||||
fun isInternal(context: Context, root: File): Boolean = root.absolutePath == internalRoot(context).absolutePath
|
||||
|
||||
fun externalGuestPath(context: Context, host: File): String? {
|
||||
return externalGuestPath(host, externalRoots(context))
|
||||
}
|
||||
|
||||
fun guestPath(context: Context, host: File): String = externalGuestPath(context, host) ?: host.path
|
||||
|
||||
internal fun externalGuestPath(host: File, roots: List<Pair<File, String>>): String? {
|
||||
val path = host.absolutePath
|
||||
for ((root, guest) in externalRoots(context)) {
|
||||
val dir = root.absolutePath
|
||||
for ((root, guest) in roots.sortedByDescending { it.first.absolutePath.length }) {
|
||||
val dir = root.absolutePath.trimEnd(File.separatorChar)
|
||||
if (path == dir) return guest
|
||||
if (path.startsWith("$dir/")) return guest + "/" + path.removePrefix("$dir/")
|
||||
val prefix = dir + File.separator
|
||||
if (path.startsWith(prefix)) return guest + "/" + path.removePrefix(prefix).replace(File.separatorChar, '/')
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -39,8 +39,9 @@ internal class XboxInstaller(private val app: Context, private val item: Catalog
|
||||
var sequence = -1L
|
||||
try {
|
||||
val source = if (content) selected else item.id
|
||||
val guestFolder = StoreInstallRoot.guestPath(app, folder)
|
||||
val selection = if (content) emptyList() else listOf("--selected-content-id", selected)
|
||||
Xodus.start(app, listOf("streaming", source, folder.path, "--market", market,
|
||||
Xodus.start(app, listOf("streaming", source, guestFolder, "--market", market,
|
||||
"--progress-json", "--control-stdin") + selection).use { process ->
|
||||
child = process
|
||||
val diagnostics = Xodus.diagnostics(process)
|
||||
|
||||
@@ -46,7 +46,7 @@ internal object XboxRuntime {
|
||||
val market = game.second.extra["market"]?.takeIf { it.matches(Regex("[A-Z]{2}")) } ?: Xodus.market()
|
||||
val directory = views.create(app.filesDir)
|
||||
val process = try {
|
||||
Xodus.start(app, listOf("run", game.first.path, "droiddeck:prepare", "--exe", game.second.exe,
|
||||
Xodus.start(app, listOf("run", StoreInstallRoot.guestPath(app, game.first), "droiddeck:prepare", "--exe", game.second.exe,
|
||||
"--materialize-chain", "--market", market), launchDirectory = directory, credentialGeneration = credentials)
|
||||
} catch (e: Exception) { XboxLaunchViews.remove(directory); throw e }
|
||||
if (!launches.attach(token, process)) { process.close(); error("Xbox launch was cancelled") }
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.droiddeck.launcher.core.AddonPack
|
||||
import com.droiddeck.launcher.runtime.LinuxNetworkLinkComponent
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import org.json.JSONObject
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
@@ -79,7 +80,8 @@ internal object Xodus {
|
||||
networkLink.publish()
|
||||
networkLink.start()
|
||||
val runtime = (runtimeDirectory ?: File(app.filesDir, "xbox-runtime")).apply { mkdirs() }
|
||||
val command = LinuxRuntime.command(app, null, null, Environment.getExternalStorageDirectory(), listOf(
|
||||
val command = LinuxRuntime.command(app, null, null, Environment.getExternalStorageDirectory(),
|
||||
StoreInstallRoot.externalBindSpecs(app), listOf(
|
||||
"/usr/bin/env", "HOME=/root", "XODUS_LOG=off", "RUST_LOG=off",
|
||||
"XDG_RUNTIME_DIR=${runtime.path}", "DROIDDECK_XBOX_CREDENTIAL_SOCKET=${credentials.name}", binary,
|
||||
) + args)
|
||||
|
||||
Reference in new issue
Block a user