diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt index f8e7eeca7..f71d0a098 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt | |||
| @@ -11,6 +11,7 @@ import kotlinx.serialization.json.Json | |||
| 11 | import org.yuzu.yuzu_emu.NativeLibrary | 11 | import org.yuzu.yuzu_emu.NativeLibrary |
| 12 | import org.yuzu.yuzu_emu.YuzuApplication | 12 | import org.yuzu.yuzu_emu.YuzuApplication |
| 13 | import org.yuzu.yuzu_emu.model.Game | 13 | import org.yuzu.yuzu_emu.model.Game |
| 14 | import org.yuzu.yuzu_emu.model.MinimalDocumentFile | ||
| 14 | 15 | ||
| 15 | object GameHelper { | 16 | object GameHelper { |
| 16 | const val KEY_GAME_PATH = "game_path" | 17 | const val KEY_GAME_PATH = "game_path" |
| @@ -29,15 +30,7 @@ object GameHelper { | |||
| 29 | // Ensure keys are loaded so that ROM metadata can be decrypted. | 30 | // Ensure keys are loaded so that ROM metadata can be decrypted. |
| 30 | NativeLibrary.reloadKeys() | 31 | NativeLibrary.reloadKeys() |
| 31 | 32 | ||
| 32 | val children = FileUtil.listFiles(context, gamesUri) | 33 | addGamesRecursive(games, FileUtil.listFiles(context, gamesUri), 3) |
| 33 | for (file in children) { | ||
| 34 | if (!file.isDirectory) { | ||
| 35 | // Check that the file has an extension we care about before trying to read out of it. | ||
| 36 | if (Game.extensions.contains(FileUtil.getExtension(file.uri))) { | ||
| 37 | games.add(getGame(file.uri)) | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | 34 | ||
| 42 | // Cache list of games found on disk | 35 | // Cache list of games found on disk |
| 43 | val serializedGames = mutableSetOf<String>() | 36 | val serializedGames = mutableSetOf<String>() |
| @@ -52,6 +45,30 @@ object GameHelper { | |||
| 52 | return games.toList() | 45 | return games.toList() |
| 53 | } | 46 | } |
| 54 | 47 | ||
| 48 | private fun addGamesRecursive( | ||
| 49 | games: MutableList<Game>, | ||
| 50 | files: Array<MinimalDocumentFile>, | ||
| 51 | depth: Int | ||
| 52 | ) { | ||
| 53 | if (depth <= 0) { | ||
| 54 | return | ||
| 55 | } | ||
| 56 | |||
| 57 | files.forEach { | ||
| 58 | if (it.isDirectory) { | ||
| 59 | addGamesRecursive( | ||
| 60 | games, | ||
| 61 | FileUtil.listFiles(YuzuApplication.appContext, it.uri), | ||
| 62 | depth - 1 | ||
| 63 | ) | ||
| 64 | } else { | ||
| 65 | if (Game.extensions.contains(FileUtil.getExtension(it.uri))) { | ||
| 66 | games.add(getGame(it.uri)) | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 55 | private fun getGame(uri: Uri): Game { | 72 | private fun getGame(uri: Uri): Game { |
| 56 | val filePath = uri.toString() | 73 | val filePath = uri.toString() |
| 57 | var name = NativeLibrary.getTitle(filePath) | 74 | var name = NativeLibrary.getTitle(filePath) |