Games: revamped add games feature (#492)

Adding and managing your own (non-Steam) games moves out of the Steam
settings into the Games tab, and works like Steam's own non-Steam
Properties.

- A + beside "Games N" opens a compact in-app picker: the storage first,
  then that storage's root, every folder, .exe files only. Picking an exe
  adds the game with its name, art, Custom badge and Steam shortcut.
- "Add all games in this folder" adds every game folder inside at once.
  A summary opens immediately and fills in as each game is found, with a
  "?" where the exe was a close call and a red X to remove a game.
- An edit button on each Custom game opens its editor: Name, Target
  (ranked exes, Other exe…), Start in, Launch options, the four pieces of
  art with thumbnails, and Remove. Edits go through the same Steam
  shortcut, so the appid never changes and nothing duplicates.
- Art chooser per piece: images in the game folder, Steam's official art,
  SteamGridDB alternatives, your own image, or back to automatic.
- Finding the exe: up to five folders deep, every exe scored (name match,
  Unreal -Shipping builds, bin folders and size up; launchers, crash
  reporters, installers, redistributables and depth down).
- Real titles from the game's files (Steam manifest, GOG info, the exe's
  version info), keeping the folder's spacing when both spell the same
  title, underscores read as spaces.
- Art: the exact Steam appid when the game names one, strict name
  matches otherwise, Steam's hashed asset paths for newer games,
  SteamGridDB as a fallback (built-in key from the SGDB_API_KEY secret,
  optional own key in Setup, sealed with the Keystore), and a cover made
  from the exe's icon when nothing else has one.
- Removing a game is instant and keeps its files; adding it again brings
  it back. Steam's shortcut list is rewritten once, in the background.
- The Games section is gone from Steam settings; folders added before
  keep listing their games. Artwork switch and SteamGridDB key are in
  Setup.
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-09 19:50:03 -04:00
1 parent d99ed8e00b
commit d250b43eb9
45 files changed
+4175 -295

No files matched your search

