diff options
Diffstat (limited to 'src')
6 files changed, 80 insertions, 9 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt index 95b98798d..010c44951 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt | |||
| @@ -548,6 +548,18 @@ object NativeLibrary { | |||
| 548 | external fun getSavePath(programId: String): String | 548 | external fun getSavePath(programId: String): String |
| 549 | 549 | ||
| 550 | /** | 550 | /** |
| 551 | * Adds a file to the manual filesystem provider in our EmulationSession instance | ||
| 552 | * @param path Path to the file we're adding. Can be a string representation of a [Uri] or | ||
| 553 | * a normal path | ||
| 554 | */ | ||
| 555 | external fun addFileToFilesystemProvider(path: String) | ||
| 556 | |||
| 557 | /** | ||
| 558 | * Clears all files added to the manual filesystem provider in our EmulationSession instance | ||
| 559 | */ | ||
| 560 | external fun clearFilesystemProvider() | ||
| 561 | |||
| 562 | /** | ||
| 551 | * Button type for use in onTouchEvent | 563 | * Button type for use in onTouchEvent |
| 552 | */ | 564 | */ |
| 553 | object ButtonType { | 565 | object ButtonType { |
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 55010dc59..579b600f1 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 | |||
| @@ -36,6 +36,12 @@ object GameHelper { | |||
| 36 | // Ensure keys are loaded so that ROM metadata can be decrypted. | 36 | // Ensure keys are loaded so that ROM metadata can be decrypted. |
| 37 | NativeLibrary.reloadKeys() | 37 | NativeLibrary.reloadKeys() |
| 38 | 38 | ||
| 39 | // Reset metadata so we don't use stale information | ||
| 40 | GameMetadata.resetMetadata() | ||
| 41 | |||
| 42 | // Remove previous filesystem provider information so we can get up to date version info | ||
| 43 | NativeLibrary.clearFilesystemProvider() | ||
| 44 | |||
| 39 | val badDirs = mutableListOf<Int>() | 45 | val badDirs = mutableListOf<Int>() |
| 40 | gameDirs.forEachIndexed { index: Int, gameDir: GameDir -> | 46 | gameDirs.forEachIndexed { index: Int, gameDir: GameDir -> |
| 41 | val gameDirUri = Uri.parse(gameDir.uriString) | 47 | val gameDirUri = Uri.parse(gameDir.uriString) |
| @@ -92,14 +98,24 @@ object GameHelper { | |||
| 92 | ) | 98 | ) |
| 93 | } else { | 99 | } else { |
| 94 | if (Game.extensions.contains(FileUtil.getExtension(it.uri))) { | 100 | if (Game.extensions.contains(FileUtil.getExtension(it.uri))) { |
| 95 | games.add(getGame(it.uri, true)) | 101 | val game = getGame(it.uri, true) |
| 102 | if (game != null) { | ||
| 103 | games.add(game) | ||
| 104 | } | ||
| 96 | } | 105 | } |
| 97 | } | 106 | } |
| 98 | } | 107 | } |
| 99 | } | 108 | } |
| 100 | 109 | ||
| 101 | fun getGame(uri: Uri, addedToLibrary: Boolean): Game { | 110 | fun getGame(uri: Uri, addedToLibrary: Boolean): Game? { |
| 102 | val filePath = uri.toString() | 111 | val filePath = uri.toString() |
| 112 | if (!GameMetadata.getIsValid(filePath)) { | ||
| 113 | return null | ||
| 114 | } | ||
| 115 | |||
| 116 | // Needed to update installed content information | ||
| 117 | NativeLibrary.addFileToFilesystemProvider(filePath) | ||
| 118 | |||
| 103 | var name = GameMetadata.getTitle(filePath) | 119 | var name = GameMetadata.getTitle(filePath) |
| 104 | 120 | ||
| 105 | // If the game's title field is empty, use the filename. | 121 | // If the game's title field is empty, use the filename. |
| @@ -118,7 +134,7 @@ object GameHelper { | |||
| 118 | filePath, | 134 | filePath, |
| 119 | programId, | 135 | programId, |
| 120 | GameMetadata.getDeveloper(filePath), | 136 | GameMetadata.getDeveloper(filePath), |
| 121 | GameMetadata.getVersion(filePath), | 137 | GameMetadata.getVersion(filePath, false), |
| 122 | GameMetadata.getIsHomebrew(filePath) | 138 | GameMetadata.getIsHomebrew(filePath) |
| 123 | ) | 139 | ) |
| 124 | 140 | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameMetadata.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameMetadata.kt index 0f3542ac6..8e412482a 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameMetadata.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameMetadata.kt | |||
| @@ -4,13 +4,15 @@ | |||
| 4 | package org.yuzu.yuzu_emu.utils | 4 | package org.yuzu.yuzu_emu.utils |
| 5 | 5 | ||
| 6 | object GameMetadata { | 6 | object GameMetadata { |
| 7 | external fun getIsValid(path: String): Boolean | ||
| 8 | |||
| 7 | external fun getTitle(path: String): String | 9 | external fun getTitle(path: String): String |
| 8 | 10 | ||
| 9 | external fun getProgramId(path: String): String | 11 | external fun getProgramId(path: String): String |
| 10 | 12 | ||
| 11 | external fun getDeveloper(path: String): String | 13 | external fun getDeveloper(path: String): String |
| 12 | 14 | ||
| 13 | external fun getVersion(path: String): String | 15 | external fun getVersion(path: String, reload: Boolean): String |
| 14 | 16 | ||
| 15 | external fun getIcon(path: String): ByteArray | 17 | external fun getIcon(path: String): ByteArray |
| 16 | 18 | ||
diff --git a/src/android/app/src/main/jni/game_metadata.cpp b/src/android/app/src/main/jni/game_metadata.cpp index 24d9df702..78f604c70 100644 --- a/src/android/app/src/main/jni/game_metadata.cpp +++ b/src/android/app/src/main/jni/game_metadata.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <core/core.h> | 4 | #include <core/core.h> |
| 5 | #include <core/file_sys/mode.h> | ||
| 5 | #include <core/file_sys/patch_manager.h> | 6 | #include <core/file_sys/patch_manager.h> |
| 6 | #include <core/loader/nro.h> | 7 | #include <core/loader/nro.h> |
| 7 | #include <jni.h> | 8 | #include <jni.h> |
| @@ -61,7 +62,11 @@ RomMetadata CacheRomMetadata(const std::string& path) { | |||
| 61 | return entry; | 62 | return entry; |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | RomMetadata GetRomMetadata(const std::string& path) { | 65 | RomMetadata GetRomMetadata(const std::string& path, bool reload = false) { |
| 66 | if (reload) { | ||
| 67 | return CacheRomMetadata(path); | ||
| 68 | } | ||
| 69 | |||
| 65 | if (auto search = m_rom_metadata_cache.find(path); search != m_rom_metadata_cache.end()) { | 70 | if (auto search = m_rom_metadata_cache.find(path); search != m_rom_metadata_cache.end()) { |
| 66 | return search->second; | 71 | return search->second; |
| 67 | } | 72 | } |
| @@ -71,6 +76,32 @@ RomMetadata GetRomMetadata(const std::string& path) { | |||
| 71 | 76 | ||
| 72 | extern "C" { | 77 | extern "C" { |
| 73 | 78 | ||
| 79 | jboolean Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getIsValid(JNIEnv* env, jobject obj, | ||
| 80 | jstring jpath) { | ||
| 81 | const auto file = EmulationSession::GetInstance().System().GetFilesystem()->OpenFile( | ||
| 82 | GetJString(env, jpath), FileSys::Mode::Read); | ||
| 83 | if (!file) { | ||
| 84 | return false; | ||
| 85 | } | ||
| 86 | |||
| 87 | auto loader = Loader::GetLoader(EmulationSession::GetInstance().System(), file); | ||
| 88 | if (!loader) { | ||
| 89 | return false; | ||
| 90 | } | ||
| 91 | |||
| 92 | const auto file_type = loader->GetFileType(); | ||
| 93 | if (file_type == Loader::FileType::Unknown || file_type == Loader::FileType::Error) { | ||
| 94 | return false; | ||
| 95 | } | ||
| 96 | |||
| 97 | u64 program_id = 0; | ||
| 98 | Loader::ResultStatus res = loader->ReadProgramId(program_id); | ||
| 99 | if (res != Loader::ResultStatus::Success) { | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | return true; | ||
| 103 | } | ||
| 104 | |||
| 74 | jstring Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getTitle(JNIEnv* env, jobject obj, | 105 | jstring Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getTitle(JNIEnv* env, jobject obj, |
| 75 | jstring jpath) { | 106 | jstring jpath) { |
| 76 | return ToJString(env, GetRomMetadata(GetJString(env, jpath)).title); | 107 | return ToJString(env, GetRomMetadata(GetJString(env, jpath)).title); |
| @@ -87,8 +118,8 @@ jstring Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getDeveloper(JNIEnv* env, job | |||
| 87 | } | 118 | } |
| 88 | 119 | ||
| 89 | jstring Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getVersion(JNIEnv* env, jobject obj, | 120 | jstring Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getVersion(JNIEnv* env, jobject obj, |
| 90 | jstring jpath) { | 121 | jstring jpath, jboolean jreload) { |
| 91 | return ToJString(env, GetRomMetadata(GetJString(env, jpath)).version); | 122 | return ToJString(env, GetRomMetadata(GetJString(env, jpath), jreload).version); |
| 92 | } | 123 | } |
| 93 | 124 | ||
| 94 | jbyteArray Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getIcon(JNIEnv* env, jobject obj, | 125 | jbyteArray Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getIcon(JNIEnv* env, jobject obj, |
| @@ -106,7 +137,7 @@ jboolean Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getIsHomebrew(JNIEnv* env, j | |||
| 106 | } | 137 | } |
| 107 | 138 | ||
| 108 | void Java_org_yuzu_yuzu_1emu_utils_GameMetadata_resetMetadata(JNIEnv* env, jobject obj) { | 139 | void Java_org_yuzu_yuzu_1emu_utils_GameMetadata_resetMetadata(JNIEnv* env, jobject obj) { |
| 109 | return m_rom_metadata_cache.clear(); | 140 | m_rom_metadata_cache.clear(); |
| 110 | } | 141 | } |
| 111 | 142 | ||
| 112 | } // extern "C" | 143 | } // extern "C" |
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index ce570b811..0c1db7d46 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -80,7 +80,7 @@ Core::System& EmulationSession::System() { | |||
| 80 | return m_system; | 80 | return m_system; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | FileSys::ManualContentProvider* EmulationSession::ContentProvider() { | 83 | FileSys::ManualContentProvider* EmulationSession::GetContentProvider() { |
| 84 | return m_manual_provider.get(); | 84 | return m_manual_provider.get(); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| @@ -880,4 +880,13 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject j | |||
| 880 | return ToJString(env, user_save_data_path); | 880 | return ToJString(env, user_save_data_path); |
| 881 | } | 881 | } |
| 882 | 882 | ||
| 883 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_addFileToFilesystemProvider(JNIEnv* env, jobject jobj, | ||
| 884 | jstring jpath) { | ||
| 885 | EmulationSession::GetInstance().ConfigureFilesystemProvider(GetJString(env, jpath)); | ||
| 886 | } | ||
| 887 | |||
| 888 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_clearFilesystemProvider(JNIEnv* env, jobject jobj) { | ||
| 889 | EmulationSession::GetInstance().GetContentProvider()->ClearAllEntries(); | ||
| 890 | } | ||
| 891 | |||
| 883 | } // extern "C" | 892 | } // extern "C" |
diff --git a/src/android/app/src/main/jni/native.h b/src/android/app/src/main/jni/native.h index 96c22d52b..4a8049578 100644 --- a/src/android/app/src/main/jni/native.h +++ b/src/android/app/src/main/jni/native.h | |||
| @@ -21,6 +21,7 @@ public: | |||
| 21 | static EmulationSession& GetInstance(); | 21 | static EmulationSession& GetInstance(); |
| 22 | const Core::System& System() const; | 22 | const Core::System& System() const; |
| 23 | Core::System& System(); | 23 | Core::System& System(); |
| 24 | FileSys::ManualContentProvider* GetContentProvider(); | ||
| 24 | 25 | ||
| 25 | const EmuWindow_Android& Window() const; | 26 | const EmuWindow_Android& Window() const; |
| 26 | EmuWindow_Android& Window(); | 27 | EmuWindow_Android& Window(); |