fix: stop importing games as Spacewar (480) and follow a changed Steam app id (#1896)

This commit is contained in:
K11MCH1 authored and GitHub committed 2026-10-31 13:36:43 -04:00
1 parent 88719f25d2
commit 583f34fc55
9 files changed
+303 -26

No files matched your search

@@ -287,14 +287,17 @@ object AddedGameArt {
var sgdbDown = false
var changed = false
for (game in games) {
if (forgetOtherAppsArt(context, game)) changed = true
val cache = cacheDir(context, game)
val start = missing(context, game)
val again = refetch(cache) intersect start
if (again.isEmpty()) File(cache, REFETCH).delete()
val full = Slot.COVER in start
val allowed = if (full) Slot.values().toSet() else EXTRAS
val allowed = if (full) Slot.values().toSet() else EXTRAS + again
var need = start intersect allowed
if (need.isEmpty() || (need == setOf(Slot.ICON) && sgdbKey.isEmpty())) continue
val cache = cacheDir(context, game)
val tried = File(cache, EXTRAS_TRIED)
if (!full && tried.isFile && tried.lastModified() >= keyChangedAt && System.currentTimeMillis() - tried.lastModified() < RETRY_AFTER_MS) continue
if (!full && again.isEmpty() && tried.isFile && tried.lastModified() >= keyChangedAt && System.currentTimeMillis() - tried.lastModified() < RETRY_AFTER_MS) continue
cache.mkdirs()
if (Slot.LOGO in need && game.source != Library.ADDED && runCatching { sources.storeLogo(game) }.getOrDefault(false)) {
changed = true
@@ -324,11 +327,42 @@ object AddedGameArt {
asked = false
}
}
if ((missing(context, game) intersect EXTRAS).isEmpty()) tried.delete() else if (asked) tried.writeText("")
val left = missing(context, game)
if (again.isNotEmpty()) keepRefetch(cache, again intersect left)
if ((left intersect EXTRAS).isEmpty()) tried.delete() else if (asked) tried.writeText("")
}
return changed
}
internal const val REFETCH = "refetch"
private fun refetch(cache: File): Set<Slot> =
runCatching { File(cache, REFETCH).readText() }.getOrDefault("").split(',').mapNotNull { key -> Slot.values().firstOrNull { it.key == key } }.toSet()
private fun keepRefetch(cache: File, slots: Set<Slot>) {
if (slots.isEmpty()) File(cache, REFETCH).delete() else File(cache, REFETCH).writeText(slots.joinToString(",") { it.key })
}
internal fun forgetOtherAppsArt(context: Context, game: AddedGames.Game): Boolean {
val cache = cacheDir(context, game)
val recorded = SteamMatch.get(context, game.folder.path)?.takeIf { it.appId != null }
val legacy = runCatching { File(cache, "steam-appid").readText().trim().toInt() }.getOrNull()?.takeIf { it > 0 }
val before = recorded?.appId ?: legacy ?: return false
val identity = runCatching { GameIdentifier.identify(game.exe) }.getOrNull()
val now = identity?.appId
val fromFiles = recorded?.certainty == SteamMatch.Certainty.FILES || before == GameIdentifier.SPACEWAR
if (now == before || (now == null && !fromFiles)) return false
SteamMatch.put(context, game.folder.path,
if (identity != null && now != null) SteamMatch.Match(now, SteamMatch.Certainty.FILES, identity.source.name.lowercase(), System.currentTimeMillis())
else SteamMatch.Match(null, SteamMatch.Certainty.NONE, "", 0))
val dropped = Slot.values().filter { File(cache, SteamGridDb.cacheName(it)).delete() }.toSet()
Slot.values().forEach { File(cache, SteamGridDb.cacheName(it) + ".src").delete() }
listOf("sgdb-id", "steam-appid", EXTRAS_TRIED).forEach { File(cache, it).delete() }
keepRefetch(cache, refetch(cache) + dropped)
Log.i(TAG, "${game.name}: its files no longer name Steam app $before; its art is fetched again")
return dropped.isNotEmpty()
}
internal fun steamMatch(context: Context, game: AddedGames.Game, search: (String) -> Int?): SteamMatch.Match {
if (game.source == Store.BATTLENET.id) {
val id = game.storeId?.let(BattleNet::title)?.steam
@@ -5,6 +5,7 @@ import java.io.File
object GameIdentifier {
private const val MAX_PARENT_DEPTH = 6
internal const val SPACEWAR = 480
enum class Source { STEAM_APPID_TXT, STEAM_MANIFEST_ACF, STEAM_EMU_INI, GOG_INFO, PE_VERSION, FILENAME, NONE }
enum class Confidence { HIGH, MEDIUM, LOW }
@@ -92,7 +93,7 @@ object GameIdentifier {
for (candidate in arrayOf(File(dir, "steam_appid.txt"), File(dir, "steam_settings/steam_appid.txt"))) {
val id = readSmallTextFile(candidate)?.removePrefix("\uFEFF")?.trim()
?.takeWhile { it.isDigit() }?.toIntOrNull()
if (id != null && id > 0) return id
if (id != null && id > 0 && id != SPACEWAR) return id
}
return null
}
@@ -111,7 +112,7 @@ object GameIdentifier {
for (f in candidates) {
val text = readSmallTextFile(f) ?: continue
val id = re.find(text)?.groupValues?.getOrNull(1)?.toIntOrNull()
if (id != null && id > 0) return id
if (id != null && id > 0 && id != SPACEWAR) return id
}
return null
}
@@ -133,7 +134,8 @@ object GameIdentifier {
val match = manifests.firstOrNull { m ->
val text = readSmallTextFile(m) ?: return@firstOrNull false
val installdir = vdfValue(text, "installdir")
gameFolder != null && installdir != null && installdir.equals(gameFolder, ignoreCase = true)
gameFolder != null && installdir != null && installdir.equals(gameFolder, ignoreCase = true) &&
vdfValue(text, "appid")?.toIntOrNull() != SPACEWAR
} ?: return null
val text = readSmallTextFile(match) ?: return null
@@ -45,15 +45,15 @@ object SteamMatch {
identity?.appId?.let { id ->
return Match(id, Certainty.FILES, identity.source.name.lowercase(), now).also { put(context, key, it) }
}
val known = get(context, key)
val known = get(context, key)?.takeUnless { it.appId == GameIdentifier.SPACEWAR }
if (known != null && known.certainty == Certainty.NAME) return known
if (known != null && known.certainty == Certainty.NONE && now - known.checkedAt < RETRY_AFTER_MS) return known
legacy?.takeIf { it.isFile }?.let { runCatching { it.readText().trim().toInt() }.getOrNull() }?.takeIf { it > 0 }?.let { id ->
legacy?.takeIf { it.isFile }?.let { runCatching { it.readText().trim().toInt() }.getOrNull() }?.takeIf { it > 0 && it != GameIdentifier.SPACEWAR }?.let { id ->
return Match(id, Certainty.NAME, "store search", now).also { put(context, key, it) }
}
if (search == null) return known?.takeIf { it.certainty != Certainty.FILES } ?: Match(null, Certainty.NONE, "", 0)
val id = runCatching { search(name) }.getOrNull()
val match = if (id != null && id > 0) Match(id, Certainty.NAME, "store search", now) else Match(null, Certainty.NONE, "", now)
val match = if (id != null && id > 0 && id != GameIdentifier.SPACEWAR) Match(id, Certainty.NAME, "store search", now) else Match(null, Certainty.NONE, "", now)
put(context, key, match)
return match
}