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 9968b1c1fd..7009e0e68f 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt @@ -239,6 +239,7 @@ object AddedGames { for (entry in AddedExes.list(context)) { val folder = File(entry.folder) if (folder.path in removed || !folder.isDirectory) continue + if (StoreGameSidecar.read(folder)?.isInstalled == false) continue scanGame(context, folder, out, single = entry, reuse = true) } for (folder in libraryDepotInstalls(context)) if (folder.path !in removed) scanGame(context, folder, out, reuse = true) @@ -337,9 +338,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, it.exe) != null) { - SessionPrefs.setAddedGameExe(app, owner.path, it.exe.path) - AddedExes.put(app, AddedExes.Entry(owner.path, it.exe.path)) + val keep = listOf(it.exe, exe).firstOrNull { f -> guestPath(app, f) != null } + if (keep != null) { + SessionPrefs.setAddedGameExe(app, owner.path, keep.path) + AddedExes.put(app, AddedExes.Entry(owner.path, keep.path)) } return AddResult.Existing(it) } 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 bdacbc4d6a..8cbe467864 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesStoreScanTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesStoreScanTest.kt @@ -137,4 +137,30 @@ class AddedGamesStoreScanTest { val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath } assertEquals("/root/Games/Stores/GOG/Witcher Game", game.guestDir) } + + @Test fun aStoreGameThatIsUpdatingIsNotListedThroughItsSavedExe() { + val folder = install(Store.GOG, "upd", "Updating GOG", "Binaries/Game.exe", launcher = true) + val own = File(folder, "Binaries/Game.exe") + assertTrue(AddedGames.addExe(app, own) is AddedGames.AddResult.Existing) + assertTrue(AddedGames.scan(app).any { it.folder.absolutePath == folder.absolutePath }) + StoreGameSidecar.read(folder)!!.copy(state = StoreGameSidecar.STATE_UPDATING).write(folder) + assertTrue(AddedGames.scan(app).none { it.folder.absolutePath == folder.absolutePath }) + } + + @Test fun reselectingTheMappedExeReplacesAnUnmappedAliasOfIt() { + val folder = install(Store.EPIC, "alias", "Alias Epic", "Binaries/Game.exe", launcher = true) + val own = File(folder, "Binaries/Game.exe") + val alias = File(java.nio.file.Files.createTempDirectory("alias").toFile(), "bin") + try { + java.nio.file.Files.createSymbolicLink(alias.toPath(), File(folder, "Binaries").toPath()) + } catch (e: Exception) { + org.junit.Assume.assumeNoException(e) + } + val aliased = File(alias, "Game.exe") + assertNull(AddedGames.guestPath(app, aliased)) + SessionPrefs.setAddedGameExe(app, folder.path, aliased.path) + assertTrue(AddedGames.addExe(app, own) is AddedGames.AddResult.Existing) + assertEquals(own.path, SessionPrefs.addedGameExe(app, folder.path)) + assertEquals(own.path, AddedExes.list(app).single { it.folder == folder.path }.exe) + } }