diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/GamesFolderMigration.kt b/app/src/main/java/com/droiddeck/launcher/frontend/GamesFolderMigration.kt index 91e5469579..5ecf529126 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/GamesFolderMigration.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/GamesFolderMigration.kt @@ -63,7 +63,8 @@ object GamesFolderMigration { val names = hosts.groupingBy { it.name.lowercase() }.eachCount() return hosts.map { host -> val name = host.name.ifEmpty { "games" } - val guestName = if ((names[name.lowercase()] ?: 0) > 1) name + "-" + "%08x".format(CRC32().apply { update(host.path.toByteArray()) }.value).take(4) else name + val clash = (names[name.lowercase()] ?: 0) > 1 || "${AddedGames.GUEST_DIR}/$name" == StoreInstallRoot.INTERNAL_GUEST + val guestName = if (clash) name + "-" + "%08x".format(CRC32().apply { update(host.path.toByteArray()) }.value).take(4) else name AddedGames.Root(host, "${AddedGames.GUEST_DIR}/$guestName") } } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt index b5677d44d9..040969b840 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt @@ -14,6 +14,7 @@ import java.util.zip.CRC32 object StoreInstallRoot { const val SPACE_UNKNOWN = -1L private const val INTERNAL = "root/Games/Stores" + const val INTERNAL_GUEST = "/$INTERNAL" private const val ON_VOLUME = "Games" const val GUEST_EXTERNAL = "/mnt/droiddeck-stores" @@ -192,18 +193,13 @@ object StoreInstallRoot { } } for (folder in AddedGames.roots(context)) { - if (!folder.host.isDirectory || !folder.host.canRead() || shadowsInternal(folder.guest)) continue + if (!folder.host.isDirectory || !folder.host.canRead()) continue File(root, folder.guest.removePrefix("/")).mkdirs() out += folder.host.path + ":" + folder.guest } return out } - private fun shadowsInternal(guest: String): Boolean { - val internal = "/$INTERNAL" - return guest == internal || internal.startsWith("$guest/") - } - internal fun externalBindSpecs(roots: List>, guestRoot: File): List = roots.mapNotNull { (host, guest) -> if (!host.isDirectory || !host.canRead()) return@mapNotNull null 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 d8626a3bb0..4177074a00 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedExesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedExesTest.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.frontend import com.droiddeck.launcher.assumeFilePermissionsEnforced import android.os.Environment import com.droiddeck.launcher.session.SessionPrefs +import com.droiddeck.launcher.stores.StoreInstallRoot import java.io.File import org.junit.Assert.assertEquals import org.junit.Assert.assertNull @@ -366,6 +367,15 @@ class AddedExesTest { assertEquals("$clash-2", guests.last()) } + @Test fun aFolderNamedStoresIsNotBoundOverTheInternalStoreRoot() { + noGamesFolders() + val stores = File(tmp.newFolder("card"), "Stores").apply { exe(File(this, "One/One.exe")) } + val result = AddedGames.addFolder(app, stores) + val guest = SessionPrefs.gameFolderBinds(app).single().second + assertTrue(guest != StoreInstallRoot.INTERNAL_GUEST && guest.startsWith("${AddedGames.GUEST_DIR}/Stores-")) + assertEquals("$guest/One/One.exe", result.added.single().guestExe) + } + @Test fun aRemovedSingleExeGameStaysOffUntilPickedAgain() { noGamesFolders() val pick = onStorage("Download/Celeste/Celeste.exe") diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/GamesFolderMigrationTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/GamesFolderMigrationTest.kt index 4994b3aebf..43dd005852 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/GamesFolderMigrationTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/GamesFolderMigrationTest.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.frontend import com.droiddeck.launcher.session.GameStorage import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.stores.StoreGameSidecar +import com.droiddeck.launcher.stores.StoreInstallRoot import java.io.File import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -182,6 +183,18 @@ class GamesFolderMigrationTest { assertEquals(listOf(pc.path to AddedGames.GUEST_DIR + "/PC"), binds) } + @Test fun aMigratedFolderNamedStoresDoesNotTakeTheInternalStoreGuest() { + val stores = File(tmp.newFolder("card"), "Stores").apply { exe(this, "One/One.exe") } + val pc = tmp.newFolder("PC").apply { exe(this, "Two/Two.exe") } + SessionPrefs.setAddedGamesDirs(app, listOf(stores.path, pc.path)) + GamesFolderMigration.run(app) + val binds = SessionPrefs.gameFolderBinds(app).toMap() + assertTrue(binds.getValue(stores.path) != StoreInstallRoot.INTERNAL_GUEST) + assertEquals(AddedGames.GUEST_DIR + "/PC", binds.getValue(pc.path)) + val games = AddedGames.scan(app).associateBy { it.name } + assertEquals(binds.getValue(stores.path) + "/One/One.exe", games.getValue("One").guestExe) + } + @Test fun twoFoldersOfOneNameKeepTheirOwnGuestPaths() { val a = File(tmp.newFolder("a"), "Games").apply { mkdirs() } val b = File(tmp.newFolder("b"), "Games").apply { mkdirs() } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt index 76be607cab..127d6eb5a4 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt @@ -75,13 +75,20 @@ class GogInnoextractTest { assertTrue(AddedGames.guestPath(app, folder)!!.startsWith("/root/Games/Stores/GOG/")) } - @Test fun anAddedFolderNamedStoresDoesNotHideTheInternalInstallRoot() { - val shadow = File(app.filesDir, "extra/Stores").apply { mkdirs() } - val normal = File(app.filesDir, "extra/Library").apply { mkdirs() } - SessionPrefs.setGameFolderBinds(app, listOf(shadow.path to "/root/Games/Stores", normal.path to "/root/Games/Library")) - val binds = StoreInstallRoot.guestBinds(app) - assertTrue(binds.none { it.endsWith(":/root/Games/Stores") }) - assertTrue(binds.contains("${normal.path}:/root/Games/Library")) + @Test fun anAddedFolderNamedStoresIsMountedWithoutHidingTheInternalInstallRoot() { + val drive = File(app.filesDir, "usb/Stores").apply { mkdirs() } + AddedGames.bindFolder(app, drive) + val guest = AddedGames.guestPath(app, drive)!! + assertTrue(guest != StoreInstallRoot.INTERNAL_GUEST && !guest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/")) + SessionPrefs.setDefaultStorageFolder(app, drive.path, "Stores") + val chosen = File(drive, "Games/GOG/Chosen") + assertTrue(AddedGames.guestPath(app, chosen)!!.startsWith("$guest/")) + assertExtractorSeesEveryPart(chosen, listOf("setup_1207658934.exe", "setup_1207658934-1.bin")) + val internal = File(StoreInstallRoot.internalRoot(app), "GOG/Internal") + installer(internal, listOf("setup_1207658935.exe")) + val internalGuest = AddedGames.guestPath(app, internal)!! + assertTrue(internalGuest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/GOG/")) + assertNull(hostOf("$internalGuest/setup_1207658935.exe", StoreInstallRoot.guestBinds(app))) } @Test fun aFailedExtractionReportsTheExtractorsOwnError() {