fix(steam): offer a Games folder as a Steam library when it is not already one (#2432)

* fix(steam): offer a Games folder as a Steam library when it is not already one

* test(steam): cover discovery with chosen storage

* fix(steam): compare Games folders and Steam libraries by the same storage path

The Games-folder overlap check used the raw canonical path, so a library saved under the raw card mount and the same folder under /storage were treated as different. Reuse the library canonicalisation.
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-11 20:55:52 -05:00
1 parent c177b1eed1
commit 3230ccdc73
3 files changed
+38 -8

No files matched your search

@@ -90,11 +90,11 @@ object GameStorage {
fun gamesFolderLibraries(context: Context): List<Library> {
if (SessionPrefs.gameStorage(context).isNotEmpty()) return emptyList()
val card = effective(context)?.let { canonical(File(it.path)) }
val added = SteamLibraries.list(context).map { canonical(it.host) }
val card = effective(context)?.let { SteamLibraries.canonical(File(it.path)) }
val added = SteamLibraries.list(context).map { SteamLibraries.canonical(it.host) }
val sm = context.getSystemService(StorageManager::class.java)
return AddedGames.roots(context).mapNotNull { root ->
val host = canonical(root.host)
val host = SteamLibraries.canonical(root.host)
if (!hasInstalledGames(root.host)) return@mapNotNull null
if ('"' in root.guest || '\\' in root.guest || !root.host.isDirectory || !root.host.canWrite()) return@mapNotNull null
if (card != null && (host == card || host.startsWith("$card/") || card.startsWith("$host/"))) return@mapNotNull null
@@ -109,8 +109,6 @@ object GameStorage {
internal fun hasInstalledGames(root: File): Boolean =
File(root, "steamapps").listFiles { f -> f.isFile && f.name.startsWith("appmanifest_") && f.name.endsWith(".acf") }?.isNotEmpty() == true
private fun canonical(file: File): String = runCatching { file.canonicalPath }.getOrDefault(file.absolutePath)
fun labelFor(context: Context, path: String): String =
options(context).firstOrNull { it.path == path }?.name
?: File(path).name.ifEmpty { context.getString(R.string.gstore_folder) }
@@ -82,13 +82,14 @@ object SteamLibraries {
/** Reads storage; call off the main thread. */
fun found(context: Context): List<Found> {
val entries = list(context)
val taken = taken(context, entries) + AddedGames.roots(context).map { canonical(it.host) }
val taken = taken(context, entries) + GameStorage.gamesFolderLibraries(context).map { canonical(it.host) }
val gamesFolders = AddedGames.roots(context).map { canonical(it.host) }
val hits = ArrayList<Pair<File, Int>>()
for (root in StorageRoots.list(context)) {
if (!root.readable) continue
for (dir in candidates(rawView(root.dir), SCAN_DEPTH)) {
val games = gameCount(dir)
if (games > 0 && File(dir, "steamapps").canWrite() && taken.none { overlaps(it, canonical(dir)) }) hits += dir to games
if (games > 0 && File(dir, "steamapps").canWrite() && offered(taken, gamesFolders, canonical(dir))) hits += dir to games
}
}
val picked = ArrayList<Pair<File, Int>>()
@@ -101,6 +102,9 @@ object SteamLibraries {
}
}
internal fun offered(taken: List<String>, gamesFolders: List<String>, dir: String): Boolean =
taken.none { overlaps(it, dir) } && gamesFolders.none { it != dir && overlaps(it, dir) }
/** The FUSE view under /storage hides files other apps wrote unless DroidDeck has all files access; the raw card mount does not. */
private fun rawView(dir: File): File {
if (!dir.path.startsWith("/storage/") || dir.path.startsWith("/storage/emulated")) return dir
@@ -171,7 +175,7 @@ object SteamLibraries {
internal fun overlaps(a: String, b: String): Boolean = a == b || a.startsWith("$b/") || b.startsWith("$a/")
private fun canonical(file: File): String = UsbLink.storagePath(runCatching { file.canonicalPath }.getOrDefault(file.absolutePath))
internal fun canonical(file: File): String = UsbLink.storagePath(runCatching { file.canonicalPath }.getOrDefault(file.absolutePath))
private const val SCAN_DEPTH = 2
private const val SCAN_LIMIT = 4000