mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix(frontend): game file export no longer fails before the game library folder exists (#2549)
* fix(frontend): game file export no longer fails before the game library folder exists * fix(frontend): previous automatic library check accepts a library folder not created yet
This commit is contained in:
1 parent
b424bfa353
commit
56fabbdbf0
2 files changed
+53
-2
No files matched your search
@@ -43,11 +43,14 @@ object GameFileSync {
|
||||
val storageSetting = SessionPrefs.gameStorage(context)
|
||||
val previousStorage = prefs(context).getString("storagePath", null)
|
||||
if (storageSetting.isEmpty() && prefs(context).getString("storageSetting", null) == storageSetting && previousStorage != null) {
|
||||
check(File(previousStorage).isDirectory) { context.getString(R.string.game_sync_err_previous_sd) }
|
||||
check(libraryReadable(File(previousStorage))) { context.getString(R.string.game_sync_err_previous_sd) }
|
||||
}
|
||||
storage?.let { check(File(it.path).listFiles() != null) { context.getString(R.string.game_sync_err_game_storage) } }
|
||||
storage?.let { check(libraryReadable(File(it.path))) { context.getString(R.string.game_sync_err_game_storage) } }
|
||||
AddedGames.roots(context).forEach { check(it.host.listFiles() != null) { context.getString(R.string.game_sync_err_added_games) } }
|
||||
GameFiles.sync(context, folder, Library.launchableGames(context, strictRead = true))
|
||||
prefs(context).edit().putString("storageSetting", storageSetting).putString("storagePath", storage?.path).apply()
|
||||
}
|
||||
|
||||
internal fun libraryReadable(dir: File): Boolean =
|
||||
dir.listFiles() != null || (!dir.exists() && dir.parentFile?.isDirectory == true)
|
||||
}
|
||||
@@ -47,4 +47,52 @@ class GameFileSyncTest {
|
||||
assertFalse(File(folder, "Geometry Wars.steam").exists())
|
||||
assertEquals(0, folder.listFiles()!!.count { it.extension == GameFiles.EXTENSION })
|
||||
}
|
||||
|
||||
@Test fun libraryNotCreatedYetOnPresentStorageIsEmptyNotUnavailable() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
listOf("usr/bin/gamescope", LinuxRuntime.SESSION_SCRIPT.removePrefix("/"), "opt/android-host/proot", "opt/android-host/loader").forEach { path ->
|
||||
File(root, path).apply { parentFile!!.mkdirs(); writeText("") }
|
||||
}
|
||||
SessionPrefs.setAddedGamesDirs(context, emptyList())
|
||||
File(root, "root/.local/share/Steam/steamapps").mkdirs()
|
||||
val volume = File(context.filesDir, "card").apply { mkdirs() }
|
||||
val library = File(volume, "steam")
|
||||
SessionPrefs.setGameStorage(context, library.path, "Card")
|
||||
val folder = File(context.filesDir, "exports-card").apply { mkdirs() }
|
||||
GameFileSync.enable(context, folder)
|
||||
assertEquals(folder.path, GameFileSync.folder(context))
|
||||
assertFalse(library.exists())
|
||||
library.writeText("")
|
||||
assertThrows(IllegalStateException::class.java) { GameFileSync.syncConfigured(context) }
|
||||
assertTrue(library.delete())
|
||||
GameFileSync.disable(context)
|
||||
}
|
||||
|
||||
@Test fun libraryReadableOnlyWhenListableOrNotCreatedOnPresentParent() {
|
||||
val base = File(RuntimeEnvironment.getApplication().filesDir, "readable").apply { mkdirs() }
|
||||
assertTrue(GameFileSync.libraryReadable(File(base, "dir").apply { mkdirs() }))
|
||||
assertTrue(GameFileSync.libraryReadable(File(base, "missing")))
|
||||
assertFalse(GameFileSync.libraryReadable(File(base, "gone/steam")))
|
||||
assertFalse(GameFileSync.libraryReadable(File(base, "file").apply { writeText("") }))
|
||||
}
|
||||
|
||||
@Test fun previousAutomaticLibraryNotCreatedYetKeepsSyncingButRemovedDriveStops() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
listOf("usr/bin/gamescope", LinuxRuntime.SESSION_SCRIPT.removePrefix("/"), "opt/android-host/proot", "opt/android-host/loader").forEach { path ->
|
||||
File(root, path).apply { parentFile!!.mkdirs(); writeText("") }
|
||||
}
|
||||
SessionPrefs.setAddedGamesDirs(context, emptyList())
|
||||
SessionPrefs.setGameStorage(context, "", "")
|
||||
File(root, "root/.local/share/Steam/steamapps").mkdirs()
|
||||
val folder = File(context.filesDir, "exports-auto").apply { mkdirs() }
|
||||
val prefs = context.getSharedPreferences("game_files", android.content.Context.MODE_PRIVATE)
|
||||
val volume = File(context.filesDir, "auto-card").apply { mkdirs() }
|
||||
prefs.edit().putString("storageSetting", "").putString("storagePath", File(volume, "steam").path).apply()
|
||||
GameFileSync.enable(context, folder)
|
||||
prefs.edit().putString("storageSetting", "").putString("storagePath", File(context.filesDir, "removed-card/steam").path).apply()
|
||||
assertThrows(IllegalStateException::class.java) { GameFileSync.syncConfigured(context) }
|
||||
GameFileSync.disable(context)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user