summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
index 6e09fa81d..004b25b04 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
@@ -49,26 +49,33 @@ class GamesViewModel : ViewModel() {
49 // Retrieve list of cached games 49 // Retrieve list of cached games
50 val storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) 50 val storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
51 .getStringSet(GameHelper.KEY_GAMES, emptySet()) 51 .getStringSet(GameHelper.KEY_GAMES, emptySet())
52 if (storedGames!!.isNotEmpty()) {
53 val deserializedGames = mutableSetOf<Game>()
54 storedGames.forEach {
55 val game: Game
56 try {
57 game = Json.decodeFromString(it)
58 } catch (e: MissingFieldException) {
59 return@forEach
60 }
61 52
62 val gameExists = 53 viewModelScope.launch {
63 DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(game.path)) 54 withContext(Dispatchers.IO) {
64 ?.exists() 55 if (storedGames!!.isNotEmpty()) {
65 if (gameExists == true) { 56 val deserializedGames = mutableSetOf<Game>()
66 deserializedGames.add(game) 57 storedGames.forEach {
58 val game: Game
59 try {
60 game = Json.decodeFromString(it)
61 } catch (e: MissingFieldException) {
62 return@forEach
63 }
64
65 val gameExists =
66 DocumentFile.fromSingleUri(
67 YuzuApplication.appContext,
68 Uri.parse(game.path)
69 )?.exists()
70 if (gameExists == true) {
71 deserializedGames.add(game)
72 }
73 }
74 setGames(deserializedGames.toList())
67 } 75 }
76 reloadGames(false)
68 } 77 }
69 setGames(deserializedGames.toList())
70 } 78 }
71 reloadGames(false)
72 } 79 }
73 80
74 fun setGames(games: List<Game>) { 81 fun setGames(games: List<Game>) {