diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index 9757070832..b2cd73db5c 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -1230,7 +1230,7 @@ class MainActivity : ComponentActivity() { // The libraries, off the main thread: manifests and a folder scan. Thread({ val games = if (ready) Library.steamGames(this) + com.droiddeck.launcher.frontend.AddedGames.scan(this).map { g -> - com.droiddeck.launcher.frontend.AddedGameArt.resolve(this, g).let { art -> Library.SteamGame(g.appId.toInt(), g.name, art.portrait ?: art.header, "added", g.gameId) } + com.droiddeck.launcher.frontend.AddedGameArt.resolve(this, g).let { art -> Library.SteamGame(g.appId.toInt(), g.name, art.portrait ?: art.header, "added", g.gameId, hero = art.hero ?: art.header) } } else emptyList() val emus = Library.emulators(this) { id -> DesktopCatalog.installed(this, id) != null } ui.post { steamGames = games; emulatorList = emus } 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 3ed6de0a4e..96610d0cf1 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -14,7 +14,14 @@ import java.io.File */ object Library { /** [gameId] is what steam://rungameid/ takes: the appid for a Steam title, the shortcut id for an added game. */ - class SteamGame(val appId: Int, val name: String, val art: File?, val library: String, val gameId: Long = appId.toLong()) + /** + * [art] is the portrait capsule; [hero] the wide banner Steam shows above a game's page, when + * the client has cached one. [lastPlayed] is Steam's own "LastPlayed" (unix seconds), 0 = never. + */ + class SteamGame( + val appId: Int, val name: String, val art: File?, val library: String, val gameId: Long = appId.toLong(), + val hero: File? = null, val lastPlayed: Long = 0L, + ) class Rom(val name: String, val hostPath: File, val guestPath: String, val emulatorId: String, val art: File? = null) class Emulator(val id: String, val name: String, val system: String, val program: String, val installed: Boolean, val games: List) { /** The emulator's own icon, bundled (the runtime keeps them as theme SVGs the app cannot draw). */ @@ -55,8 +62,10 @@ object Library { 4690330, // Legacy Steam Runtime ) private val STEAM_CAPSULES = listOf("library_capsule.jpg", "library_600x900.jpg") + private val STEAM_HEROES = listOf("library_hero.jpg") private val NAME = Regex("^\\s*\"name\"\\s*\"([^\"]*)\"", RegexOption.MULTILINE) private val STATE = Regex("^\\s*\"StateFlags\"\\s*\"(\\d+)\"", RegexOption.MULTILINE) + private val LAST_PLAYED = Regex("^\\s*\"LastPlayed\"\\s*\"(\\d+)\"", RegexOption.MULTILINE) fun steamGames(context: Context): List { val root = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam") @@ -77,19 +86,21 @@ object Library { val flags = STATE.find(text)?.groupValues?.get(1)?.toIntOrNull() ?: 0 // StateFlags 4 = fully installed; anything else is downloading, updating or broken. if (name.isEmpty() || flags and 4 == 0) return@forEach - val art = steamCapsule(cache, appId) - out[appId] = SteamGame(appId, name, art, label) + val art = steamCacheImage(cache, appId, STEAM_CAPSULES) + val hero = steamCacheImage(cache, appId, STEAM_HEROES) + val lastPlayed = LAST_PLAYED.find(text)?.groupValues?.get(1)?.toLongOrNull() ?: 0L + out[appId] = SteamGame(appId, name, art, label, hero = hero, lastPlayed = lastPlayed) } } return out.values.toList() } - /** Steam stores current library capsules inside hash-named folders under the app's cache dir. */ - private fun steamCapsule(cache: File, appId: Int): File? { + /** Steam stores current library art inside hash-named folders under the app's cache dir. */ + private fun steamCacheImage(cache: File, appId: Int, names: List): File? { val appDir = File(cache, appId.toString()) val dirs = listOf(appDir) + appDir.listFiles() .orEmpty().filter { it.isDirectory }.sortedBy { it.name } - return STEAM_CAPSULES.asSequence() + return names.asSequence() .flatMap { name -> dirs.asSequence().map { File(it, name) } } .firstOrNull { it.isFile && it.length() > 0L } }