mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
feat(frontend): launch from every frontend file format and store, with per-store game files (#2872)
This commit is contained in:
1 parent
45c31a480a
commit
dc9d1b81cc
10 files changed
+399
-53
No files matched your search
@@ -33,27 +33,64 @@ class GameFilesTest {
|
||||
assertEquals("18446744073709551615", file.readText())
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
listOf(Uri.fromFile(file), Uri.parse(file.path)).forEach { uri ->
|
||||
assertEquals("18446744073709551615", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, uri)))
|
||||
assertEquals("18446744073709551615", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, uri))?.id)
|
||||
}
|
||||
val provider = LaunchFileProvider(file)
|
||||
provider.attachInfo(context, android.content.pm.ProviderInfo().apply { authority = "frontend" })
|
||||
ShadowContentResolver.registerProviderInternal("frontend", provider)
|
||||
val uri = Uri.parse("content://frontend/document/opaque%3A42")
|
||||
assertEquals("18446744073709551615", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, uri)))
|
||||
assertEquals("18446744073709551615", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, uri))?.id)
|
||||
}
|
||||
|
||||
@Test fun readsIdsFromEveryFrontendFileFormat() {
|
||||
listOf("8400\n", "steam://rungameid/8400", "droiddeck://game/8400",
|
||||
"# Daijishou Player Template\n[steamappid] 8400\n", "# DST\n[steamappid] 8400\n",
|
||||
"[InternetShortcut]\r\nIconIndex=0\r\nURL=steam://rungameid/8400\r\nIconFile=C:\\steam.ico\r\n").forEach { value ->
|
||||
assertEquals(value, "8400", GameFiles.read(ByteArrayInputStream(value.toByteArray())))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun rejectsCommandsMalformedIdsLargeFilesAndUnsupportedIntents() {
|
||||
listOf("", "0", "01", "-1", "18446744073709551616", "steam://rungameid/8400",
|
||||
"8400\n8401", "droiddeck://game/8400", "droiddeck://game/8400?command=quit", "x".repeat(129)).forEach { value ->
|
||||
listOf("", "0", "01", "-1", "18446744073709551616", "steam://rungameid/8400?x=1", "steam://run/8400",
|
||||
"8400\n8401", "droiddeck://game/8400?command=quit", "x".repeat(4097),
|
||||
"[InternetShortcut]\nURL=https://example.com/8400", "[InternetShortcut]\nURL=8400",
|
||||
"# Daijishou Player Template\n[epicappid] 8400").forEach { value ->
|
||||
assertNull(value, GameFiles.read(ByteArrayInputStream(value.toByteArray())))
|
||||
}
|
||||
assertEquals("8400", GameFiles.read(ByteArrayInputStream("8400\n".toByteArray())))
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
assertNull(GameFiles.readIntent(context, Intent(Intent.ACTION_SEND, Uri.parse("droiddeck://game/8400"))))
|
||||
assertNull(GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com/8400.steam"))))
|
||||
assertNull(GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.parse("file://remote/game.steam"))))
|
||||
assertNull(GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.fromFile(File(tmp.root, "missing.steam")))))
|
||||
assertEquals("8400", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.parse("droiddeck://game/8400"))))
|
||||
assertEquals("8400", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.parse("droiddeck://game/8400")))?.id)
|
||||
assertEquals("8400", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.parse("8400")))?.id)
|
||||
assertEquals("8400", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.parse("steam://rungameid/8400")))?.id)
|
||||
}
|
||||
|
||||
@Test fun storeFilesCarryTheirSourceAndTitle() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val epic = File(tmp.root, "Hades II.epic").apply { writeText("17") }
|
||||
val request = GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.fromFile(epic)))!!
|
||||
assertEquals("epic", request.source)
|
||||
assertEquals("Hades II", request.title)
|
||||
val daijishou = File(tmp.root, "Portal.steamappid").apply { writeText("# Daijishou Player Template\n[steamappid] 400\n") }
|
||||
val steam = GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.fromFile(daijishou)))!!
|
||||
assertEquals(Library.SOURCE_STEAM, steam.source)
|
||||
assertEquals("400", steam.id)
|
||||
}
|
||||
|
||||
@Test fun programFilesArriveAsPathsNotContents() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val exe = File(tmp.newFolder("Game"), "Game.exe").apply { writeBytes(byteArrayOf(0x4d, 0x5a)) }
|
||||
val request = GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.fromFile(exe)))!!
|
||||
assertEquals(exe.canonicalFile, request.program)
|
||||
assertNull(request.id)
|
||||
val provider = LaunchFileProvider(exe)
|
||||
provider.attachInfo(context, android.content.pm.ProviderInfo().apply { authority = "frontend.files" })
|
||||
ShadowContentResolver.registerProviderInternal("frontend.files", provider)
|
||||
val shared = Uri.parse("content://frontend.files/root" + exe.canonicalPath)
|
||||
assertEquals(exe.canonicalFile, GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, shared))?.program)
|
||||
assertNull(GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, Uri.fromFile(File(exe.parentFile, "Missing.exe")))))
|
||||
}
|
||||
|
||||
@Test fun exportsGameIconBeforeCapsuleAndPreservesCustomArtwork() {
|
||||
@@ -185,13 +222,32 @@ class GameFilesTest {
|
||||
val file = GameFiles.export(app, folder, game("620", "Portal 2"))
|
||||
assertEquals("Portal 2.steam", file.name)
|
||||
assertEquals("620", file.readText())
|
||||
assertEquals("620", GameFiles.readIntent(RuntimeEnvironment.getApplication(), Intent(Intent.ACTION_VIEW, Uri.fromFile(file))))
|
||||
assertEquals("620", GameFiles.readIntent(RuntimeEnvironment.getApplication(), Intent(Intent.ACTION_VIEW, Uri.fromFile(file)))?.id)
|
||||
val added = Library.SteamGame(1, "Added Game", null, Library.ADDED, -1L)
|
||||
val addedFile = GameFiles.export(app, folder, added)
|
||||
assertEquals("Added Game.steam", addedFile.name)
|
||||
assertEquals("18446744073709551615", addedFile.readText())
|
||||
}
|
||||
|
||||
@Test fun storeGamesExportUnderTheirStoreExtensionAndLaunchBack() {
|
||||
val folder = tmp.newFolder()
|
||||
val forza = Library.SteamGame(1, "Forza Horizon 5", null, Library.ADDED, -7L, source = "xbox", storeId = "9NKX70BBCDRN")
|
||||
val steam = File(folder, "Forza Horizon 5.steam").apply { writeText(forza.gameIdString) }
|
||||
File(folder, ".droiddeck-sync.json").writeText(
|
||||
"""{"format":"droiddeck-game-files-v1","games":{"Forza Horizon 5.steam":"${forza.gameIdString}"}}""")
|
||||
GameFiles.sync(app, folder, listOf(forza))
|
||||
val file = File(folder, "Forza Horizon 5.xbox")
|
||||
assertEquals(forza.gameIdString, file.readText())
|
||||
assertFalse(steam.exists())
|
||||
val request = GameFiles.readIntent(RuntimeEnvironment.getApplication(), Intent(Intent.ACTION_VIEW, Uri.fromFile(file)))!!
|
||||
assertEquals("xbox", request.source)
|
||||
assertSame(forza, request.find(listOf(game("620", "Portal 2"), forza)))
|
||||
listOf("ubisoft", "ea", "rockstar", "battlenet", "itch", "gamejolt", "epic", "gog", "amazon").forEach { store ->
|
||||
val game = Library.SteamGame(1, "Game", null, Library.ADDED, -8L, source = store)
|
||||
assertEquals("Game.$store", GameFiles.filename(game))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun steamSyncDisambiguatesTitlesAndPreservesEditedAndForeignFiles() {
|
||||
val folder = tmp.newFolder()
|
||||
val first = game("620", "A/B")
|
||||
|
||||
@@ -14,29 +14,41 @@ class GameLaunchIntentTest {
|
||||
@Test fun acceptsNativeAndExplicitlyRetargetedGameNativeProfiles() {
|
||||
listOf(GameLaunchIntent.ACTION, "app.gamenative.LAUNCH_GAME").forEach { action ->
|
||||
val request = Intent(action).putExtra("app_id", 620).putExtra("game_source", "STEAM")
|
||||
assertEquals("620", GameLaunchIntent.read(RuntimeEnvironment.getApplication(), request))
|
||||
assertEquals("8400", GameLaunchIntent.readId(Intent(action).putExtra("app_id", "8400")))
|
||||
assertEquals("620", GameLaunchIntent.readId(request.putExtra("game_source", "steam")))
|
||||
assertEquals("620", GameLaunchIntent.read(RuntimeEnvironment.getApplication(), request)?.id)
|
||||
assertEquals("8400", GameLaunchIntent.readExtras(Intent(action).putExtra("app_id", "8400"))?.id)
|
||||
assertEquals("620", GameLaunchIntent.readExtras(request.putExtra("game_source", "steam"))?.id)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun stringIdsPreserveUnsignedShortcutIds() {
|
||||
@Test fun longAndStringIdsPreserveUnsignedShortcutIds() {
|
||||
listOf("2147483648", "18446744073709551615").forEach { id ->
|
||||
assertEquals(id, GameLaunchIntent.readId(Intent(GameLaunchIntent.ACTION).putExtra("app_id", id)))
|
||||
assertEquals(id, GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", id))?.id)
|
||||
}
|
||||
assertEquals("620", GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 620L))?.id)
|
||||
assertEquals("18446744073709551615", GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", -1L))?.id)
|
||||
}
|
||||
|
||||
@Test fun storeSourcesComeThroughForLibraryMatching() {
|
||||
mapOf("EPIC" to "epic", "gog" to "gog", "AMAZON" to "amazon", "XBOX" to "xbox", "UBISOFT" to "ubisoft",
|
||||
"EA" to "ea", "ROCKSTAR" to "rockstar", "BATTLENET" to "battlenet", "ITCH" to "itch", "GAMEJOLT" to "gamejolt",
|
||||
"CUSTOM_GAME" to Library.ADDED).forEach { (name, source) ->
|
||||
val request = GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 1207658924).putExtra("game_source", name))
|
||||
assertEquals(name, source, request?.source)
|
||||
assertEquals("1207658924", request?.id)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun rejectsUnsupportedSourcesTypesAndIdsWithoutFallingBackToData() {
|
||||
listOf("", "0", "01", "+1", "-1", "18446744073709551616", "620\n", "steam://rungameid/620").forEach { id ->
|
||||
assertNull(id, GameLaunchIntent.readId(Intent(GameLaunchIntent.ACTION).putExtra("app_id", id)))
|
||||
assertNull(id, GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", id)))
|
||||
}
|
||||
listOf("EPIC", "GOG", "CUSTOM_GAME", "", "STEAM ").forEach { source ->
|
||||
assertNull(GameLaunchIntent.readId(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 620).putExtra("game_source", source)))
|
||||
listOf("STADIA", "", "STEAM ", "added").forEach { source ->
|
||||
assertNull(GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 620).putExtra("game_source", source)))
|
||||
}
|
||||
assertNull(GameLaunchIntent.readId(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 620L)))
|
||||
assertNull(GameLaunchIntent.readId(Intent(GameLaunchIntent.ACTION).putExtra("app_id", -1)))
|
||||
assertNull(GameLaunchIntent.readId(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 620).putExtra("game_source", 1)))
|
||||
assertNull(GameLaunchIntent.readId(Intent(Intent.ACTION_MAIN).putExtra("app_id", 620)))
|
||||
assertNull(GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 0L)))
|
||||
assertNull(GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", -1)))
|
||||
assertNull(GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", 620).putExtra("game_source", 1)))
|
||||
assertNull(GameLaunchIntent.readExtras(Intent(Intent.ACTION_MAIN).putExtra("app_id", 620)))
|
||||
assertNull(GameLaunchIntent.read(RuntimeEnvironment.getApplication(), Intent(GameLaunchIntent.ACTION,
|
||||
android.net.Uri.parse("droiddeck://game/620"))))
|
||||
}
|
||||
@@ -44,7 +56,7 @@ class GameLaunchIntentTest {
|
||||
@Test fun deepLinksStillAcceptUnsignedShortcutIds() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
assertEquals("18446744073709551615", GameLaunchIntent.read(context,
|
||||
Intent(Intent.ACTION_VIEW, android.net.Uri.parse("droiddeck://game/18446744073709551615"))))
|
||||
Intent(Intent.ACTION_VIEW, android.net.Uri.parse("droiddeck://game/18446744073709551615")))?.id)
|
||||
assertFalse(GameLaunchIntent.accepts(Intent.ACTION_SEND))
|
||||
assertTrue(GameLaunchIntent.accepts(GameLaunchIntent.ACTION))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class GameRequestTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun game(id: Long, name: String, source: String = Library.SOURCE_STEAM, storeId: String? = null, files: File? = null,
|
||||
library: String = "internal", appId: Int = id.toInt()) =
|
||||
Library.SteamGame(appId, name, null, library, id, gameFiles = files, source = source, storeId = storeId)
|
||||
|
||||
@Test fun steamIdsMatchTheGameIdOrAnAddedGamesSteamAppId() {
|
||||
val portal = game(400, "Portal")
|
||||
val added = game(-1L, "Celeste", library = Library.ADDED, source = Library.ADDED, appId = 504230)
|
||||
val games = listOf(portal, added)
|
||||
assertSame(portal, GameRequest("400").find(games))
|
||||
assertSame(added, GameRequest("18446744073709551615").find(games))
|
||||
assertSame(added, GameRequest("504230").find(games))
|
||||
assertNull(GameRequest("401").find(games))
|
||||
}
|
||||
|
||||
@Test fun titleMatchingWaitsForTheFullScan() {
|
||||
val cached = game(-2L, "Example", source = "gog", storeId = "111")
|
||||
assertNull(GameRequest("222", "gog", "Example").find(listOf(cached), byTitle = false))
|
||||
assertSame(cached, GameRequest("222", "gog", "Example").find(listOf(cached)))
|
||||
assertSame(cached, GameRequest("111", "gog", "Other").find(listOf(cached), byTitle = false))
|
||||
}
|
||||
|
||||
@Test fun gogMatchesItsProductIdThenTitle() {
|
||||
val witcher = game(-2L, "The Witcher 3: Wild Hunt", source = "gog", storeId = "1207664663")
|
||||
val games = listOf(game(292030, "The Witcher 3: Wild Hunt"), witcher)
|
||||
assertSame(witcher, GameRequest("1207664663", "gog").find(games))
|
||||
assertSame(witcher, GameRequest("5", "gog", "The Witcher 3 Wild Hunt").find(games))
|
||||
}
|
||||
|
||||
@Test fun storesWithAppLocalIdsMatchByTitleWithinTheirStore() {
|
||||
val hades = game(-3L, "Hades II", source = "epic", storeId = "Ixion")
|
||||
val custom = game(-4L, "Cave Story+", library = Library.ADDED, source = Library.ADDED)
|
||||
val games = listOf(game(1145350, "Hades II"), hades, custom)
|
||||
assertSame(hades, GameRequest("17", "epic", "hades ii").find(games))
|
||||
assertSame(custom, GameRequest("9", Library.ADDED, "Cave Story").find(games))
|
||||
assertNull(GameRequest("17", "epic").find(games))
|
||||
assertNull(GameRequest("17", "amazon", "Hades II").find(games))
|
||||
}
|
||||
|
||||
@Test fun programsStartTheDeepestGameThatOwnsThem() {
|
||||
val root = tmp.newFolder("Games")
|
||||
val suite = File(root, "Suite").apply { mkdirs() }
|
||||
val inner = File(suite, "Episode 2").apply { mkdirs() }
|
||||
val outer = game(-5L, "Suite", files = suite)
|
||||
val episode = game(-6L, "Episode 2", files = inner)
|
||||
val games = listOf(outer, episode)
|
||||
assertSame(episode, GameRequest(program = File(inner, "bin/game.exe")).find(games))
|
||||
assertSame(outer, GameRequest(program = File(suite, "launcher.exe")).find(games))
|
||||
assertNull(GameRequest(program = File(root, "Other/other.exe")).find(games))
|
||||
assertNull(GameRequest(program = File(root, "Suite2/game.exe")).find(games))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user