mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix: stop importing games as Spacewar (480) and follow a changed Steam app id (#1896)
This commit is contained in:
1 parent
88719f25d2
commit
583f34fc55
9 files changed
+303
-26
No files matched your search
@@ -154,6 +154,98 @@ class AddedGameArtFillTest {
|
||||
assertFalse(File(AddedGameArt.cacheDir(app, second), AddedGameArt.EXTRAS_TRIED).exists())
|
||||
}
|
||||
|
||||
private fun steamFrom(asked: MutableList<String>, bytes: Byte, search: Int? = null, slotsAsked: MutableList<Set<Slot>> = ArrayList()) = AddedGameArt.Sources(
|
||||
storeLogo = { false },
|
||||
steamSearch = { if (search == null) fail("searched although the game names its appid"); search },
|
||||
steam = { id, cache, slots ->
|
||||
asked += id
|
||||
slotsAsked += slots
|
||||
slots.forEach { File(cache, steamNames.getValue(it)).writeBytes(byteArrayOf(bytes)) }
|
||||
slots.isNotEmpty()
|
||||
},
|
||||
sgdbGame = { _, _, _ -> null },
|
||||
sgdb = { _, _, _, _ -> false },
|
||||
)
|
||||
|
||||
@Test fun artOfTheAppTheFilesNamedBeforeIsFetchedAgain() {
|
||||
val g = game("Peak", 0x8100000AL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("1029210")
|
||||
val asked = ArrayList<String>()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 1)))
|
||||
File(g.folder, "steam_appid.txt").writeText("3527290")
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2)))
|
||||
assertEquals(listOf("1029210", "3527290"), asked)
|
||||
assertArrayEquals(byteArrayOf(2), File(AddedGameArt.cacheDir(app, g), "p.jpg").readBytes())
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 3)))
|
||||
assertEquals(2, asked.size)
|
||||
}
|
||||
|
||||
@Test fun aPictureTheUserChoseOutlivesTheChange() {
|
||||
val g = game("Peak", 0x8100000BL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("1029210")
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(ArrayList(), 1))
|
||||
val picked = File(tmp.root, "mine.jpg").apply { writeBytes(byteArrayOf(7)) }
|
||||
assertTrue(AddedGameArt.store(AddedGameArt.cacheDir(app, g), Slot.COVER, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
File(g.folder, "steam_appid.txt").writeText("3527290")
|
||||
val asked = ArrayList<String>()
|
||||
val slots = ArrayList<Set<Slot>>()
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2, slotsAsked = slots))
|
||||
assertArrayEquals(byteArrayOf(7), AddedGameArt.resolve(app, g).portrait!!.readBytes())
|
||||
assertEquals(listOf("3527290"), asked)
|
||||
assertEquals(listOf(setOf(Slot.WIDE, Slot.BACKGROUND, Slot.LOGO)), slots)
|
||||
val cache = AddedGameArt.cacheDir(app, g)
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "header.jpg").readBytes())
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "hero.jpg").readBytes())
|
||||
assertFalse(File(cache, AddedGameArt.REFETCH).exists())
|
||||
}
|
||||
|
||||
private fun olderBuildsArt(g: AddedGames.Game, marker: String): File = AddedGameArt.cacheDir(app, g).apply {
|
||||
mkdirs()
|
||||
File(this, "steam-appid").writeText(marker)
|
||||
steamNames.values.forEach { File(this, it).writeBytes(byteArrayOf(1)) }
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildsSpacewarMarkerGoesWithItsArt() {
|
||||
val g = game("Peak", 0x8100000DL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("480")
|
||||
val cache = olderBuildsArt(g, "480")
|
||||
val asked = ArrayList<String>()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2, search = 3527290)))
|
||||
assertEquals(listOf("3527290"), asked)
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "p.jpg").readBytes())
|
||||
assertFalse(File(cache, "steam-appid").exists())
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildsMatchStaysWhileTheFilesNameNoApp() {
|
||||
val g = game("Hades", 0x8100000EL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").delete()
|
||||
val cache = olderBuildsArt(g, "1145360")
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(ArrayList(), 2)))
|
||||
assertEquals("1145360", File(cache, "steam-appid").readText())
|
||||
assertArrayEquals(byteArrayOf(1), File(cache, "p.jpg").readBytes())
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildsMatchGivesWayToTheAppTheFilesName() {
|
||||
val g = game("Peak", 0x8100000FL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("3527290")
|
||||
val cache = olderBuildsArt(g, "1029210")
|
||||
val asked = ArrayList<String>()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2)))
|
||||
assertEquals(listOf("3527290"), asked)
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "p.jpg").readBytes())
|
||||
assertFalse(File(cache, "steam-appid").exists())
|
||||
}
|
||||
|
||||
@Test fun filesThatStopNamingAnAppFallBackToTheGamesName() {
|
||||
val g = game("Peak", 0x8100000CL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("1029210")
|
||||
val asked = ArrayList<String>()
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 1))
|
||||
File(g.folder, "steam_appid.txt").writeText("480")
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2, search = 3527290)))
|
||||
assertEquals(listOf("1029210", "3527290"), asked)
|
||||
}
|
||||
|
||||
@Test fun nothingIsFetchedWhenArtIsOff() {
|
||||
SessionPrefs.setAddedGamesArt(app, false)
|
||||
val calls = Calls()
|
||||
|
||||
@@ -66,6 +66,29 @@ class AddedGameArtLookupTest {
|
||||
assertEquals(SteamMatch.Certainty.NAME, match.certainty)
|
||||
}
|
||||
|
||||
@Test fun anEarlierBuildsSpacewarLookupIsNotAMatch() {
|
||||
val dir = tmp.newFolder("Peak")
|
||||
val exe = File(dir, "PEAK.exe").apply { writeText("x") }
|
||||
val legacy = File(tmp.newFolder(), "steam-appid").apply { writeText("480") }
|
||||
assertEquals(3527290, SteamMatch.resolve(app, dir.path, exe, "PEAK", legacy = legacy) { 3527290 }.appId)
|
||||
}
|
||||
|
||||
@Test fun aSavedSpacewarMatchIsNotAMatch() {
|
||||
val dir = tmp.newFolder("Peak")
|
||||
val exe = File(dir, "PEAK.exe").apply { writeText("x") }
|
||||
SteamMatch.put(app, dir.path, SteamMatch.Match(480, SteamMatch.Certainty.NAME, "store search", System.currentTimeMillis()))
|
||||
assertNull(SteamMatch.resolve(app, dir.path, exe, "PEAK").appId)
|
||||
assertEquals(3527290, SteamMatch.resolve(app, dir.path, exe, "PEAK") { 3527290 }.appId)
|
||||
}
|
||||
|
||||
@Test fun aStoreSearchAnsweringSpacewarIsNoMatch() {
|
||||
val dir = tmp.newFolder("Spacewar Fan Remake")
|
||||
val exe = File(dir, "game.exe").apply { writeText("x") }
|
||||
val match = SteamMatch.resolve(app, dir.path, exe, "Spacewar Fan Remake") { 480 }
|
||||
assertNull(match.appId)
|
||||
assertEquals(SteamMatch.Certainty.NONE, match.certainty)
|
||||
}
|
||||
|
||||
@Test fun aStoreResultIsTakenOnlyWhenItsNameMatches() {
|
||||
assertNull(AddedGameArt.pickStoreResult("My Obscure Game", listOf("10" to "Totally Different", "11" to "Another One")))
|
||||
assertEquals("20", AddedGameArt.pickStoreResult("Hades", listOf("19" to "Hades II Soundtrack Bundle Extra", "20" to "Hades")))
|
||||
|
||||
@@ -31,8 +31,25 @@ class GameIdentifierTest {
|
||||
fun steamAppIdTxt_inSteamSettingsSubdir_isFound() {
|
||||
val dir = tmp.newFolder("Game")
|
||||
File(dir, "steam_settings").mkdirs()
|
||||
File(dir, "steam_settings/steam_appid.txt").writeText("480")
|
||||
assertEquals(480, GameIdentifier.identify(exeIn(dir)).appId)
|
||||
File(dir, "steam_settings/steam_appid.txt").writeText("3527290")
|
||||
assertEquals(3527290, GameIdentifier.identify(exeIn(dir)).appId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarAppId_namesNoGame() {
|
||||
val dir = tmp.newFolder("PEAK")
|
||||
File(dir, "steam_appid.txt").writeText("480")
|
||||
File(dir, "steam_emu.ini").writeText("[Settings]\nAppId=480\n")
|
||||
assertNull(GameIdentifier.identify(exeIn(dir)).appId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarAppId_fallsThroughToTheGamesOwnId() {
|
||||
val dir = tmp.newFolder("PEAK")
|
||||
File(dir, "steam_appid.txt").writeText("480")
|
||||
File(dir, "steam_settings").mkdirs()
|
||||
File(dir, "steam_settings/steam_appid.txt").writeText("3527290")
|
||||
assertEquals(3527290, GameIdentifier.identify(exeIn(dir)).appId)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,6 +61,30 @@ class GameIdentifierTest {
|
||||
assertEquals(GameIdentifier.Source.STEAM_EMU_INI, id.source)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarManifest_namesNoGame() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
File(steamapps, "appmanifest_480.acf").writeText(""""AppState" { "appid" "480" "name" "Spacewar" "installdir" "PEAK" }""")
|
||||
val game = File(steamapps, "common/PEAK").apply { mkdirs() }
|
||||
File(game, "steam_appid.txt").writeText("3527290")
|
||||
val id = GameIdentifier.identify(exeIn(game, "PEAK.exe"))
|
||||
assertEquals(3527290, id.appId)
|
||||
assertEquals(GameIdentifier.Source.STEAM_APPID_TXT, id.source)
|
||||
assertTrue(id.name != "Spacewar")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarManifest_leavesTheGamesOwnManifestForTheSameFolder() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
File(steamapps, "appmanifest_480.acf").writeText(""""AppState" { "appid" "480" "name" "Spacewar" "installdir" "PEAK" }""")
|
||||
File(steamapps, "appmanifest_3527290.acf").writeText(""""AppState" { "appid" "3527290" "name" "PEAK" "installdir" "PEAK" }""")
|
||||
val game = File(steamapps, "common/PEAK").apply { mkdirs() }
|
||||
val id = GameIdentifier.identify(exeIn(game, "PEAK.exe"))
|
||||
assertEquals(3527290, id.appId)
|
||||
assertEquals("PEAK", id.name)
|
||||
assertEquals(GameIdentifier.Source.STEAM_MANIFEST_ACF, id.source)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun steamManifestAcf_matchedByInstalldir_givesAppIdAndName() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
|
||||
Reference in new issue
Block a user