mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Games: old Games folders become entries, not Steam libraries (#542)
Games folders saved before the settings section went away were still registered as Steam libraries on Automatic, with no way left to remove them. Once, at app start and before any scan, each game such a folder listed becomes an entry of its own, keeping everything keyed by its folder (chosen exe, shortcut appid, name, Start in, launch options, art, removal); store installs and steamapps are skipped. The folders stay bound at their old guest paths, so no shortcut changes, and the saved roots are cleared. A Games folder stays a library only when Steam installed a game into it; the others leave the library list, and the runtime forgets them.
This commit is contained in:
1 parent
49f6209c3a
commit
3589ad9127
12 files changed
+266
-30
No files matched your search
@@ -83,7 +83,8 @@ class AddedExesTest {
|
||||
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)
|
||||
// The Games folder's game is an entry of its own (GamesFolderMigration); no second one.
|
||||
assertEquals(listOf(File(games, "Example").path), AddedExes.list(app).map { it.folder })
|
||||
}
|
||||
|
||||
@Test fun anExeTheSessionCannotSeeIsNotAdded() {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.session.GameStorage
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
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
|
||||
|
||||
/** Games folders from earlier builds become entries, every game keeping what it had. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GamesFolderMigrationTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun exe(root: File, rel: String) = File(root, rel).apply { parentFile!!.mkdirs(); writeBytes(ByteArray(16)) }
|
||||
|
||||
@Before fun setUp() {
|
||||
SessionPrefs.setGameStorage(app, "", "")
|
||||
AddedGamesPublisher.now = true
|
||||
}
|
||||
|
||||
@Test fun eachGameBecomesAnEntryKeepingItsExeAppidNameAndRemoval() {
|
||||
val pc = tmp.newFolder("PC")
|
||||
val alpha = File(pc, "Alpha"); exe(pc, "Alpha/Alpha.exe")
|
||||
val beta = File(pc, "Beta"); exe(pc, "Beta/Beta.exe"); val pick = exe(pc, "Beta/bin/Beta64.exe")
|
||||
val gone = File(pc, "Gone"); exe(pc, "Gone/Gone.exe")
|
||||
exe(pc, "steamapps/common/Installed/Installed.exe")
|
||||
val store = File(pc, "Store"); exe(pc, "Store/Store.exe")
|
||||
StoreGameSidecar.file(store).writeText("""{"store":"gog","id":"1","title":"Store Game","exe":"Store.exe"}""")
|
||||
File(pc, "Notes").mkdirs()
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(pc.path))
|
||||
// What earlier scans had kept, by folder.
|
||||
SessionPrefs.setAddedGameExe(app, beta.path, pick.path)
|
||||
SessionPrefs.addedGameAppId(app, alpha.path, 0x8123_4567L)
|
||||
SessionPrefs.addedGameAppId(app, beta.path, 0x8765_4321L)
|
||||
SessionPrefs.setAddedGameName(app, alpha.path, "Alpha GOTY")
|
||||
SessionPrefs.setAddedGameRemoved(app, gone.path, true)
|
||||
|
||||
GamesFolderMigration.run(app)
|
||||
|
||||
assertEquals(emptyList<String>(), SessionPrefs.addedGamesDirs(app))
|
||||
assertTrue(SessionPrefs.gamesFoldersMigrated(app))
|
||||
val entries = AddedExes.list(app).associateBy { it.folder }
|
||||
assertEquals(setOf(alpha.path, beta.path, gone.path), entries.keys)
|
||||
assertTrue(entries.getValue(beta.path).picked)
|
||||
assertEquals(pick.path, entries.getValue(beta.path).exe)
|
||||
assertFalse(entries.getValue(alpha.path).picked)
|
||||
|
||||
val games = AddedGames.scan(app).associateBy { it.folder.path }
|
||||
assertEquals(setOf(alpha.path, beta.path), games.keys)
|
||||
assertEquals(0x8123_4567L, games.getValue(alpha.path).appId)
|
||||
assertEquals(0x8765_4321L, games.getValue(beta.path).appId)
|
||||
assertEquals("Alpha GOTY", games.getValue(alpha.path).name)
|
||||
assertEquals(pick.path, games.getValue(beta.path).exe.path)
|
||||
// The same path inside the session as before: the shortcut keeps its target.
|
||||
assertEquals(AddedGames.GUEST_DIR + "/PC/Alpha/Alpha.exe", games.getValue(alpha.path).guestExe)
|
||||
assertEquals(AddedGames.GUEST_DIR + "/PC/Beta/bin/Beta64.exe", games.getValue(beta.path).guestExe)
|
||||
assertTrue(SessionPrefs.removedAddedGames(app).contains(gone.path))
|
||||
// Not a library any more.
|
||||
assertTrue(GameStorage.gamesFolderLibraries(app).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun runningAgainChangesNothing() {
|
||||
val pc = tmp.newFolder("PC")
|
||||
exe(pc, "Alpha/Alpha.exe")
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(pc.path))
|
||||
GamesFolderMigration.run(app)
|
||||
val entries = AddedExes.list(app).map { it.folder to it.exe }
|
||||
val binds = SessionPrefs.gameFolderBinds(app)
|
||||
val before = AddedGames.scan(app).map { it.appId to it.guestExe }
|
||||
GamesFolderMigration.run(app)
|
||||
GamesFolderMigration.run(app)
|
||||
assertEquals(entries, AddedExes.list(app).map { it.folder to it.exe })
|
||||
assertEquals(binds, SessionPrefs.gameFolderBinds(app))
|
||||
assertEquals(before, AddedGames.scan(app).map { it.appId to it.guestExe })
|
||||
assertEquals(listOf(pc.path to AddedGames.GUEST_DIR + "/PC"), binds)
|
||||
}
|
||||
|
||||
@Test fun twoFoldersOfOneNameKeepTheirOwnGuestPaths() {
|
||||
val a = File(tmp.newFolder("a"), "Games").apply { mkdirs() }
|
||||
val b = File(tmp.newFolder("b"), "Games").apply { mkdirs() }
|
||||
exe(a, "One/One.exe")
|
||||
exe(b, "Two/Two.exe")
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(a.path, b.path))
|
||||
val guests = GamesFolderMigration.legacyRoots(listOf(a.path, b.path)).map { it.guest }
|
||||
val games = AddedGames.scan(app).associateBy { it.name }
|
||||
assertEquals(guests[0] + "/One/One.exe", games.getValue("One").guestExe)
|
||||
assertEquals(guests[1] + "/Two/Two.exe", games.getValue("Two").guestExe)
|
||||
assertTrue(guests[0] != guests[1])
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,14 @@ class GameStorageTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun gamesFoldersBecomeLibrariesOnAutomatic() {
|
||||
@Test fun onlyAGamesFolderSteamInstalledIntoStaysALibrary() {
|
||||
val pc = tmp.newFolder("PC")
|
||||
File(pc, "steamapps").mkdirs()
|
||||
File(pc, "steamapps/appmanifest_220.acf").writeText("\"AppState\" { \"appid\" \"220\" }")
|
||||
val plain = tmp.newFolder("Games")
|
||||
File(plain, "steamapps/common").mkdirs()
|
||||
val missing = File(tmp.root, "Unplugged")
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(pc.path, missing.path))
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(pc.path, plain.path, missing.path))
|
||||
val libraries = GameStorage.gamesFolderLibraries(app)
|
||||
assertEquals(listOf(pc), libraries.map { it.host })
|
||||
assertEquals(listOf(AddedGames.GUEST_DIR + "/PC"), libraries.map { it.guest })
|
||||
@@ -28,7 +32,10 @@ class GameStorageTest {
|
||||
}
|
||||
|
||||
@Test fun aChosenLibraryOrInternalKeepsGamesFoldersPlain() {
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(tmp.newFolder("PC").path))
|
||||
val pc = tmp.newFolder("PC")
|
||||
File(pc, "steamapps").mkdirs()
|
||||
File(pc, "steamapps/appmanifest_220.acf").writeText("x")
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(pc.path))
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
assertTrue(GameStorage.gamesFolderLibraries(app).isEmpty())
|
||||
SessionPrefs.setGameStorage(app, tmp.newFolder("chosen").path, "Chosen")
|
||||
@@ -36,7 +43,9 @@ class GameStorageTest {
|
||||
}
|
||||
|
||||
@Test fun namesTheClientCannotStoreAreLeftOut() {
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(tmp.newFolder("Quote\"d").path, tmp.newFolder("Back\\slash").path))
|
||||
val odd = listOf(tmp.newFolder("Quote\"d"), tmp.newFolder("Back\\slash"))
|
||||
odd.forEach { File(it, "steamapps").mkdirs(); File(it, "steamapps/appmanifest_220.acf").writeText("x") }
|
||||
SessionPrefs.setAddedGamesDirs(app, odd.map { it.path })
|
||||
assertTrue(GameStorage.gamesFolderLibraries(app).isEmpty())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user