From bafd4d344f455c4f4a790a73766b9beaecd6a2f0 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Thu, 11 May 2023 16:57:13 -0400 Subject: android: Check if cached games are valid Fixes bug when you close yuzu, delete games, and reopen to an instant crash. --- .../src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 5a35b14c9..d4de7a09a 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 @@ -3,6 +3,8 @@ package org.yuzu.yuzu_emu.model +import android.net.Uri +import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -44,7 +46,13 @@ class GamesViewModel : ViewModel() { if (storedGames!!.isNotEmpty()) { val deserializedGames = mutableSetOf() storedGames.forEach { - deserializedGames.add(Json.decodeFromString(it)) + val game: Game = Json.decodeFromString(it) + val gameExists = + DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(game.path)) + ?.exists() + if (gameExists == true) { + deserializedGames.add(game) + } } setGames(deserializedGames.toList()) } -- cgit v1.2.3