diff options
Diffstat (limited to 'src/android/app')
8 files changed, 114 insertions, 79 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 b7556e353..8cb98d6d7 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 @@ -21,6 +21,7 @@ import org.yuzu.yuzu_emu.utils.DocumentsTree import org.yuzu.yuzu_emu.utils.FileUtil import org.yuzu.yuzu_emu.utils.Log import org.yuzu.yuzu_emu.utils.SerializableHelper.serializable +import org.yuzu.yuzu_emu.model.InstallResult /** * Class which contains methods that interact @@ -235,9 +236,12 @@ object NativeLibrary { /** * Installs a nsp or xci file to nand * @param filename String representation of file uri - * @param extension Lowercase string representation of file extension without "." + * @return int representation of [InstallResult] */ - external fun installFileToNand(filename: String, extension: String): Int + external fun installFileToNand( + filename: String, + callback: (max: Long, progress: Long) -> Boolean + ): Int external fun doesUpdateMatchProgram(programId: String, updatePath: String): Boolean @@ -609,15 +613,4 @@ object NativeLibrary { const val RELEASED = 0 const val PRESSED = 1 } - - /** - * Result from installFileToNand - */ - object InstallFileToNandResult { - const val Success = 0 - const val SuccessFileOverwritten = 1 - const val Error = 2 - const val ErrorBaseGame = 3 - const val ErrorFilenameExtension = 4 - } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/InstallResult.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/InstallResult.kt new file mode 100644 index 000000000..0c3cd0521 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/InstallResult.kt @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.model + +enum class InstallResult(val int: Int) { + Success(0), + Overwrite(1), + Failure(2), + BaseInstallAttempted(3); + + companion object { + fun from(int: Int): InstallResult = entries.firstOrNull { it.int == int } ?: Success + } +} diff --git a/src/android/app/src/main/jni/android_common/android_common.cpp b/src/android/app/src/main/jni/android_common/android_common.cpp index 1e884ffdd..7018a52af 100644 --- a/src/android/app/src/main/jni/android_common/android_common.cpp +++ b/src/android/app/src/main/jni/android_common/android_common.cpp @@ -42,3 +42,19 @@ double GetJDouble(JNIEnv* env, jobject jdouble) { jobject ToJDouble(JNIEnv* env, double value) { return env->NewObject(IDCache::GetDoubleClass(), IDCache::GetDoubleConstructor(), value); } + +s32 GetJInteger(JNIEnv* env, jobject jinteger) { + return env->GetIntField(jinteger, IDCache::GetIntegerValueField()); +} + +jobject ToJInteger(JNIEnv* env, s32 value) { + return env->NewObject(IDCache::GetIntegerClass(), IDCache::GetIntegerConstructor(), value); +} + +bool GetJBoolean(JNIEnv* env, jobject jboolean) { + return env->GetBooleanField(jboolean, IDCache::GetBooleanValueField()); +} + +jobject ToJBoolean(JNIEnv* env, bool value) { + return env->NewObject(IDCache::GetBooleanClass(), IDCache::GetBooleanConstructor(), value); +} diff --git a/src/android/app/src/main/jni/android_common/android_common.h b/src/android/app/src/main/jni/android_common/android_common.h index 8eb803e1b..29a338c0a 100644 --- a/src/android/app/src/main/jni/android_common/android_common.h +++ b/src/android/app/src/main/jni/android_common/android_common.h @@ -6,6 +6,7 @@ #include <string> #include <jni.h> +#include "common/common_types.h" std::string GetJString(JNIEnv* env, jstring jstr); jstring ToJString(JNIEnv* env, std::string_view str); @@ -13,3 +14,9 @@ jstring ToJString(JNIEnv* env, std::u16string_view str); double GetJDouble(JNIEnv* env, jobject jdouble); jobject ToJDouble(JNIEnv* env, double value); + +s32 GetJInteger(JNIEnv* env, jobject jinteger); +jobject ToJInteger(JNIEnv* env, s32 value); + +bool GetJBoolean(JNIEnv* env, jobject jboolean); +jobject ToJBoolean(JNIEnv* env, bool value); diff --git a/src/android/app/src/main/jni/id_cache.cpp b/src/android/app/src/main/jni/id_cache.cpp index c79ad7d76..19ced175f 100644 --- a/src/android/app/src/main/jni/id_cache.cpp +++ b/src/android/app/src/main/jni/id_cache.cpp @@ -47,6 +47,14 @@ static jclass s_double_class; static jmethodID s_double_constructor; static jfieldID s_double_value_field; +static jclass s_integer_class; +static jmethodID s_integer_constructor; +static jfieldID s_integer_value_field; + +static jclass s_boolean_class; +static jmethodID s_boolean_constructor; +static jfieldID s_boolean_value_field; + static constexpr jint JNI_VERSION = JNI_VERSION_1_6; namespace IDCache { @@ -198,6 +206,30 @@ jfieldID GetDoubleValueField() { return s_double_value_field; } +jclass GetIntegerClass() { + return s_integer_class; +} + +jmethodID GetIntegerConstructor() { + return s_integer_constructor; +} + +jfieldID GetIntegerValueField() { + return s_integer_value_field; +} + +jclass GetBooleanClass() { + return s_boolean_class; +} + +jmethodID GetBooleanConstructor() { + return s_boolean_constructor; +} + +jfieldID GetBooleanValueField() { + return s_boolean_value_field; +} + } // namespace IDCache #ifdef __cplusplus @@ -284,6 +316,18 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) { s_double_value_field = env->GetFieldID(double_class, "value", "D"); env->DeleteLocalRef(double_class); + const jclass int_class = env->FindClass("java/lang/Integer"); + s_integer_class = reinterpret_cast<jclass>(env->NewGlobalRef(int_class)); + s_integer_constructor = env->GetMethodID(int_class, "<init>", "(I)V"); + s_integer_value_field = env->GetFieldID(int_class, "value", "I"); + env->DeleteLocalRef(int_class); + + const jclass boolean_class = env->FindClass("java/lang/Boolean"); + s_boolean_class = reinterpret_cast<jclass>(env->NewGlobalRef(boolean_class)); + s_boolean_constructor = env->GetMethodID(boolean_class, "<init>", "(Z)V"); + s_boolean_value_field = env->GetFieldID(boolean_class, "value", "Z"); + env->DeleteLocalRef(boolean_class); + // Initialize Android Storage Common::FS::Android::RegisterCallbacks(env, s_native_library_class); @@ -310,6 +354,8 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) { env->DeleteGlobalRef(s_pair_class); env->DeleteGlobalRef(s_overlay_control_data_class); env->DeleteGlobalRef(s_double_class); + env->DeleteGlobalRef(s_integer_class); + env->DeleteGlobalRef(s_boolean_class); // UnInitialize applets SoftwareKeyboard::CleanupJNI(env); diff --git a/src/android/app/src/main/jni/id_cache.h b/src/android/app/src/main/jni/id_cache.h index 784d1412f..0e5267b73 100644 --- a/src/android/app/src/main/jni/id_cache.h +++ b/src/android/app/src/main/jni/id_cache.h @@ -47,4 +47,12 @@ jclass GetDoubleClass(); jmethodID GetDoubleConstructor(); jfieldID GetDoubleValueField(); +jclass GetIntegerClass(); +jmethodID GetIntegerConstructor(); +jfieldID GetIntegerValueField(); + +jclass GetBooleanClass(); +jmethodID GetBooleanConstructor(); +jfieldID GetBooleanValueField(); + } // namespace IDCache diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index ed3b1353a..b8fef5c6f 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -17,6 +17,7 @@ #include <core/file_sys/patch_manager.h> #include <core/file_sys/savedata_factory.h> #include <core/loader/nro.h> +#include <frontend_common/content_manager.h> #include <jni.h> #include "common/detached_tasks.h" @@ -100,67 +101,6 @@ void EmulationSession::SetNativeWindow(ANativeWindow* native_window) { m_native_window = native_window; } -int EmulationSession::InstallFileToNand(std::string filename, std::string file_extension) { - jconst copy_func = [](const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest, - std::size_t block_size) { - if (src == nullptr || dest == nullptr) { - return false; - } - if (!dest->Resize(src->GetSize())) { - return false; - } - - using namespace Common::Literals; - [[maybe_unused]] std::vector<u8> buffer(1_MiB); - - for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - jconst read = src->Read(buffer.data(), buffer.size(), i); - dest->Write(buffer.data(), read, i); - } - return true; - }; - - enum InstallResult { - Success = 0, - SuccessFileOverwritten = 1, - InstallError = 2, - ErrorBaseGame = 3, - ErrorFilenameExtension = 4, - }; - - [[maybe_unused]] std::shared_ptr<FileSys::NSP> nsp; - if (file_extension == "nsp") { - nsp = std::make_shared<FileSys::NSP>(m_vfs->OpenFile(filename, FileSys::Mode::Read)); - if (nsp->IsExtractedType()) { - return InstallError; - } - } else { - return ErrorFilenameExtension; - } - - if (!nsp) { - return InstallError; - } - - if (nsp->GetStatus() != Loader::ResultStatus::Success) { - return InstallError; - } - - jconst res = m_system.GetFileSystemController().GetUserNANDContents()->InstallEntry(*nsp, true, - copy_func); - - switch (res) { - case FileSys::InstallResult::Success: - return Success; - case FileSys::InstallResult::OverwriteExisting: - return SuccessFileOverwritten; - case FileSys::InstallResult::ErrorBaseInstall: - return ErrorBaseGame; - default: - return InstallError; - } -} - void EmulationSession::InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir, const std::string& custom_driver_name, @@ -512,10 +452,20 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_setAppDirectory(JNIEnv* env, jobject } int Java_org_yuzu_yuzu_1emu_NativeLibrary_installFileToNand(JNIEnv* env, jobject instance, - jstring j_file, - jstring j_file_extension) { - return EmulationSession::GetInstance().InstallFileToNand(GetJString(env, j_file), - GetJString(env, j_file_extension)); + jstring j_file, jobject jcallback) { + auto jlambdaClass = env->GetObjectClass(jcallback); + auto jlambdaInvokeMethod = env->GetMethodID( + jlambdaClass, "invoke", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + const auto callback = [env, jcallback, jlambdaInvokeMethod](size_t max, size_t progress) { + auto jwasCancelled = env->CallObjectMethod(jcallback, jlambdaInvokeMethod, + ToJDouble(env, max), ToJDouble(env, progress)); + return GetJBoolean(env, jwasCancelled); + }; + + return static_cast<int>( + ContentManager::InstallNSP(&EmulationSession::GetInstance().System(), + EmulationSession::GetInstance().System().GetFilesystem().get(), + GetJString(env, j_file), callback)); } jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_doesUpdateMatchProgram(JNIEnv* env, jobject jobj, diff --git a/src/android/app/src/main/jni/native.h b/src/android/app/src/main/jni/native.h index 4a8049578..dadb138ad 100644 --- a/src/android/app/src/main/jni/native.h +++ b/src/android/app/src/main/jni/native.h @@ -7,6 +7,7 @@ #include "core/file_sys/registered_cache.h" #include "core/hle/service/acc/profile_manager.h" #include "core/perf_stats.h" +#include "frontend_common/content_manager.h" #include "jni/applets/software_keyboard.h" #include "jni/emu_window/emu_window.h" #include "video_core/rasterizer_interface.h" @@ -29,7 +30,6 @@ public: void SetNativeWindow(ANativeWindow* native_window); void SurfaceChanged(); - int InstallFileToNand(std::string filename, std::string file_extension); void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir, const std::string& custom_driver_name, const std::string& file_redirect_dir); |