diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt index f437de9a36..e255d314b6 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -104,7 +104,9 @@ object Library { // The root itself only one deep, for a file left loose there. val systemDirs = romsRoot.listFiles { f -> f.isDirectory && f.name.lowercase() in spec.folders }.orEmpty().toList() val dirs = LinkedHashSet() - for (top in systemDirs) top.walkTopDown().maxDepth(3).filter { it.isDirectory }.forEach { dirs.add(it) } + // A BIOS folder holds the console's firmware, not games (psx/bios/SCPH1001.BIN). + for (top in systemDirs) top.walkTopDown().maxDepth(3).onEnter { it.name.lowercase() !in firmwareFolders } + .filter { it.isDirectory }.forEach { dirs.add(it) } dirs.add(romsRoot) // ...and not into another system's folder: a PS3 .iso in ps3/ is not a PS2 game. romsRoot.listFiles { f -> f.isDirectory && f.name.lowercase() !in systemFolders }?.forEach { dirs.add(it) } @@ -117,10 +119,15 @@ object Library { art = File(dir, "PS3_GAME/ICON0.PNG").takeIf { it.isFile })) continue } - dir.listFiles()?.sortedBy { it.name.lowercase() }?.forEach { f -> + val files = dir.listFiles()?.sortedBy { it.name.lowercase() }.orEmpty() + // A disc sheet (.cue, .gdi) names its track files and a playlist (.m3u) its + // discs: the sheet is the game, what it names is part of it. A .bin beside a + // .cue of the same name is a track even when the sheet can't be read. + val parts = files.filter { it.isFile && it.extension.lowercase() in sheetExts }.flatMap(::sheetParts).toSet() + files.forEach { f -> val ext = f.extension.lowercase() - // A .bin beside a .cue is a track, not a game. - if (f.isFile && ext in spec.exts && !(ext == "bin" && File(dir, f.nameWithoutExtension + ".cue").isFile)) { + if (f.isFile && ext in spec.exts && f.name.lowercase() !in parts && + !(ext == "bin" && File(dir, f.nameWithoutExtension + ".cue").isFile)) { val rel = f.relativeTo(romsRoot).path games.add(Rom(displayTitle(f.nameWithoutExtension.removeSuffix(".dec")), f, "/root/ROMs/$rel", spec.id)) } @@ -134,6 +141,25 @@ object Library { } } + private val firmwareFolders = setOf("bios", "firmware") + private val sheetExts = setOf("cue", "gdi", "m3u") + + /** The file names (lower case) a .cue, .gdi or .m3u refers to, from its own folder. */ + private fun sheetParts(sheet: File): List = runCatching { + if (sheet.length() > 64 * 1024) return emptyList() + sheet.readLines().mapNotNull { line -> + val t = line.trim() + when (sheet.extension.lowercase()) { + // FILE "Tekken 3 (USA) (Track 1).bin" BINARY + "cue" -> Regex("^FILE\\s+\"([^\"]+)\"", RegexOption.IGNORE_CASE).find(t)?.groupValues?.get(1) + ?: Regex("^FILE\\s+(\\S+)", RegexOption.IGNORE_CASE).find(t)?.groupValues?.get(1) + // 1 0 4 2352 "track01.bin" 0 / 1 0 4 2352 track01.bin 0 + "gdi" -> Regex("\"([^\"]+)\"").find(t)?.groupValues?.get(1) ?: t.split(Regex("\\s+")).getOrNull(4) + else -> t.takeIf { it.isNotEmpty() && !it.startsWith("#") } + } + }.map { File(it.replace('\\', '/')).name.lowercase() } + }.getOrDefault(emptyList()) + /** * What RPCS3 has installed on its own HDD - packages (PSN games) land in dev_hdd0/game/ * with a PARAM.SFO for the title and an EBOOT to boot - as RPCS3's own file list would show diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 0f949f56c0..0d355d5d93 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -273,6 +273,10 @@ private class FrontFocus { val items = HashMap() val attached = HashMap() var last: String? = null + // The first tile of the page's grid: Down from the page's buttons goes to it, not to whichever + // tile happens to sit under the button. + val firstTile = FocusRequester() + var firstTileAttached = 0 fun paneEntry(): FocusRequester { val id = last return when { @@ -285,6 +289,24 @@ private class FrontFocus { companion object { const val PRIMARY = "\u0000primary" } } +/** Down from this button goes to the first tile of the page's grid, when there is one. */ +@Composable +private fun Modifier.downToFirstTile(): Modifier { + val ff = LocalFrontFocus.current ?: return this + return this.focusProperties { down = if (ff.firstTileAttached > 0) ff.firstTile else FocusRequester.Default } +} + +/** Marks the first tile of the page's grid. */ +@Composable +private fun Modifier.firstTile(): Modifier { + val ff = LocalFrontFocus.current ?: return this + DisposableEffect(Unit) { + ff.firstTileAttached++ + onDispose { ff.firstTileAttached-- } + } + return this.focusRequester(ff.firstTile) +} + /** Lets the pane come back to this control: it is remembered when focused. */ @Composable private fun Modifier.paneItem(id: String): Modifier { @@ -328,7 +350,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com LaunchedEffect(s.isHomeApp) { if (!s.isHomeApp && selected == "android-apps") selected = "steam" } remember { Motion.scale = Settings.Global.getFloat(ctx.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f); true } - BoxWithConstraints(modifier = Modifier.fillMaxSize().background(colors.background).systemBarsPadding()) { + var anyFocused by remember { mutableStateOf(false) } + BoxWithConstraints(modifier = Modifier.fillMaxSize().background(colors.background).systemBarsPadding().onFocusChanged { anyFocused = it.hasFocus }) { val wide = maxWidth >= 640.dp val railSelection = when { s.pageKey == "performance" || s.pageKey == "protons" -> "setup" @@ -364,6 +387,17 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com kotlinx.coroutines.delay(100) } } + // A tile or button that opens a page goes away with the page it was on, and focus with it; + // the pad then had nothing to move from (a press landed back on the rail's first item). So + // once the new page is in, a controller lands on its main button. + val inputModeManager = LocalInputModeManager.current + LaunchedEffect(selected, s.pageKey) { + kotlinx.coroutines.delay(450) + if (!anyFocused && inputModeManager.inputMode == InputMode.Keyboard) runCatching { + if (frontFocus.primaryAttached > 0) frontFocus.primary.requestFocus() + else frontFocus.railFor(railSelection).requestFocus() + } + } val back = if (wide) FocusDirection.Left else FocusDirection.Up val paneFocus = Modifier .focusProperties { @@ -998,7 +1032,7 @@ private fun PrimaryButton(text: String, enabled: Boolean = true, main: Boolean = frontFocus.primaryAttached++ onDispose { frontFocus.primaryAttached-- } } - val track = if (frontFocus == null) Modifier.paneItem("btn:$text") else Modifier + val track = (if (frontFocus == null) Modifier.paneItem("btn:$text") else Modifier).downToFirstTile() val src = remember { MutableInteractionSource() } val hot = rememberHot(src) && enabled val pressed by src.collectIsPressedAsState() @@ -1033,7 +1067,7 @@ internal fun SecondaryButton(text: String, enabled: Boolean = true, onClick: () val edge by animateColorAsState(if (hot) pal.signal else pal.line2, Motion.tw(250), label = "secEdge") val fill by animateColorAsState(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.03f), Motion.tw(250), label = "secFill") Box( - modifier = Modifier.paneItem("btn:$text").graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(fill).border(1.dp, edge, Shape12) + modifier = Modifier.paneItem("btn:$text").downToFirstTile().graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(fill).border(1.dp, edge, Shape12) .alpha(if (enabled) 1f else 0.5f) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick) .controllerConfirm(enabled = enabled, onClick = onClick) @@ -1051,7 +1085,7 @@ private fun Cog(onClick: () -> Unit) { val edge by animateColorAsState(if (hot) pal.signal else pal.line2, Motion.tw(250), label = "cogEdge") Box( contentAlignment = Alignment.Center, - modifier = Modifier.paneItem("cog").size(42.dp).clip(Shape12).background(Color.White.copy(alpha = 0.03f)).border(1.dp, edge, Shape12) + modifier = Modifier.paneItem("cog").downToFirstTile().size(42.dp).clip(Shape12).background(Color.White.copy(alpha = 0.03f)).border(1.dp, edge, Shape12) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onClick), ) { Icon(Icons.Filled.Settings, "Settings", tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(18.dp).rotate(rot)) } } @@ -1092,7 +1126,8 @@ private fun ArtGrid(tiles: List, wide: Boolean = false) { for (t in row) key(t.key) { val src = remember { MutableInteractionSource() } val hot = rememberHot(src) - Box(modifier = Modifier.width(tileWidth).zIndex(if (hot) 1f else 0f)) { GameTile(t, wide, square, src, hot, Modifier.paneItem("tile:" + t.key)) } + val track = Modifier.paneItem("tile:" + t.key).then(if (t === tiles.first()) Modifier.firstTile() else Modifier) + Box(modifier = Modifier.width(tileWidth).zIndex(if (hot) 1f else 0f)) { GameTile(t, wide, square, src, hot, track) } } } } diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults b/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults index e9ca2b5d58..88e56d76de 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults @@ -266,9 +266,10 @@ def duckstation(): if not os.path.isfile(ini) and os.path.isfile(legacy): ini = legacy if not os.path.isfile(ini): - # A new player: DuckStation's own first-time setup still runs, looking in the ROMs folder. + # A new player: everything DuckStation's first-time setup asks is answered here (it finds + # the BIOS in its folder by itself), so a game from the front end boots straight away. bios = bios_folder(ps1) - seed(ini, "[Main]\nSetupWizardIncomplete = true\n\n" + seed(ini, "[Main]\nSetupWizardIncomplete = false\nInhibitScreensaver = false\n\n" f"[BIOS]\nSearchDirectory = {bios}\n\n" f"[GameList]\nRecursivePaths = {ps1}\n\n" "[GPU]\nRenderer = Vulkan\n\n" @@ -281,6 +282,15 @@ def duckstation(): done="the guide button opens the pause menu") patch_ini_section(ini, "GameList", f"RecursivePaths = {ps1}\n", "DuckStation", needle=ROMS, done="games listed from the ROMs folder") + # One set up by an earlier build still has its first-time setup pending, in the way of a game. + if ini_get(ini, "Main", "SetupWizardIncomplete") == "true": + ini_set(ini, "Main", "SetupWizardIncomplete", "false") + print("bannerlator-pad-defaults: DuckStation: first-time setup already done here") + # Keeping the screen awake goes through org.freedesktop.ScreenSaver, which nothing in the session + # provides (Android decides when the screen sleeps): DuckStation only warns it failed, every game. + if (ini_get(ini, "Main", "InhibitScreensaver") or "true") == "true": + ini_set(ini, "Main", "InhibitScreensaver", "false") + print("bannerlator-pad-defaults: DuckStation: no screensaver inhibit (no such service here)") # Once, for a DuckStation set up before this: its own empty BIOS folder moves to the ROMs folder, # and Automatic becomes Vulkan. A later choice in DuckStation's settings is kept. marker = os.path.join(os.path.dirname(ini), ".droiddeck-setup") @@ -443,17 +453,18 @@ def armsx2(): shutil.copytree(src, os.path.join(root, sub), dirs_exist_ok=True) print(f"bannerlator-pad-defaults: ARMSX2: settings and memory cards copied from PCSX2 ({root})") elif not os.path.isfile(ini): - # A new player: ARMSX2's own first-time setup still runs (SetupWizardIncomplete) to pick the - # BIOS, but looking in the ROMs folder, with the ps2 folder as its game list and the - # controller already on Player 1. + # A new player: everything ARMSX2's first-time setup asks is answered here - the BIOS + # folder in the ROMs folder, the ps2 folder as its game list, the controller on Player 1 - + # and the BIOS file itself is picked below once one is there. bios, games = ps2_bios_folder(), ps2_folder() - seed(ini, "[UI]\nSettingsVersion = 1\nSetupWizardIncomplete = true\n\n" + seed(ini, "[UI]\nSettingsVersion = 1\nSetupWizardIncomplete = false\n\n" f"[Folders]\nBios = {bios}\n\n" f"[GameList]\nRecursivePaths = {games}\n\n" # Vulkan outright rather than Auto's pick: the renderer every other path here uses. "[EmuCore/GS]\nRenderer = 14\n\n" "[Hotkeys]\nOpenPauseMenu = Keyboard/Escape\nOpenPauseMenu = SDL-0/Guide\n\n" "[Pad1]\n" + ARMSX2_PAD1, "ARMSX2", "first-time setup, BIOS from " + bios) + armsx2_bios(ini) return patch_ini_section(ini, "Pad1", ARMSX2_PAD1, "ARMSX2", require="SettingsVersion") # The guide button is the pause menu here; PCSX2's profile (ours, copied over) had it as the @@ -469,6 +480,34 @@ def armsx2(): require="SettingsVersion", done="the guide button opens the pause menu") patch_ini_section(ini, "GameList", f"RecursivePaths = {ps2_folder()}\n", "ARMSX2", needle=ROMS, require="SettingsVersion", done="games listed from the ROMs folder") + if ini_get(ini, "UI", "SetupWizardIncomplete") == "true": + ini_set(ini, "UI", "SetupWizardIncomplete", "false") + print("bannerlator-pad-defaults: ARMSX2: first-time setup already done here") + armsx2_bios(ini) + + +def armsx2_bios(ini): + """PCSX2 boots the one BIOS file named in [Filenames] BIOS (inside [Folders] Bios); its first-time + setup is what names it. With that skipped, the first dump in the folder is named here - a US one + first - while none is named or the named one is gone. A choice made in ARMSX2 is kept.""" + folder = ini_get(ini, "Folders", "Bios") or ps2_bios_folder() + if not os.path.isabs(folder): + folder = os.path.join(os.path.dirname(os.path.dirname(ini)), folder) + current = ini_get(ini, "Filenames", "BIOS") + if current and os.path.isfile(os.path.join(folder, current)): + return + try: + # A PS2 BIOS dump is 4 MiB (a few are 8); the .nvm/.mec files beside it are not dumps. + dumps = sorted(f for f in os.listdir(folder) + if os.path.isfile(os.path.join(folder, f)) and 4 << 20 <= os.path.getsize(os.path.join(folder, f)) <= 8 << 20) + except OSError: + return + if not dumps: + return + us = [f for f in dumps if any(t in f.lower() for t in ("usa", "(us)", "(us,", "ntsc-u"))] + pick = (us or dumps)[0] + ini_set(ini, "Filenames", "BIOS", pick) + print(f"bannerlator-pad-defaults: ARMSX2: BIOS {pick}") def dolphin():