mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Game storage: a second Steam library on an SD card or a chosen folder
The runtime already knew how to register /mnt/bannerlator-sd with the client; the app never bound anything there, so the client only ever saw internal storage. The Steam cog's Game storage section offers every removable volume (through the app's own folder on it, the one place a card lets a targetSdk-28 app write) and any folder from the File Manager, proven writable first. The session binds the choice and names it (BL_LIBRARY_LABEL); bannerlator-steam-library registers it, or forgets it when nothing is bound. The client does the rest: asks where to install, shows both on Storage, moves games between them. device.txt records the choice.
This commit is contained in:
1 parent
2cbd015d80
commit
fa25451766
8 files changed
+171
-3
No files matched your search
@@ -50,6 +50,7 @@ import com.steamdeck.launcher.ui.RomsDialog
|
||||
import com.steamdeck.launcher.files.InAppFilePicker
|
||||
import com.steamdeck.launcher.session.SessionArtifacts
|
||||
import com.steamdeck.launcher.session.SessionState
|
||||
import com.steamdeck.launcher.session.GameStorage
|
||||
|
||||
/**
|
||||
* The whole app outside a session: is the runtime installed, is there a newer one, frame
|
||||
@@ -121,6 +122,11 @@ class MainActivity : ComponentActivity() {
|
||||
private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO)
|
||||
private var oscMode by mutableStateOf(SessionPrefs.OSC_AUTO)
|
||||
private var renderer by mutableStateOf("pixman")
|
||||
private var gameStorage by mutableStateOf("")
|
||||
private var storageOptions by mutableStateOf<List<Pair<String, String>>>(emptyList())
|
||||
private val pickGameStorage = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedPath(r.data)?.let { path -> setGameStorage(path, GameStorage.labelFor(this, path)) }
|
||||
}
|
||||
private var emulators by mutableStateOf<List<Pair<String, String>>>(emptyList())
|
||||
private var showEmulatorHelp by mutableStateOf(false)
|
||||
private var romsDir by mutableStateOf<String?>(null)
|
||||
@@ -204,6 +210,8 @@ class MainActivity : ComponentActivity() {
|
||||
directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null,
|
||||
mic = if (mode == SessionService.MODE_STEAM) mic else null,
|
||||
renderer = if (mode == SessionService.MODE_DESKTOP) renderer else null,
|
||||
gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null,
|
||||
storageOptions = storageOptions,
|
||||
),
|
||||
ModeSettingsActions(
|
||||
onResolution = { cap -> SessionPrefs.setResolutionCap(this, mode, cap); resolutionCap = cap },
|
||||
@@ -228,6 +236,10 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
},
|
||||
onRenderer = { r -> SessionPrefs.setDesktopRenderer(this, r); renderer = r },
|
||||
onGameStorage = { path, label -> setGameStorage(path, label) },
|
||||
onPickGameStorageFolder = {
|
||||
pickGameStorage.launch(InAppFilePicker.buildDirIntent(this, "Choose the game storage folder", gameStorage.ifEmpty { null }))
|
||||
},
|
||||
onDismiss = { settingsMode = null },
|
||||
),
|
||||
)
|
||||
@@ -367,9 +379,24 @@ class MainActivity : ComponentActivity() {
|
||||
directAudio = SessionPrefs.directAudio(this)
|
||||
mic = SessionPrefs.micEnabled(this)
|
||||
renderer = SessionPrefs.desktopRenderer(this)
|
||||
gameStorage = SessionPrefs.gameStorage(this)
|
||||
storageOptions = GameStorage.options(this).map { it.label to it.path }
|
||||
settingsMode = mode
|
||||
}
|
||||
|
||||
/** A second Steam library, proven writable first; "" = internal only. */
|
||||
private fun setGameStorage(path: String, label: String) {
|
||||
if (path.isNotEmpty()) {
|
||||
val problem = GameStorage.prepare(path)
|
||||
if (problem != null) {
|
||||
android.widget.Toast.makeText(this, "Not usable: $problem", android.widget.Toast.LENGTH_LONG).show()
|
||||
return
|
||||
}
|
||||
}
|
||||
SessionPrefs.setGameStorage(this, path, label)
|
||||
gameStorage = path
|
||||
}
|
||||
|
||||
private fun refreshDrivers() {
|
||||
val lm = LinuxVulkanDriverManager(this)
|
||||
linuxRows = LinuxVulkanDriver.optionValues(this).map { id ->
|
||||
|
||||
@@ -147,6 +147,7 @@ object DeviceReport {
|
||||
k("On-screen controls", SessionPrefs.oscMode(context))
|
||||
k("Touch mode", SessionPrefs.touchMode(context))
|
||||
k("Performance HUD", SessionPrefs.hudEnabled(context))
|
||||
k("Game storage", SessionPrefs.gameStorage(context).ifEmpty { "internal only" })
|
||||
|
||||
h("Android process limits")
|
||||
// Android 12 kills "phantom" processes - the children an app forks itself rather than
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.steamdeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.os.StatFs
|
||||
import android.os.storage.StorageManager
|
||||
import com.steamdeck.launcher.core.FileUtils
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Where a second Steam library can live on this device.
|
||||
*
|
||||
* An SD card is offered through the app's own folder on it ({@code Android/data/<pkg>/files/steam}):
|
||||
* the one place on a card a targetSdk-28 app may write without a permission prompt, and a real
|
||||
* filesystem path the session can bind. Any other folder comes from the File Manager's pick mode
|
||||
* and is checked for writing before it is accepted. Both are FUSE-backed on Android and stream
|
||||
* slowly (intro movies, big asset loads); internal stays the default and the dialog says so.
|
||||
*/
|
||||
object GameStorage {
|
||||
class Option(val label: String, val path: String)
|
||||
|
||||
/** Every removable volume, as its app folder, with the free space it has. */
|
||||
fun options(context: Context): List<Option> {
|
||||
val sm = context.getSystemService(StorageManager::class.java)
|
||||
return context.getExternalFilesDirs(null).orEmpty().filterNotNull().mapNotNull { dir ->
|
||||
val removable = try { Environment.isExternalStorageRemovable(dir) } catch (e: Exception) { false }
|
||||
if (!removable) return@mapNotNull null
|
||||
val volume = try { sm?.getStorageVolume(dir) } catch (e: Exception) { null }
|
||||
val name = volume?.getDescription(context)?.takeIf { it.isNotBlank() && !it.equals("android", true) } ?: "SD card"
|
||||
Option("$name · ${free(dir)} free", File(dir, "steam").absolutePath)
|
||||
}
|
||||
}
|
||||
|
||||
fun free(dir: File): String = try {
|
||||
FileUtils.sizeToString(StatFs(dir.path).availableBytes)
|
||||
} catch (e: Exception) {
|
||||
"?"
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes [path] a library root the session can bind - the folder and its steamapps/ - and proves
|
||||
* it writable. Returns why it cannot be used, or null when it can.
|
||||
*/
|
||||
fun prepare(path: String): String? {
|
||||
val root = File(path)
|
||||
val steamapps = File(root, "steamapps")
|
||||
if (!steamapps.isDirectory && !steamapps.mkdirs()) return "cannot create folders in $path"
|
||||
val probe = File(steamapps, ".writable")
|
||||
return try {
|
||||
if (!probe.createNewFile() && !probe.isFile) "cannot write in $path" else { probe.delete(); null }
|
||||
} catch (e: Exception) {
|
||||
"cannot write in $path (${e.message})"
|
||||
}
|
||||
}
|
||||
|
||||
/** The label the client shows for a chosen folder: its last name, or the volume's. */
|
||||
fun labelFor(context: Context, path: String): String =
|
||||
options(context).firstOrNull { it.path == path }?.label?.substringBefore(" ·")
|
||||
?: File(path).name.ifEmpty { "Folder" }
|
||||
}
|
||||
@@ -223,4 +223,19 @@ object SessionPrefs {
|
||||
* fullscreen session like Steam's, so it takes Steam's display, driver and HDR choices.
|
||||
*/
|
||||
fun prefMode(mode: String): String = if (mode == SessionService.MODE_RUN) SessionService.MODE_STEAM else mode
|
||||
|
||||
// ── Game storage ────────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* A second Steam library on this device: the folder bound at /mnt/bannerlator-sd and
|
||||
* registered with the client, which then asks where to install every game and shows both
|
||||
* on its Storage page. "" = internal only (the client's own library, the default).
|
||||
*/
|
||||
fun gameStorage(context: Context): String = prefs(context).getString("gameStorage", "") ?: ""
|
||||
|
||||
fun gameStorageLabel(context: Context): String = prefs(context).getString("gameStorageLabel", "SD Card") ?: "SD Card"
|
||||
|
||||
fun setGameStorage(context: Context, path: String, label: String) {
|
||||
prefs(context).edit().putString("gameStorage", path).putString("gameStorageLabel", label).apply()
|
||||
}
|
||||
}
|
||||
@@ -321,6 +321,21 @@ class SessionService : Service() {
|
||||
val home = File(LinuxRuntime.rootDir(this), "root")
|
||||
File(home, "Storage").mkdirs()
|
||||
binds.add(Environment.getExternalStorageDirectory().path + ":/root/Storage")
|
||||
// A second Steam library: the storage chosen in the Steam cog, at the path the runtime's
|
||||
// bannerlator-steam-library registers with the client. Nothing bound = the script removes
|
||||
// the entry, so the client never offers a place that is not there.
|
||||
val library = SessionPrefs.gameStorage(this).takeIf { it.isNotEmpty() }
|
||||
if (library != null) {
|
||||
val problem = GameStorage.prepare(library)
|
||||
if (problem == null) {
|
||||
File(LinuxRuntime.rootDir(this), "mnt/bannerlator-sd").mkdirs()
|
||||
binds.add("$library:/mnt/bannerlator-sd")
|
||||
guest.add("BL_LIBRARY_LABEL=" + SessionPrefs.gameStorageLabel(this).replace('"', ' '))
|
||||
Log.i(TAG, "game storage: $library -> /mnt/bannerlator-sd (\"${SessionPrefs.gameStorageLabel(this)}\")")
|
||||
} else {
|
||||
Log.w(TAG, "game storage: $problem; internal only this session")
|
||||
}
|
||||
}
|
||||
val roms = SessionPrefs.romsDir(this).takeIf { it.isNotEmpty() }?.let { File(it) }
|
||||
if (roms != null && roms.isDirectory && roms.canRead()) {
|
||||
File(home, "ROMs").mkdirs()
|
||||
|
||||
@@ -61,6 +61,9 @@ class ModeSettings(
|
||||
val mic: Boolean?,
|
||||
/** Desktop only. */
|
||||
val renderer: String?,
|
||||
/** Steam only: the second library's root ("" = internal only) and what this device offers. */
|
||||
val gameStorage: String? = null,
|
||||
val storageOptions: List<Pair<String, String>> = emptyList(),
|
||||
)
|
||||
|
||||
class ModeSettingsActions(
|
||||
@@ -78,6 +81,8 @@ class ModeSettingsActions(
|
||||
val onDirectAudio: (Boolean) -> Unit,
|
||||
val onMic: (Boolean) -> Unit,
|
||||
val onRenderer: (String) -> Unit,
|
||||
val onGameStorage: (path: String, label: String) -> Unit = { _, _ -> },
|
||||
val onPickGameStorageFolder: () -> Unit = {},
|
||||
val onDismiss: () -> Unit,
|
||||
)
|
||||
|
||||
@@ -102,6 +107,7 @@ fun ModeSettingsDialog(s: ModeSettings, a: ModeSettingsActions) {
|
||||
add(SettingsSection("panel", "Display driver"))
|
||||
add(SettingsSection("touch", if (steam) "Touch & controls" else "Touch"))
|
||||
if (steam) add(SettingsSection("audio", "Audio"))
|
||||
if (steam) add(SettingsSection("storage", "Game storage"))
|
||||
if (!steam) add(SettingsSection("renderer", "Renderer"))
|
||||
}
|
||||
}
|
||||
@@ -239,6 +245,32 @@ fun ModeSettingsDialog(s: ModeSettings, a: ModeSettingsActions) {
|
||||
s.mic, true, a.onMic,
|
||||
)
|
||||
}
|
||||
"storage" -> if (s.gameStorage != null) {
|
||||
Section(
|
||||
"Game storage",
|
||||
"Where Steam may install games. Internal is the client's own library and always there. A second " +
|
||||
"place is registered with the client at the next session start: it then asks where to install " +
|
||||
"every game, lists both on its Storage page, and can move a game between them itself.",
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Choice("Internal only — the default", s.gameStorage.isEmpty()) { a.onGameStorage("", "") }
|
||||
for ((label, path) in s.storageOptions) {
|
||||
Choice(label, s.gameStorage == path) { a.onGameStorage(path, label.substringBefore(" ·")) }
|
||||
}
|
||||
val custom = s.gameStorage.isNotEmpty() && s.storageOptions.none { it.second == s.gameStorage }
|
||||
if (custom) Choice("Folder: ${s.gameStorage}", true) {}
|
||||
OutlinedButton(onClick = a.onPickGameStorageFolder, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) {
|
||||
Text("Choose a folder…")
|
||||
}
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
"Slow for streaming: an SD card and the phone's shared storage go through Android's file layer, " +
|
||||
"and a game that streams video or big assets from there can stall. Keep such games internal; " +
|
||||
"use the second place for size. On a card, the app may write only inside its own folder, which " +
|
||||
"is the one offered.",
|
||||
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
"renderer" -> if (s.renderer != null) {
|
||||
Section(
|
||||
"Desktop renderer",
|
||||
|
||||
Reference in new issue
Block a user