@@ -0,0 +1,106 @@
package com.droiddeck.launcher.frontend
import android.os.Environment
import com.droiddeck.launcher.session.SessionPrefs
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
/** The Games tab's +: one picked .exe becomes a game, once, wherever the session can see it. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class AddedExesTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
@org.junit.Before fun publishAtOnce() { AddedGamesPublisher.now = true }
private fun exe(path: File): File = path.apply { parentFile!!.mkdirs(); writeBytes(ByteArray(16)) }
private fun onStorage(rel: String) = exe(File(Environment.getExternalStorageDirectory(), rel))
private fun noGamesFolders() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, emptyList())
}
@Test fun theEntryStoreKeepsOneEntryPerFolder() {
assertEquals(0, AddedExes.list(app).size)
AddedExes.put(app, AddedExes.Entry("/a/One", "/a/One/one.exe"))
AddedExes.put(app, AddedExes.Entry("/a/Two", "/a/Two/two.exe"))
AddedExes.put(app, AddedExes.Entry("/a/One", "/a/One/bin/one64.exe"))
assertEquals(listOf("/a/Two" to "/a/Two/two.exe", "/a/One" to "/a/One/bin/one64.exe"), AddedExes.list(app).map { it.folder to it.exe })
AddedExes.drop(app, "/a/Two")
assertEquals(listOf("/a/One"), AddedExes.list(app).map { it.folder })
}
@Test fun aPickedExeOnInternalStorageBecomesAGameOnce() {
noGamesFolders()
val pick = onStorage("Download/Celeste/Celeste.exe")
val added = AddedGames.addExe(app, pick)
assertTrue(added is AddedGames.AddResult.Added)
val game = (added as AddedGames.AddResult.Added).game
assertEquals("Celeste", game.name)
assertEquals(pick.path, game.exe.path)
assertEquals("/root/Storage/Download/Celeste/Celeste.exe", game.guestExe)
assertEquals("/root/Storage/Download/Celeste", game.guestDir)
assertEquals(Library.ADDED, game.source)
assertTrue(File(app.filesDir, "session/added-games.json").readText().contains("Celeste.exe"))
// The same exe again: the game it already is, no second entry.
val again = AddedGames.addExe(app, pick)
assertTrue(again is AddedGames.AddResult.Existing)
assertEquals(game.appId, (again as AddedGames.AddResult.Existing).game.appId)
assertEquals(1, AddedExes.list(app).size)
assertEquals(1, AddedGames.scan(app).size)
}
@Test fun anotherExeInTheSameGameSwitchesItsExe() {
noGamesFolders()
val first = onStorage("Games2/Hades/Hades.exe")
val other = onStorage("Games2/Hades/x64/Hades.exe")
val game = (AddedGames.addExe(app, first) as AddedGames.AddResult.Added).game
val switched = AddedGames.addExe(app, other)
assertTrue(switched is AddedGames.AddResult.Switched)
assertEquals(other.path, (switched as AddedGames.AddResult.Switched).game.exe.path)
assertEquals(game.appId, switched.game.appId)
assertEquals(1, AddedGames.scan(app).size)
}
@Test fun anExeInsideAListedGamesFolderGameSwitchesThatGame() {
val games = tmp.newFolder("PC")
exe(File(games, "Example/Example.exe"))
val deep = exe(File(games, "Example/bin/Example64.exe"))
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
val result = AddedGames.addExe(app, deep)
assertTrue(result is AddedGames.AddResult.Switched)
assertEquals(deep.path, AddedGames.scan(app).single().exe.path)
assertEquals(0, AddedExes.list(app).size)
}
@Test fun anExeTheSessionCannotSeeIsNotAdded() {
noGamesFolders()
val outside = exe(File(tmp.newFolder("elsewhere"), "Game/Game.exe"))
assertEquals(AddedGames.AddResult.Unreachable, AddedGames.addExe(app, outside))
assertEquals(0, AddedExes.list(app).size)
assertEquals(0, AddedGames.scan(app).size)
}
@Test fun aRemovedSingleExeGameStaysOffUntilPickedAgain() {
noGamesFolders()
val pick = onStorage("Download/Celeste/Celeste.exe")
val game = (AddedGames.addExe(app, pick) as AddedGames.AddResult.Added).game
AddedGames.remove(app, game.folder)
assertEquals(0, AddedGames.scan(app).size)
assertTrue(AddedGames.addExe(app, pick) is AddedGames.AddResult.Switched)
assertEquals(1, AddedGames.scan(app).size)
}
}
@@ -0,0 +1,102 @@
package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.stores.CredentialCipher
import org.json.JSONArray
import org.json.JSONObject
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.security.SecureRandom
import javax.crypto.spec.SecretKeySpec
/** Where an added game's art comes from: its own Steam appid, a matching name, SteamGridDB's key. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class AddedGameArtLookupTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
@After fun tearDown() {
SteamGridDb.setUserKey(app, "")
SteamGridDb.keys = CredentialCipher.Keystore
}
@Test fun anAppidFromTheGamesFilesIsUsedWithoutASearch() {
val lookup = File(tmp.newFolder(), "steam-appid")
val id = AddedGameArt.steamAppId("Palworld", 1623730, lookup) { fail("searched"); null }
assertEquals("1623730", id)
assertEquals("1623730", lookup.readText())
// An earlier "none" from a search does not stand in its way.
lookup.writeText("none")
assertEquals("1623730", AddedGameArt.steamAppId("Palworld", 1623730, lookup) { fail("searched"); null })
}
@Test fun withoutAnAppidTheTitleIsSearchedOnceAWeek() {
val lookup = File(tmp.newFolder(), "steam-appid")
var searches = 0
assertNull(AddedGameArt.steamAppId("Nothing Like It", null, lookup) { searches++; null })
assertEquals("none", lookup.readText())
assertNull(AddedGameArt.steamAppId("Nothing Like It", null, lookup) { searches++; "1" })
assertEquals(1, searches)
lookup.setLastModified(System.currentTimeMillis() - 8L * 24 * 3600 * 1000)
assertEquals("42", AddedGameArt.steamAppId("Nothing Like It", null, lookup) { searches++; "42" })
assertEquals(2, searches)
}
@Test fun aStoreResultIsTakenOnlyWhenItsNameMatches() {
// The first result is no longer taken for being first.
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")))
assertEquals("30", AddedGameArt.pickStoreResult("Skyrim Special Edition Complete Edition", listOf("1" to "Unrelated", "30" to "Skyrim Special Edition")))
assertEquals("40", AddedGameArt.pickStoreResult("Portal 2", listOf("40" to "Portal 2 - Perpetual Testing")))
assertNull(AddedGameArt.pickStoreResult("", listOf("1" to "Anything")))
}
@Test fun aSteamGridDbSearchResultIsTakenOnlyWhenItsNameMatches() {
assertNull(SteamGridDb.match("My Obscure Game", listOf(5 to "Something Else")))
assertEquals(6, SteamGridDb.match("The Witcher 3 - Wild Hunt", listOf(5 to "Witcher", 6 to "The Witcher 3: Wild Hunt")))
}
@Test fun theBestScoredImageWinsAndAPngSlotTakesOnlyPng() {
val items = JSONArray()
.put(JSONObject().put("url", "https://cdn2.steamgriddb.com/a.png").put("mime", "image/png").put("score", 2))
.put(JSONObject().put("url", "https://cdn2.steamgriddb.com/b.jpg").put("mime", "image/jpeg").put("score", 9))
assertEquals("https://cdn2.steamgriddb.com/b.jpg", SteamGridDb.best(items, pngOnly = false))
assertEquals("https://cdn2.steamgriddb.com/a.png", SteamGridDb.best(items, pngOnly = true))
assertNull(SteamGridDb.best(JSONArray(), pngOnly = false))
}
@Test fun theUsersKeyWinsOverTheBuildsAndNoneMeansNone() {
assertEquals("user", SteamGridDb.pick("user", "build"))
assertEquals("build", SteamGridDb.pick("", "build"))
assertEquals("build", SteamGridDb.pick(" ", "build"))
assertEquals("", SteamGridDb.pick("", ""))
// This test build carries no key.
assertEquals("", SteamGridDb.builtInKey())
assertEquals("", SteamGridDb.key(app))
}
@Test fun theUsersKeyIsSealedOnDiskAndClears() {
val key = SecretKeySpec(ByteArray(32).also { SecureRandom().nextBytes(it) }, "AES")
SteamGridDb.keys = CredentialCipher.KeyProvider { key }
SteamGridDb.setUserKey(app, "abcdef0123456789secretkey")
val file = File(app.filesDir, "sgdb/key.json")
assertFalse(file.readText().contains("secretkey"))
assertTrue(CredentialCipher.isEnvelope(JSONObject(file.readText())))
assertEquals("abcdef0123456789secretkey", SteamGridDb.key(app))
SteamGridDb.setUserKey(app, "")
assertFalse(file.exists())
assertEquals("", SteamGridDb.key(app))
}
}
@@ -0,0 +1,148 @@
package com.droiddeck.launcher.frontend
import android.os.Environment
import com.droiddeck.launcher.session.SessionPrefs
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
/** "Add all games in this folder", the editor's writes to the shortcut listing, art choices. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class AddedGameEditsTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
private fun exe(rel: String, size: Int = 16): File =
File(Environment.getExternalStorageDirectory(), rel).apply { parentFile!!.mkdirs(); writeBytes(ByteArray(size)) }
private fun listing(): List<JSONObject> = JSONArray(File(app.filesDir, "session/added-games.json").readText()).let { a -> (0 until a.length()).map { a.getJSONObject(it) } }
@Before fun noGamesFolders() {
AddedGamesPublisher.now = true
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, emptyList())
}
@Test fun addingAFolderAddsEachGameWithItsBestExeAndSkipsThoseListed() {
exe("Games/Alpha/Alpha.exe")
exe("Games/Alpha/UnityCrashHandler64.exe")
exe("Games/Beta/x86/Run.exe")
exe("Games/Beta/x64/Thing.exe")
File(Environment.getExternalStorageDirectory(), "Games/Manual").mkdirs()
val listed = exe("Games/Celeste/Celeste.exe")
assertTrue(AddedGames.addExe(app, listed) is AddedGames.AddResult.Added)
val dir = File(Environment.getExternalStorageDirectory(), "Games")
val result = AddedGames.addFolder(app, dir)
assertEquals(listOf("Alpha", "Beta"), result.added.map { it.name })
assertEquals(1, result.already)
val alpha = result.added.first { it.name == "Alpha" }
assertEquals("Alpha.exe", alpha.exe.name)
assertFalse(alpha.exeUncertain)
// Two lookalikes: the best guess, marked.
assertTrue(result.added.first { it.name == "Beta" }.exeUncertain)
// Entries, not a Games folder.
assertEquals(emptyList<String>(), SessionPrefs.addedGamesDirs(app))
assertEquals(3, AddedExes.list(app).size)
assertTrue(listing().map { it.getString("name") }.containsAll(listOf("Alpha", "Beta", "Celeste")))
// Again: nothing new, all three there already.
val again = AddedGames.addFolder(app, dir)
assertEquals(emptyList<String>(), again.added.map { it.name })
assertEquals(3, again.already)
}
@Test fun editsReachTheShortcutListingOnTheSameAppid() {
val pick = exe("Games/Hades/Hades.exe")
val other = exe("Games/Hades/x64/Hades.exe")
val game = (AddedGames.addExe(app, pick) as AddedGames.AddResult.Added).game
val folder = game.folder.path
AddedGameEdits.setName(app, folder, "Hades: Deluxe")
AddedGameEdits.setLaunchOptions(app, folder, "-dx11")
assertTrue(AddedGameEdits.setStartIn(app, folder, File(game.folder, "x64").path))
assertTrue(AddedGameEdits.setExe(app, folder, other))
val entry = listing().single()
assertEquals("Hades: Deluxe", entry.getString("name"))
assertEquals("-dx11", entry.getString("launch"))
assertEquals("/root/Storage/Games/Hades/x64/Hades.exe", entry.getString("exe"))
assertEquals("/root/Storage/Games/Hades/x64", entry.getString("dir"))
assertEquals(game.appId, entry.getLong("appid"))
assertEquals(game.appId, AddedGameEdits.game(app, folder)!!.appId)
// Back to automatic.
AddedGameEdits.setName(app, folder, "")
assertTrue(AddedGameEdits.setStartIn(app, folder, ""))
val auto = listing().single()
assertEquals("Hades", auto.getString("name"))
assertEquals("/root/Storage/Games/Hades/x64", auto.getString("dir"))
assertEquals(game.appId, auto.getLong("appid"))
}
@Test fun aStartInTheSessionCannotSeeIsRefused() {
val game = (AddedGames.addExe(app, exe("Games/Tunic/Tunic.exe")) as AddedGames.AddResult.Added).game
assertFalse(AddedGameEdits.setStartIn(app, game.folder.path, tmp.newFolder("elsewhere").path))
assertEquals("", SessionPrefs.addedGameStartIn(app, game.folder.path))
}
@Test fun editsMadeInSteamAreTakenOnceAndAnAppEditAfterThemStays() {
val folder = File("/x/Game")
val record = JSONObject()
.put("app", JSONObject().put("AppName", "Game").put("StartDir", "\"/g/Game\"").put("LaunchOptions", "").put("Exe", "\"/g/Game/Game.exe\""))
.put("steam", JSONObject().put("AppName", "Game GOTY").put("StartDir", "\"/g/Game/data\"").put("LaunchOptions", "-safe").put("Exe", "\"/g/Game/Game.exe\""))
AddedGames.adoptSteamEdits(app, folder, record)
assertEquals("Game GOTY", SessionPrefs.addedGameName(app, folder.path))
assertEquals("/g/Game/data", SessionPrefs.addedGameStartIn(app, folder.path))
assertEquals("-safe", SessionPrefs.addedGameLaunch(app, folder.path))
// The user renames it in the app before Steam's shortcut is written again: the same Steam
// value is not taken a second time.
SessionPrefs.setAddedGameName(app, folder.path, "Mine")
AddedGames.adoptSteamEdits(app, folder, record)
assertEquals("Mine", SessionPrefs.addedGameName(app, folder.path))
}
@Test fun aStartInSteamMovedWithTheExeIsAutomatic() {
val folder = File("/x/Other")
val record = JSONObject()
.put("app", JSONObject().put("StartDir", "\"/g/Other\"").put("Exe", "\"/g/Other/Other.exe\""))
.put("steam", JSONObject().put("StartDir", "\"/g/Other/bin\"").put("Exe", "\"/g/Other/bin/Other.exe\""))
AddedGames.adoptSteamEdits(app, folder, record)
assertEquals("", SessionPrefs.addedGameStartIn(app, folder.path))
}
@Test fun anArtChoiceIsKeptAndResetGoesBackToAutomatic() {
val game = (AddedGames.addExe(app, exe("Games/Celeste/Celeste.exe")) as AddedGames.AddResult.Added).game
val image = File(game.folder, "cover-alt.png").apply { writeBytes(byteArrayOf(1, 2, 3)) }
val option = AddedGameArt.folderImages(game.folder).map { AddedGameArt.Option(AddedGameArt.FOLDER, it.path, it.path) }.single()
assertEquals(image.path, option.full)
assertTrue(AddedGameEdits.setArt(app, game.folder.path, AddedGameArt.Slot.COVER, option))
val cover = AddedGameArt.describe(app, game).first { it.slot == AddedGameArt.Slot.COVER }
assertTrue(cover.chosen)
assertEquals(AddedGameArt.FOLDER, cover.source)
assertEquals(AddedGameArt.FOLDER to image.path, AddedGameArt.chosenSource(app, game, AddedGameArt.Slot.COVER))
assertEquals(cover.file, AddedGameArt.resolve(app, game).portrait)
assertEquals(cover.file!!.absolutePath, listing().single().getJSONObject("art").getString("p"))
AddedGameEdits.resetArt(app, game.folder.path, AddedGameArt.Slot.COVER)
val auto = AddedGameArt.describe(app, game).first { it.slot == AddedGameArt.Slot.COVER }
assertFalse(auto.chosen)
assertNull(AddedGameArt.resolve(app, game).portrait)
assertEquals(AddedGameArt.AUTO, auto.source)
}
}
@@ -0,0 +1,151 @@
package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.session.SessionPrefs
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
/** The .exe picker below a game folder (five levels, past installer folders, ranked) and the names it finds. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class AddedGamesCandidatesTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
private fun exe(root: File, path: String, size: Int = 10): File =
File(root, path).apply { parentFile!!.mkdirs(); writeBytes(ByteArray(size)) }
private fun names(folder: File) = AddedGames.candidates(folder).map { it.relativeTo(folder).invariantSeparatorsPath }
@Test fun anUnrealShippingBuildThreeDownWinsOverTheTopLevelHelpers() {
val game = tmp.newFolder("Some Game")
exe(game, "CrashReportClient.exe", 5000)
exe(game, "Engine/Binaries/Win64/UnrealCEFSubProcess.exe", 9000)
val shipping = exe(game, "SomeGame/Binaries/Win64/SomeGame-Win64-Shipping.exe", 100)
exe(game, "SomeGame/Binaries/Win64/Tool.exe", 8000)
assertEquals("SomeGame/Binaries/Win64/SomeGame-Win64-Shipping.exe", names(game).first())
assertFalse(names(game).any { it.contains("CrashReport") })
assertEquals(shipping, AddedGames.candidates(game).first())
}
@Test fun aShippingExeNotNamedAfterTheFolderStillRanksAboveOtherDeepExes() {
val game = tmp.newFolder("Folder")
exe(game, "Proj/Binaries/Win64/Proj-Win64-Shipping.exe", 10)
exe(game, "Proj/Tools/Big.exe", 9000)
assertEquals("Proj/Binaries/Win64/Proj-Win64-Shipping.exe", names(game).first())
}
@Test fun fiveLevelsDownIsFoundSixIsNot() {
val game = tmp.newFolder("Deep")
exe(game, "a/b/c/d/e/Five.exe")
exe(game, "a/b/c/d/e/f/Six.exe")
assertEquals(listOf("a/b/c/d/e/Five.exe"), names(game))
}
@Test fun installerAndRedistFoldersAreSkipped() {
val game = tmp.newFolder("Skips")
for (dir in listOf("_CommonRedist", "CommonRedist", "Redist", "DirectX", "DotNetFx", "vcredist_x64", "Prerequisites",
"Support", "Engine/Extras", "Engine/Binaries/ThirdParty", "__Installer", "Installers", ".git", "\$PLUGINSDIR")) {
exe(game, "$dir/Thing.exe")
}
val game2 = exe(game, "Bin/Game.exe")
assertEquals(listOf("Bin/Game.exe"), names(game))
assertTrue(game2.isFile)
}
@Test fun theWalkStopsAtItsBudget() {
val game = tmp.newFolder("Huge")
for (i in 0 until GameExePicker.WALK_BUDGET + 50) File(game, "data/d%04d".format(i)).mkdirs()
exe(game, "zzz/Late.exe")
// data/ alone fills the budget before zzz/ is listed.
assertEquals(emptyList<String>(), names(game))
val small = tmp.newFolder("Small")
exe(small, "x/y/Found.exe")
assertEquals(listOf("x/y/Found.exe"), names(small))
}
@Test fun theUsersPickIsKeptOverTheDeepScan() {
val games = tmp.newFolder("PC")
val game = File(games, "Some Game")
val top = exe(game, "Launcher.exe", 10)
exe(game, "SomeGame/Binaries/Win64/SomeGame-Win64-Shipping.exe", 100)
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
SessionPrefs.setAddedGameExe(app, game.path, top.path)
val g = AddedGames.scan(app).single()
assertEquals(top.path, g.exe.path)
}
@Test fun aDeepExeStartsInItsOwnFolder() {
val games = tmp.newFolder("PC")
val game = File(games, "Some Game")
exe(game, "SomeGame/Binaries/Win64/SomeGame-Win64-Shipping.exe", 100)
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
val g = AddedGames.scan(app).single()
assertEquals("/root/Games/PC/Some Game/SomeGame/Binaries/Win64/SomeGame-Win64-Shipping.exe", g.guestExe)
assertEquals("/root/Games/PC/Some Game/SomeGame/Binaries/Win64", g.guestDir)
}
@Test fun twoLookalikeExesAreUncertainANamedOneIsNot() {
val unsure = tmp.newFolder("Folder A")
exe(unsure, "x86/Run.exe"); exe(unsure, "x64/Thing.exe")
assertTrue(GameExePicker.rank(unsure).uncertain)
val sure = tmp.newFolder("Example")
exe(sure, "Example.exe"); exe(sure, "bin/Tool.exe")
val r = GameExePicker.rank(sure)
assertFalse(r.uncertain)
assertEquals("Example.exe", r.exes.first().name)
}
@Test fun aLauncherRanksBelowTheGame() {
val game = tmp.newFolder("Grand Theft Auto V")
exe(game, "PlayGTAV.exe"); exe(game, "GTA5.exe")
assertEquals("GTA5.exe", names(game).first())
}
@Test fun anUncertainGuessIsMarkedAndAPickIsNot() {
val games = tmp.newFolder("PC")
val game = File(games, "Folder A")
exe(game, "x86/Run.exe"); val pick = exe(game, "x64/Thing.exe")
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
assertTrue(AddedGames.scan(app).single().exeUncertain)
SessionPrefs.setAddedGameExe(app, game.path, pick.path)
assertFalse(AddedGames.scan(app).single().exeUncertain)
}
@Test fun theGamesOwnTitleNamesItAndItsShortcutIdStays() {
val games = tmp.newFolder("PC")
val game = File(games, "ws-v1.2")
exe(game, "ws-v1.2.exe")
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
val before = AddedGames.scan(app).single()
assertEquals("ws-v1.2", before.name)
File(game, "goggame-1207658691.info").writeText("""{"gameId":"1207658691","name":"The Witcher 3: Wild Hunt"}""")
game.setLastModified(game.lastModified() + 10_000)
val after = AddedGames.scan(app).single()
assertEquals("The Witcher 3 - Wild Hunt", after.name)
// Already added under the folder name: the shortcut keeps its id.
assertEquals(before.appId, after.appId)
}
@Test fun onlyACleanedFileNameKeepsTheFolderName() {
val games = tmp.newFolder("PC")
val game = File(games, "My Game [Repack]")
exe(game, "MyGame-Win64-Shipping.exe")
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
assertEquals("My Game [Repack]", AddedGames.scan(app).single().name)
}
}
@@ -0,0 +1,74 @@
package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.session.SessionPrefs
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
/** Removing an added game stops listing it and keeps it off after a rescan, until it is added again; nothing on disk goes. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class AddedGamesRemoveTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
@org.junit.Before fun publishAtOnce() { AddedGamesPublisher.now = true }
private fun gamesFolder(vararg names: String): File {
val games = tmp.newFolder("PC")
for (n in names) File(games, "$n/$n.exe").apply { parentFile!!.mkdirs() }.writeText("game")
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setAddedGamesDirs(app, listOf(games.path))
return games
}
@Test fun theExclusionListAddsRemovesAndKeepsOrder() {
assertEquals(emptyList<String>(), SessionPrefs.removedAddedGames(app))
SessionPrefs.setAddedGameRemoved(app, "/a/One", true)
SessionPrefs.setAddedGameRemoved(app, "/a/Two", true)
SessionPrefs.setAddedGameRemoved(app, "/a/One", true)
assertEquals(listOf("/a/Two", "/a/One"), SessionPrefs.removedAddedGames(app))
SessionPrefs.setAddedGameRemoved(app, "/a/Two", false)
assertEquals(listOf("/a/One"), SessionPrefs.removedAddedGames(app))
SessionPrefs.setAddedGameRemoved(app, "/a/Missing", false)
assertEquals(listOf("/a/One"), SessionPrefs.removedAddedGames(app))
}
@Test fun aScanSkipsRemovedFoldersUntilRestored() {
val games = gamesFolder("Alpha", "Beta", "Gamma")
assertEquals(listOf("Alpha", "Beta", "Gamma"), AddedGames.scan(app).map { it.name })
SessionPrefs.setAddedGameRemoved(app, File(games, "Beta").path, true)
assertEquals(listOf("Alpha", "Gamma"), AddedGames.scan(app).map { it.name })
// A rescan does not bring it back.
assertEquals(listOf("Alpha", "Gamma"), AddedGames.scan(app).map { it.name })
SessionPrefs.setAddedGameRemoved(app, File(games, "Beta").path, false)
assertEquals(listOf("Alpha", "Beta", "Gamma"), AddedGames.scan(app).map { it.name })
}
@Test fun removeDropsItFromTheListingAndLeavesTheFolder() {
val games = gamesFolder("Alpha", "Beta")
val beta = File(games, "Beta")
AddedGames.remove(app, beta)
assertEquals(listOf(beta.path), SessionPrefs.removedAddedGames(app))
assertEquals(listOf("Alpha"), AddedGames.scan(app).map { it.name })
val listing = File(app.filesDir, "session/added-games.json").readText()
assertTrue(listing.contains("\"Alpha\""))
assertTrue(!listing.contains("\"Beta\""))
assertTrue(File(beta, "Beta.exe").isFile)
// Added again with the +: it comes back.
assertTrue(AddedGames.addExe(app, File(beta, "Beta.exe")) is AddedGames.AddResult.Switched)
assertEquals(emptyList<String>(), SessionPrefs.removedAddedGames(app))
assertTrue(File(app.filesDir, "session/added-games.json").readText().contains("\"Beta\""))
}
}
@@ -0,0 +1,14 @@
package com.droiddeck.launcher.frontend
import org.junit.Assert.assertEquals
import org.junit.Test
class AddedGamesSpellingTest {
@Test fun folderSpacingWinsOverAJoinedExeName() = assertEquals("Insane 2", AddedGames.betterSpelling("Insane2", "Insane 2"))
@Test fun exeSpacingWinsOverAJoinedFolderName() = assertEquals("DiRT 3", AddedGames.betterSpelling("DiRT 3", "dirt3"))
@Test fun mixedCaseWinsATie() = assertEquals("Hollow Knight", AddedGames.betterSpelling("HOLLOW KNIGHT", "Hollow Knight"))
@Test fun differentTitlesKeepTheExeName() = assertEquals("The Witcher 3", AddedGames.betterSpelling("The Witcher 3", "witcher3-goty"))
@Test fun sameSpellingKeepsTheExeName() = assertEquals("Celeste", AddedGames.betterSpelling("Celeste", "Celeste"))
@Test fun underscoresBecomeSpaces() = assertEquals("Watch Dogs", AddedGames.betterSpelling(AddedGames.underscoresToSpaces("Watch_Dogs"), "Watch Dogs"))
@Test fun underscoresBecomeSpacesWithoutAFolderMatch() = assertEquals("Watch Dogs 2", AddedGames.underscoresToSpaces("Watch_Dogs_2"))
}
@@ -0,0 +1,219 @@
package com.droiddeck.launcher.frontend
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
/**
* Signal-chain coverage for [GameIdentifier]. Pure JVM: builds
* fake game layouts in a temp dir and asserts the right appId/name/source/confidence come back.
* The PE version-resource path is exercised on-device (real .exe), not here.
*/
class GameIdentifierTest {
@get:Rule
val tmp = TemporaryFolder()
private fun exeIn(dir: File, name: String = "game.exe"): File =
File(dir, name).apply { parentFile?.mkdirs(); writeBytes(byteArrayOf(0x4D, 0x5A)) } // "MZ" — not a real PE
@Test
fun steamAppIdTxt_besideExe_givesHighConfidenceAppId() {
val dir = tmp.newFolder("Palworld")
File(dir, "steam_appid.txt").writeText("1623730\n")
val id = GameIdentifier.identify(exeIn(dir))
assertEquals(1623730, id.appId)
assertEquals(GameIdentifier.Source.STEAM_APPID_TXT, id.source)
assertEquals(GameIdentifier.Confidence.HIGH, id.confidence)
}
@Test
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)
}
@Test
fun coldClientLoaderIni_appIdKey_isParsed() {
val dir = tmp.newFolder("Cracked")
File(dir, "ColdClientLoader.ini").writeText("[SteamClient]\nExe=game.exe\nAppId=427520\n")
val id = GameIdentifier.identify(exeIn(dir))
assertEquals(427520, id.appId)
assertEquals(GameIdentifier.Source.STEAM_EMU_INI, id.source)
}
@Test
fun steamManifestAcf_matchedByInstalldir_givesAppIdAndName() {
// steamapps/common/Palworld/Pal/Binaries/Win64/Palworld-Win64-Shipping.exe
val steamapps = tmp.newFolder("steamapps")
File(steamapps, "appmanifest_1623730.acf").writeText(
"""
"AppState"
{
"appid" "1623730"
"name" "Palworld"
"installdir" "Palworld"
}
""".trimIndent()
)
// a decoy manifest that must NOT win
File(steamapps, "appmanifest_570.acf").writeText(
""""AppState" { "appid" "570" "name" "Dota 2" "installdir" "dota 2 beta" }"""
)
val win64 = File(steamapps, "common/Palworld/Pal/Binaries/Win64").apply { mkdirs() }
val id = GameIdentifier.identify(exeIn(win64, "Palworld-Win64-Shipping.exe"))
assertEquals(1623730, id.appId)
assertEquals("Palworld", id.name)
assertEquals(GameIdentifier.Source.STEAM_MANIFEST_ACF, id.source)
}
@Test
fun gogInfo_givesNameAndId_highConfidence() {
val dir = tmp.newFolder("Witcher3")
File(dir, "goggame-1207658691.info").writeText(
"""{"gameId":"1207658691","name":"The Witcher 3: Wild Hunt","version":1}"""
)
val id = GameIdentifier.identify(exeIn(dir))
// normalizeName() deliberately converts ":" to " - " (a colon is illegal in a Windows
// filename), so the identified name never carries one. The test asserted the raw GOG
// string and had never passed.
assertEquals("The Witcher 3 - Wild Hunt", id.name)
assertEquals("1207658691", id.gogId)
assertNull(id.appId)
assertEquals(GameIdentifier.Confidence.HIGH, id.confidence)
}
@Test
fun acfNamePreferredOverGogName_whenBothPresent() {
val steamapps = tmp.newFolder("steamapps")
File(steamapps, "appmanifest_100.acf").writeText(""""AppState"{"appid" "100" "name" "SteamName" "installdir" "MyGame"}""")
val gameDir = File(steamapps, "common/MyGame").apply { mkdirs() }
File(gameDir, "goggame-9.info").writeText("""{"name":"GogName"}""")
val id = GameIdentifier.identify(exeIn(gameDir))
assertEquals("SteamName", id.name)
assertEquals(100, id.appId)
}
@Test
fun noMarkers_fallsBackToCleanedFolderName_forEngineBinary() {
// UE shipping binary → the folder name is the real title, exe basename is noise.
val dir = tmp.newFolder("Hades")
val id = GameIdentifier.identify(exeIn(dir, "Hades-Win64-Shipping.exe"))
assertEquals("Hades", id.name)
assertEquals(GameIdentifier.Source.FILENAME, id.source)
assertEquals(GameIdentifier.Confidence.LOW, id.confidence)
}
@Test
fun fallbackName_stripsRepackTagsAndVersionTokens() {
val dir = tmp.newFolder("Stardew Valley [FitGirl Repack] v1.5.4")
val id = GameIdentifier.identify(exeIn(dir, "Stardew.exe"))
assertEquals("Stardew", id.name) // exe basename wins (not an engine binary); folder tags irrelevant here
// and a repack-style exe basename is cleaned too:
val id2 = GameIdentifier.identify(exeIn(tmp.newFolder("g2"), "Game.CODEX.exe"))
assertEquals(GameIdentifier.Source.FILENAME, id2.source)
}
@Test
fun fltIni_gameSettingsAppId_isParsed() {
// Real God of War (FLT release) layout: flt.ini holds the appid under [GameSettings].
val dir = tmp.newFolder("GodOfWar")
File(dir, "flt.ini").writeText("[GameSettings]\nAppId=1593500\nUserName=X\nBuildId=7969425\n")
File(dir, "settings.ini").writeText("[Settings]\nVideoDevice=Wrapper\nMonitor=0\n") // no AppId -> ignored
val id = GameIdentifier.identify(exeIn(dir, "GoW.exe"))
assertEquals(1593500, id.appId)
assertEquals(GameIdentifier.Confidence.HIGH, id.confidence)
}
@Test
fun genericIni_withAppId_isFoundByBroadScan() {
val dir = tmp.newFolder("g")
File(dir, "whatever_crack.ini").writeText("[cfg]\nappid = 220\n")
assertEquals(220, GameIdentifier.identify(exeIn(dir)).appId)
}
@Test
fun bestName_prefersFileDescriptionWhenProductNameIsAbbreviation() {
// God of War ships ProductName "GoW" but FileDescription "God of War".
assertEquals(
"God of War",
PeVersionInfo.bestName(mapOf("ProductName" to "GoW", "FileDescription" to "God of War")),
)
// Normal case: ProductName is the full title -> keep it.
assertEquals(
"Cyberpunk 2077",
PeVersionInfo.bestName(mapOf("ProductName" to "Cyberpunk 2077", "FileDescription" to "Cyberpunk 2077")),
)
assertNull(PeVersionInfo.bestName(null))
}
@Test
fun name_isNormalizedToBeFilesystemSafeAndTidy() {
// Colon → " - " (would otherwise be sanitized to '_' by the shortcut writer).
val d1 = tmp.newFolder("ds")
File(d1, "goggame-1.info").writeText("""{"name":"Dark Souls: Remastered"}""")
assertEquals("Dark Souls - Remastered", GameIdentifier.identify(exeIn(d1)).name)
// Trademark marks (symbol and text forms) stripped.
val d2 = tmp.newFolder("gow2")
File(d2, "goggame-2.info").writeText("""{"name":"God of War™"}""")
assertEquals("God of War", GameIdentifier.identify(exeIn(d2)).name)
val d3 = tmp.newFolder("ds3")
File(d3, "goggame-3.info").writeText("""{"name":"DARK SOULS(TM): REMASTERED"}""")
assertEquals("DARK SOULS - REMASTERED", GameIdentifier.identify(exeIn(d3)).name)
// Trailing PE descriptors dropped (DiRT 3's FileDescription is "DiRT 3 Executable").
val d4 = tmp.newFolder("dirt")
File(d4, "goggame-4.info").writeText("""{"name":"DiRT 3 Executable"}""")
assertEquals("DiRT 3", GameIdentifier.identify(exeIn(d4)).name)
}
@Test
fun launcherExe_prefersFolderName_overLauncher() {
// GTA V Enhanced: user picks the Rockstar launcher PlayGTAV.exe (no Steam id, PE = junk on
// a real exe). Fallback must use the folder title, not "PlayGTAV".
val dir = tmp.newFolder("Grand Theft Auto V Enhanced")
val id = GameIdentifier.identify(exeIn(dir, "PlayGTAV.exe"))
assertEquals("Grand Theft Auto V Enhanced", id.name)
assertEquals(GameIdentifier.Source.FILENAME, id.source)
}
@Test
fun launcherExe_withSeparator_prefersFolder_andStripsSiteTag() {
val dir = tmp.newFolder("Grand-Theft-Auto-IV-AnkerGames")
val id = GameIdentifier.identify(exeIn(dir, "Play - GTA IV.exe"))
assertEquals("Grand Theft Auto IV", id.name) // "AnkerGames" site tag stripped
}
@Test
fun nonLauncherExe_startingWithPlay_keepsItsOwnName() {
// "PlayerUnknown" must NOT be treated as a launcher (would wrongly use the folder name).
val dir = tmp.newFolder("SomeInstallFolder")
val id = GameIdentifier.identify(exeIn(dir, "PlayerUnknown.exe"))
assertEquals("PlayerUnknown", id.name)
}
@Test
fun isJunkPeName_flagsLaunchersNotGames() {
for (junk in listOf("Rockstar Games Launcher Redirector", "GSE", "Steam", "Launcher", "Epic Games Launcher")) {
assertTrue("expected junk: $junk", GameIdentifier.isJunkPeName(junk))
}
for (real in listOf("God of War", "Grand Theft Auto V", "DARK SOULS: REMASTERED", "Hades")) {
assertFalse("expected real: $real", GameIdentifier.isJunkPeName(real))
}
}
@Test
fun emptyWhenNothingIdentifiable() {
val dir = tmp.newFolder("x")
val id = GameIdentifier.identify(exeIn(dir, "Game.exe")) // engine-ish base → folder "x"
// "x" is a valid (if useless) fallback name; the point is it must not crash and appId is null.
assertNull(id.appId)
assertTrue(id.confidence == GameIdentifier.Confidence.LOW)
}
}
@@ -0,0 +1,52 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assume.assumeFalse
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.io.File
/** What the in-app picker lists in a folder: every folder A-Z, then only the files asked for. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class PickListingTest {
@get:Rule val tmp = TemporaryFolder()
private fun storage(): File {
val root = tmp.newFolder("emulated0")
for (d in listOf("Download", "Android", "DCIM", "Games", "Documents", "Winlator", ".thumbnails", "alarms")) File(root, d).mkdirs()
for (f in listOf("Setup.exe", "game.EXE", "cover.jpg", "notes.txt", "logo.PNG", "icon.ico", "hero.webp", ".hidden.exe")) File(root, f).writeText("x")
return root
}
@Test fun everyFolderIsListedAToZAndDotFoldersAreNot() {
val listing = pickListing(storage(), PickKind.EXE)
assertEquals(listOf("alarms", "Android", "DCIM", "Documents", "Download", "Games", "Winlator"), listing.folders.map { it.dir.name })
}
@Test fun onlyExesForAGameOnlyImagesForArt() {
val root = storage()
assertEquals(listOf("game.EXE", "Setup.exe"), pickListing(root, PickKind.EXE).files.map { it.name })
assertEquals(listOf("cover.jpg", "hero.webp", "icon.ico", "logo.PNG"), pickListing(root, PickKind.IMAGE).files.map { it.name })
}
@Test fun aFolderTheAppCannotReadIsListedButMarked() {
val root = storage()
val locked = File(root, "Android")
locked.setReadable(false, false)
try {
assumeFalse("running as root reads everything", locked.list() != null)
val folders = pickListing(root, PickKind.EXE).folders.associate { it.dir.name to it.readable }
assertFalse(folders.getValue("Android"))
assertTrue(folders.getValue("Download"))
} finally {
locked.setReadable(true, false)
}
}
}