diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 7b7dc4fdfd..04984918ae 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1036,7 +1036,7 @@ class SessionService : Service() { Log.w(TAG, "added games: ${root.host} is not a readable folder this session") } } - for ((host, guest) in com.droiddeck.launcher.stores.StoreInstallRoot.externalRoots(this)) { + for ((host, guest) in com.droiddeck.launcher.stores.StoreInstallRoot.externalRootsForXodus(this)) { if (host.isDirectory && host.canRead()) { File(LinuxRuntime.rootDir(this), guest.removePrefix("/")).mkdirs() binds.add(host.path + ":" + guest) 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 fa20167da9..d1acc89372 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt @@ -137,10 +137,7 @@ object StoreInstallRoot { .filter { !isInternal(context, it) && (library == null || !it.absolutePath.startsWith("$library/")) } .map { root -> val base = guestFor(context, root) - val guest = if (used.add(base)) base else { - val suffix = "%08x".format(CRC32().apply { update(root.absolutePath.toByteArray()) }.value) - "$base-$suffix".also { used.add(it) } - } + val guest = if (used.add(base)) base else "$base-${pathKey(root)}".also { used.add(it) } root to guest } } @@ -168,15 +165,20 @@ object StoreInstallRoot { /** Xodus has its own PRoot mount table and cannot see the selected Steam library's SD bind. */ fun externalRootsForXodus(context: Context): List> { - val roots = externalRoots(context).toMutableList() + val roots = externalRoots(context) val selectedLibrary = GameStorage.effective(context)?.let { File(it.path, ON_VOLUME) } - ?.takeUnless { isInternal(context, it) } - if (selectedLibrary != null && roots.none { it.first.absolutePath == selectedLibrary.absolutePath }) { - roots += selectedLibrary to guestFor(context, selectedLibrary) - } - return roots + ?.takeUnless { isInternal(context, it) } ?: return roots + return withSelectedLibrary(roots, selectedLibrary, guestFor(context, selectedLibrary)) } + internal fun withSelectedLibrary(roots: List>, library: File, base: String): List> { + if (roots.any { it.first.absolutePath == library.absolutePath }) return roots + val guest = if (roots.none { it.second == base }) base else "$base-${pathKey(library)}" + return roots + (library to guest) + } + + private fun pathKey(root: File): String = "%08x".format(CRC32().apply { update(root.absolutePath.toByteArray()) }.value) + fun externalBindSpecs(context: Context): List = externalBindSpecs(externalRoots(context), LinuxRuntime.rootDir(context)) fun externalBindSpecsForXodus(context: Context): List = @@ -192,7 +194,7 @@ object StoreInstallRoot { private fun guestFor(context: Context, root: File): String { val sm = context.getSystemService(StorageManager::class.java) val uuid = runCatching { sm?.getStorageVolume(root)?.uuid }.getOrNull()?.takeIf { it.isNotBlank() }?.replace(Regex("[^A-Za-z0-9-]"), "") - val key = uuid ?: "%08x".format(CRC32().apply { update(root.absolutePath.toByteArray()) }.value) + val key = uuid ?: pathKey(root) return "$GUEST_EXTERNAL/$key" } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt index 126001797d..78508a525f 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt @@ -138,6 +138,32 @@ class StoreInstallRootTest { assertTrue(File(LinuxRuntime.rootDir(app), xodusRoot.second.removePrefix("/")).isDirectory) } + @Test fun xodusRootsKeepEveryOtherStoreRootAtTheSameGuestPath() { + val card = File(app.filesDir, "card2").apply { mkdirs() } + val library = File(app.filesDir, "card/steam").apply { mkdirs() } + File(library, "Games").mkdirs() + SessionPrefs.setDefaultStorageFolder(app, card.path, "Card 2") + SessionPrefs.setGameStorage(app, library.path, "Card") + + val xodus = StoreInstallRoot.externalRootsForXodus(app) + assertTrue(xodus.containsAll(StoreInstallRoot.externalRoots(app))) + assertTrue(xodus.any { it.first.absolutePath == File(library, "Games").absolutePath }) + } + + @Test fun theSteamLibraryGetsItsOwnGuestPathWhenItSharesACardWithAnotherStoreRoot() { + val card = File(app.filesDir, "same-card/Games") + val library = File(app.filesDir, "same-card/steam/Games") + val base = "/mnt/droiddeck-stores/ABCD-1234" + + val roots = StoreInstallRoot.withSelectedLibrary(listOf(card to base), library, base) + assertEquals(2, roots.map { it.second }.distinct().size) + assertEquals(base, roots.single { it.first == card }.second) + assertTrue(roots.single { it.first == library }.second.startsWith("$base-")) + assertEquals("${roots.single { it.first == library }.second}/Xbox/Doom", + StoreInstallRoot.externalGuestPath(File(library, "Xbox/Doom"), roots)) + assertEquals(roots, StoreInstallRoot.withSelectedLibrary(roots, library, base)) + } + @Test fun externalStoreBindsCreateGuestTargetsAndSkipUnavailableVolumes() { val host = File(app.filesDir, "card/Games").apply { mkdirs() } val guestRoot = "/mnt/droiddeck-stores/card" diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox index 9382f2deba..efd0b707fc 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox @@ -151,13 +151,13 @@ def view_drive(prefix, exe): if os.path.lexists(link) and (os.path.exists(link) or not os.readlink(link).startswith(str(view.parent.parent) + '/')): continue devices.mkdir(parents=True, exist_ok=True) - staged.symlink_to(view) + staged.symlink_to(view.parent) os.replace(staged, link) except OSError: if os.path.lexists(staged): staged.unlink() continue - return letter.upper() + ':\\' + str(path.relative_to(view)).replace('/', '\\'), link + return letter.upper() + ':\\' + str(path.relative_to(view.parent)).replace('/', '\\'), link return exe, None diff --git a/tools/tests/test_xbox_launch.py b/tools/tests/test_xbox_launch.py index 370c694dfd..1701d6ea4b 100644 --- a/tools/tests/test_xbox_launch.py +++ b/tools/tests/test_xbox_launch.py @@ -136,7 +136,7 @@ class XboxLaunchTest(unittest.TestCase): self.assertNotIn('DROIDDECK_XBOX_COMMAND_FILE', child_env) self.assertEqual(child_env['XODUS_BRIDGE_KEY'], 'runtime-key') - def test_launch_view_runs_from_a_short_drive_letter(self): + def test_launch_view_runs_from_its_own_folder_on_a_short_drive_letter(self): with tempfile.TemporaryDirectory() as root: root = Path(root) prefix = root / 'compat/pfx' @@ -156,7 +156,7 @@ class XboxLaunchTest(unittest.TestCase): with patch.dict(os.environ, env), patch.dict(xbox['wine'].__globals__, RUNTIME=runtime.parent), patch('subprocess.run') as initialize, patch('subprocess.call', side_effect=call): initialize.return_value.returncode = 0 self.assertEqual(xbox['wine']([str(view / 'Bin/Game.exe')]), 0) - self.assertEqual(seen, [(['/selected/proton', 'waitforexitandrun', 'X:\\Bin\\Game.exe'], str(view))]) + self.assertEqual(seen, [(['/selected/proton', 'waitforexitandrun', 'X:\\droiddeck-xbox-1ZpM3D\\Bin\\Game.exe'], str(view.parent))]) self.assertFalse(os.path.lexists(prefix / 'dosdevices/x:')) def test_view_drive_keeps_drives_in_use_and_reuses_a_stale_view(self): @@ -170,8 +170,8 @@ class XboxLaunchTest(unittest.TestCase): (devices / 'w:').symlink_to(root / 'games') (devices / 'v:').symlink_to(views / 'launch-0/droiddeck-xbox-gone') exe, link = xbox['view_drive'](root / 'pfx', str(view / 'Game.exe')) - self.assertEqual((exe, link), ('V:\\Game.exe', devices / 'v:')) - self.assertEqual(os.readlink(devices / 'v:'), str(view)) + self.assertEqual((exe, link), ('V:\\droiddeck-xbox-new\\Game.exe', devices / 'v:')) + self.assertEqual(os.readlink(devices / 'v:'), str(view.parent)) self.assertEqual(os.readlink(devices / 'x:'), str(live)) self.assertEqual(sorted(p.name for p in devices.iterdir()), ['v:', 'w:', 'x:']) self.assertEqual(xbox['view_drive'](root / 'pfx', '/games/Game.exe'), ('/games/Game.exe', None))