From 5dbf842a46a68de87471c3f8e265f284ebc2c362 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Mon, 22 May 2023 18:32:18 -0400 Subject: android: Improve missing game handling Previously the app would crash if you selected a game that no longer existed. Now we show an error message and reload the games list to remove any invalid games from the list. --- .../java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt | 19 ++++++++++++++++++- src/android/app/src/main/res/values/strings.xml | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/android/app') diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt index a9653475f..7f9e2e2d4 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt @@ -3,15 +3,18 @@ package org.yuzu.yuzu_emu.adapters -import android.annotation.SuppressLint import android.graphics.Bitmap import android.graphics.BitmapFactory +import android.net.Uri import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.documentfile.provider.DocumentFile +import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager import androidx.recyclerview.widget.AsyncDifferConfig @@ -27,6 +30,7 @@ import org.yuzu.yuzu_emu.databinding.CardGameBinding import org.yuzu.yuzu_emu.activities.EmulationActivity import org.yuzu.yuzu_emu.model.Game import org.yuzu.yuzu_emu.adapters.GameAdapter.GameViewHolder +import org.yuzu.yuzu_emu.model.GamesViewModel class GameAdapter(private val activity: AppCompatActivity) : ListAdapter(AsyncDifferConfig.Builder(DiffCallback()).build()), @@ -53,6 +57,19 @@ class GameAdapter(private val activity: AppCompatActivity) : */ override fun onClick(view: View) { val holder = view.tag as GameViewHolder + + val gameExists = DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(holder.game.path))?.exists() == true + if (!gameExists) { + Toast.makeText( + YuzuApplication.appContext, + R.string.loader_error_file_not_found, + Toast.LENGTH_LONG + ).show() + + ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true) + return + } + val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) preferences.edit() .putLong( diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index e171cf799..03a5ffc7e 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -177,6 +177,7 @@ An error occurred initializing the video core This is usually caused by an incompatible GPU driver. Installing a custom GPU driver may resolve this problem. Unable to load ROM + ROM file does not exist Exit Emulation -- cgit v1.2.3