mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
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:
1 parent
906e60a042
commit
5971b91ed4
5 files changed
+106
-13
No files matched your search
@@ -48,7 +48,33 @@ object GameStorage {
|
||||
return when {
|
||||
pref == SessionPrefs.GAME_STORAGE_OFF -> null
|
||||
pref.isEmpty() -> options(context).firstOrNull()?.let { Option(it.name, it.path) }
|
||||
else -> Option(SessionPrefs.gameStorageLabel(context), pref)
|
||||
else -> Option(SessionPrefs.gameStorageLabel(context), pref).takeIf { attached(File(pref)) }
|
||||
}
|
||||
}
|
||||
|
||||
fun disconnected(context: Context): Boolean {
|
||||
val pref = SessionPrefs.gameStorage(context)
|
||||
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(pref))
|
||||
}
|
||||
|
||||
internal fun attached(path: File): Boolean =
|
||||
attached(path, runCatching { Environment.getExternalStorageState(path) }.getOrNull())
|
||||
|
||||
internal fun attached(
|
||||
path: File,
|
||||
state: String?,
|
||||
externalStoragePath: Boolean = isExternalStoragePath(path),
|
||||
): Boolean = when {
|
||||
state == Environment.MEDIA_MOUNTED || state == Environment.MEDIA_MOUNTED_READ_ONLY -> true
|
||||
externalStoragePath -> false
|
||||
state == Environment.MEDIA_UNKNOWN || state == null -> path.isDirectory || path.parentFile?.isDirectory == true
|
||||
else -> false
|
||||
}
|
||||
|
||||
private fun isExternalStoragePath(path: File): Boolean {
|
||||
val absolute = path.absoluteFile.toPath().normalize()
|
||||
return listOf(File("/storage"), File("/mnt/media_rw")).any {
|
||||
absolute.startsWith(it.absoluteFile.toPath().normalize())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,20 +97,25 @@ object StoreInstallRoot {
|
||||
|
||||
fun installRoot(context: Context): File = internalRoot(context)
|
||||
|
||||
fun externalTarget(context: Context): Target? =
|
||||
if (SessionPrefs.defaultStorageFolder(context).isNotBlank()) customTarget(context)
|
||||
else detectedExternalTarget(context)
|
||||
fun externalTarget(context: Context): Target? = when {
|
||||
SessionPrefs.defaultStorageFolder(context).isNotBlank() -> customTarget(context)
|
||||
GameStorage.disconnected(context) -> null
|
||||
else -> detectedExternalTarget(context)
|
||||
}
|
||||
|
||||
internal fun externalTarget(targets: List<Target>, internalRoot: File): Target? =
|
||||
targets.firstOrNull { it.folder && it.root.absolutePath != internalRoot.absolutePath }
|
||||
?: targets.firstOrNull { it.removable && it.root.absolutePath != internalRoot.absolutePath }
|
||||
|
||||
fun defaultTarget(context: Context): Target? = when (SessionPrefs.defaultStorage(context)) {
|
||||
SessionPrefs.DEFAULT_STORAGE_INTERNAL -> Target(internalRoot(context), context.getString(com.droiddeck.launcher.R.string.games_internal), removable = false)
|
||||
SessionPrefs.DEFAULT_STORAGE_EXTERNAL -> externalTarget(context)
|
||||
SessionPrefs.DEFAULT_STORAGE_INTERNAL -> internalTarget(context)
|
||||
SessionPrefs.DEFAULT_STORAGE_EXTERNAL -> externalTarget(context) ?: internalTarget(context)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun internalTarget(context: Context) =
|
||||
Target(internalRoot(context), context.getString(com.droiddeck.launcher.R.string.games_internal), removable = false)
|
||||
|
||||
fun libraryRoot(context: Context): File? = GameStorage.effective(context)?.let { File(it.path, ON_VOLUME) }
|
||||
|
||||
fun roots(context: Context): List<File> {
|
||||
|
||||
Reference in new issue
Block a user