fix: an unplugged game drive falls back to internal storage (#1913)

* fix: an unplugged game drive falls back to internal storage

When the drive chosen for game storage is not connected, installs, sessions and the install picker use internal storage instead of failing with "Game storage is unavailable". The saved drive is kept and used again once it is plugged back in.

* fix: store installs set to external use internal storage while the drive is unplugged

With default storage set to external, a missing drive or folder no longer stops installs at the location dialog or leaves the Epic launcher pointing at it. Installs go to internal storage and switch back to the drive once it is connected again.

* fix: external installs do not move to another card while the saved drive is unplugged

* fix(storage): verify saved volume is mounted

* fix(storage): reject unknown external volumes

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
MaxsTechReviewandKurt Himebauch authored and GitHub committed 2026-11-05 18:33:38 -05:00
1 parent 906e60a042
commit 5971b91ed4
5 files changed
+106 -13

No files matched your search

@@ -1,5 +1,6 @@
package com.droiddeck.launcher.session
import android.os.Environment
import com.droiddeck.launcher.frontend.AddedGames
import java.io.File
import org.junit.Assert.*
@@ -48,4 +49,46 @@ class GameStorageTest {
SessionPrefs.setAddedGamesDirs(app, odd.map { it.path })
assertTrue(GameStorage.gamesFolderLibraries(app).isEmpty())
}
@Test fun anUnpluggedDriveFallsBackToInternalWithoutForgettingIt() {
val gone = "/storage/0000-0000/Android/data/com.droiddeck.launcher/files/steam"
SessionPrefs.setGameStorage(app, gone, "USB drive")
assertNull(GameStorage.effective(app))
assertNull(GameStorage.x64CardLibrary(app))
assertEquals(gone, SessionPrefs.gameStorage(app))
}
@Test fun aPluggedInDriveStaysTheLibrary() {
val files = tmp.newFolder("files")
val steam = File(files, "steam")
SessionPrefs.setGameStorage(app, steam.path, "USB drive")
assertEquals(steam.path, GameStorage.effective(app)?.path)
steam.mkdirs()
assertEquals(steam.path, GameStorage.effective(app)?.path)
assertEquals("USB drive", GameStorage.effective(app)?.label)
}
@Test fun missingSubfolderIsAttachedWhenItsVolumeIsMounted() {
val path = File(tmp.newFolder("mounted-volume"), "missing/steam")
assertTrue(GameStorage.attached(path, Environment.MEDIA_MOUNTED, externalStoragePath = true))
}
@Test fun removedVolumeIsNotAttachedEvenWhenItsParentExists() {
val parent = tmp.newFolder("storage")
val volume = File(parent, "0000-0000")
assertTrue(parent.isDirectory)
assertFalse(GameStorage.attached(volume, Environment.MEDIA_REMOVED, externalStoragePath = true))
assertFalse(GameStorage.attached(volume, Environment.MEDIA_UNKNOWN, externalStoragePath = true))
}
@Test fun onlyASavedDriveThatIsMissingCountsAsDisconnected() {
SessionPrefs.setGameStorage(app, "", "")
assertFalse(GameStorage.disconnected(app))
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
assertFalse(GameStorage.disconnected(app))
SessionPrefs.setGameStorage(app, "/storage/0000-0000/Android/data/com.droiddeck.launcher/files/steam", "USB drive")
assertTrue(GameStorage.disconnected(app))
SessionPrefs.setGameStorage(app, tmp.newFolder("plugged").path, "USB drive")
assertFalse(GameStorage.disconnected(app))
}
}
@@ -53,10 +53,10 @@ class StoreInstallRootTest {
assertEquals(SessionPrefs.DEFAULT_STORAGE_ASK, SessionPrefs.defaultStorage(app))
}
@Test fun defaultExternalStorageFallsBackToTheInstallDialogWhenNoCardIsPresent() {
@Test fun defaultExternalStorageFallsBackToInternalWhenNoCardIsPresent() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
SessionPrefs.setDefaultStorage(app, SessionPrefs.DEFAULT_STORAGE_EXTERNAL)
assertNull(StoreInstallRoot.defaultTarget(app))
assertEquals(StoreInstallRoot.internalRoot(app).absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath)
}
@Test fun aChosenFolderIsUsedForDefaultExternalStorage() {
@@ -74,7 +74,7 @@ class StoreInstallRootTest {
assertFalse(File(root, ".droiddeck-write-probe").exists())
}
@Test fun aDisconnectedChosenFolderDoesNotFallBackToAnotherTarget() {
@Test fun aDisconnectedChosenFolderFallsBackToInternalUntilItIsBack() {
val card = File(app.filesDir, "card/steam").apply { mkdirs() }
SessionPrefs.setGameStorage(app, card.path, "Card")
val folder = File(app.filesDir, "usb/SSD").apply { mkdirs() }
@@ -83,8 +83,11 @@ class StoreInstallRootTest {
assertNotNull(StoreInstallRoot.defaultTarget(app))
assertTrue(folder.delete())
assertNull(StoreInstallRoot.defaultTarget(app))
assertEquals(StoreInstallRoot.internalRoot(app).absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath)
assertEquals(File(card, "Games").absolutePath, StoreInstallRoot.detectedExternalTarget(app)?.root?.absolutePath)
assertTrue(folder.mkdirs())
assertEquals(File(folder, "Games").absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath)
}
@Test fun filesOnAChosenFolderAreMappedIntoTheGuest() {
@@ -303,4 +306,20 @@ class StoreInstallRootTest {
assertEquals("itch", StoreInstallRoot.storeDir(File("/games"), Store.ITCH).name)
assertEquals("Game Jolt", StoreInstallRoot.storeDir(File("/games"), Store.GAMEJOLT).name)
}
@Test fun anUnpluggedLibraryDriveSendsInstallsToInternalUntilItIsBack() {
val files = File(app.filesDir, "usb-drive/files")
val library = File(files, "steam")
SessionPrefs.setGameStorage(app, library.path, "USB drive")
SessionPrefs.setDefaultStorage(app, SessionPrefs.DEFAULT_STORAGE_EXTERNAL)
val internal = StoreInstallRoot.internalRoot(app).absolutePath
assertEquals(internal, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath)
assertEquals(listOf(internal), StoreInstallRoot.targets(app).map { it.root.absolutePath })
assertNull(StoreInstallRoot.libraryRoot(app))
library.mkdirs()
assertEquals(File(library, "Games").absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath)
assertEquals(File(library, "Games").absolutePath, StoreInstallRoot.libraryRoot(app)?.absolutePath)
}
}
@@ -457,7 +457,7 @@ class EpicClientTest {
assertEquals("/root/Games/Stores/Epic", EpicClient.prepareInstallDir(context))
}
@Test fun aDisconnectedDefaultFolderKeepsTheLauncherInstallDir() {
@Test fun aDisconnectedDefaultFolderMovesTheLauncherInstallDirToInternal() {
val context = org.robolectric.RuntimeEnvironment.getApplication()
val previousStorage = com.droiddeck.launcher.session.SessionPrefs.defaultStorage(context)
val previousFolder = com.droiddeck.launcher.session.SessionPrefs.defaultStorageFolder(context)
@@ -470,8 +470,8 @@ class EpicClientTest {
com.droiddeck.launcher.session.SessionPrefs.setDefaultStorageFolder(
context, File(context.filesDir, "missing-${System.nanoTime()}").path, "SSD")
try {
assertEquals(current, EpicClient.prepareInstallDir(context))
assertEquals(current, org.json.JSONObject(settings.readText()).getString("defaultInstallDir"))
assertEquals("/root/Games/Stores/Epic", EpicClient.prepareInstallDir(context))
assertEquals("/root/Games/Stores/Epic", org.json.JSONObject(settings.readText()).getString("defaultInstallDir"))
} finally {
com.droiddeck.launcher.session.SessionPrefs.setDefaultStorage(context, previousStorage)
if (previousFolder.isBlank()) com.droiddeck.launcher.session.SessionPrefs.clearDefaultStorageFolder(context)