diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt index 2a4ef7cb21..9968b1c1fd 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt @@ -337,7 +337,10 @@ object AddedGames { val owner = ownerFolder(app, exe) if (owner != null && owner.path !in SessionPrefs.removedAddedGames(app)) { single(app, owner.path)?.takeIf { canonical(it.exe) == path }?.let { - if (guestPath(app, exe) != null) AddedExes.put(app, AddedExes.Entry(owner.path, exe.path)) + if (guestPath(app, it.exe) != null) { + SessionPrefs.setAddedGameExe(app, owner.path, it.exe.path) + AddedExes.put(app, AddedExes.Entry(owner.path, it.exe.path)) + } return AddResult.Existing(it) } } @@ -443,9 +446,9 @@ object AddedGames { val chosen = picked.takeIf { it.isNotEmpty() }?.let { File(it) }?.takeIf { it.isFile } ?: single?.takeIf { it.picked }?.let { File(it.exe) }?.takeIf { it.isFile } val found = chosen ?: sidecar?.exeFile(folder)?.takeIf { it.isFile } ?: candidates.firstOrNull() ?: return - val epicLauncher = sidecar?.takeIf { it.store == Store.EPIC && (chosen == null || canonical(chosen) == canonical(it.exeFile(folder))) } + val storeLauncher = sidecar?.takeIf { chosen == null || canonical(chosen) == canonical(it.exeFile(folder)) } ?.launcherFile(folder)?.takeIf { it.isFile } - val launch = epicLauncher ?: if (chosen == null) sidecar?.launcherFile(folder)?.takeIf { it.isFile } ?: found else found + val launch = storeLauncher ?: found val foundGuest = guestPath(context, launch) if (foundGuest == null) { Log.w(TAG, "${folder.name}: the session cannot see ${launch.path}"); return } val autoName = sidecar?.title ?: identifiedName(folder, found) ?: folder.name diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedExesTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedExesTest.kt index 902a70b1db..5409eee150 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedExesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedExesTest.kt @@ -92,6 +92,38 @@ class AddedExesTest { } } + @Test fun reselectingTheCurrentExeKeepsItWhenTheRankingChanges() { + val storage = tmp.newFolder("Ranked") + exe(File(storage, "Example/Example.exe")) + exe(File(storage, "Example/Other.exe")) + SessionPrefs.setAddedGamesDirs(app, emptyList()) + SessionPrefs.setGameStorage(app, storage.path, "Card") + val folder = File(storage, "Example") + val current = AddedGames.scan(app).single { it.folder == folder }.exe + val other = listOf("Example.exe", "Other.exe").map { File(folder, it) }.single { it.path != current.path } + val existing = AddedGames.addExe(app, current) + assertTrue(existing is AddedGames.AddResult.Existing) + assertEquals(current.path, SessionPrefs.addedGameExe(app, folder.path)) + File(folder, "MicrosoftGame.config").writeText("") + assertEquals(other.path, AddedGames.rank(folder).exes.first().path) + assertEquals(current.path, AddedGames.scan(app).single { it.folder == folder }.exe.path) + } + + @Test fun reselectingASteamInstallsExeThroughAnAliasStoresTheReachablePath() { + val storage = tmp.newFolder("Aliased") + val pick = exe(File(storage, "steamapps/common/Example/Example.exe")) + File(storage, "steamapps/appmanifest_123.acf").writeText("\"installdir\" \"Example\"") + SessionPrefs.setAddedGamesDirs(app, emptyList()) + SessionPrefs.setGameStorage(app, storage.path, "Card") + val alias = File(tmp.newFolder("Links"), "Example.exe") + java.nio.file.Files.createSymbolicLink(alias.toPath(), pick.toPath()) + assertTrue(AddedGames.addExe(app, alias) is AddedGames.AddResult.Existing) + assertEquals(pick.path, AddedExes.list(app).single { it.folder == pick.parentFile!!.path }.exe) + assertEquals(pick.path, SessionPrefs.addedGameExe(app, pick.parentFile!!.path)) + assertEquals(pick.path, AddedGames.scan(app).single { it.folder == pick.parentFile }.exe.path) + AddedExes.drop(app, pick.parentFile!!.path) + } + @Test fun anotherExeInTheSameGameSwitchesItsExe() { noGamesFolders() val first = onStorage("Games2/Hades/Hades.exe") diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesStoreScanTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesStoreScanTest.kt index 1c61034221..bdacbc4d6a 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesStoreScanTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesStoreScanTest.kt @@ -66,6 +66,27 @@ class AddedGamesStoreScanTest { assertTrue(game.guestExe.endsWith("/Tools/Editor.exe")) } + @Test fun everyStoreKeepsItsLauncherWhenItsOwnExeIsReselected() { + for (store in listOf(Store.GOG, Store.AMAZON, Store.EPIC)) { + val folder = install(store, "own-${store.id}", "Own ${store.label}", "Binaries/Game.exe", launcher = true) + val own = File(folder, "Binaries/Game.exe") + val before = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath } + assertTrue(AddedGames.addExe(app, own) is AddedGames.AddResult.Existing) + val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath } + assertEquals(own.path, game.exe.path) + assertTrue(game.guestExe.endsWith("/" + StoreLaunch.LAUNCHER)) + assertEquals(before.appId, game.appId) + } + } + + @Test fun aDifferentPickedExeOnAnyStoreGameIsRunDirectly() { + val folder = install(Store.GOG, "tool", "Tool GOG", "Binaries/Game.exe", launcher = true) + val tool = File(folder, "Tools/Editor.exe").apply { parentFile!!.mkdirs(); writeText("tool") } + AddedExes.put(app, AddedExes.Entry(folder.path, tool.path, picked = true)) + val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath } + assertTrue(game.guestExe.endsWith("/Tools/Editor.exe")) + } + @Test fun anOlderSidecarsSteamSwitchIsIgnoredEveryInstallIsListed() { val folder = install(Store.AMAZON, "amzn1.adg.product.x", "Yakuza 0", "Yakuza0.exe") val file = StoreGameSidecar.file(folder)