From c89828b22ecdf5b8e36741ced7bad9bd2af54076 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 6 Jul 2020 17:02:01 +0200 Subject: [PATCH] Android: Convert some files to LF I wonder why lint didn't catch this... --- .../jni/AndroidCommon/AndroidCommon.cpp | 78 +-- .../Android/jni/AndroidCommon/AndroidCommon.h | 26 +- Source/Android/jni/AndroidCommon/IDCache.cpp | 340 ++++++------- Source/Android/jni/AndroidCommon/IDCache.h | 62 +-- Source/Android/jni/GameList/GameFile.cpp | 448 +++++++++--------- Source/Android/jni/GameList/GameFile.h | 34 +- Source/Android/jni/GameList/GameFileCache.cpp | 244 +++++----- 7 files changed, 616 insertions(+), 616 deletions(-) diff --git a/Source/Android/jni/AndroidCommon/AndroidCommon.cpp b/Source/Android/jni/AndroidCommon/AndroidCommon.cpp index 04e34c0f21..cb7b9ff073 100644 --- a/Source/Android/jni/AndroidCommon/AndroidCommon.cpp +++ b/Source/Android/jni/AndroidCommon/AndroidCommon.cpp @@ -1,39 +1,39 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include "jni/AndroidCommon/AndroidCommon.h" - -#include -#include - -#include - -std::string GetJString(JNIEnv* env, jstring jstr) -{ - std::string result = ""; - if (!jstr) - return result; - - const char* s = env->GetStringUTFChars(jstr, nullptr); - result = s; - env->ReleaseStringUTFChars(jstr, s); - return result; -} - -jstring ToJString(JNIEnv* env, const std::string& str) -{ - return env->NewStringUTF(str.c_str()); -} - -std::vector JStringArrayToVector(JNIEnv* env, jobjectArray array) -{ - const jsize size = env->GetArrayLength(array); - std::vector result; - result.reserve(size); - - for (jsize i = 0; i < size; ++i) - result.push_back(GetJString(env, (jstring)env->GetObjectArrayElement(array, i))); - - return result; -} +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "jni/AndroidCommon/AndroidCommon.h" + +#include +#include + +#include + +std::string GetJString(JNIEnv* env, jstring jstr) +{ + std::string result = ""; + if (!jstr) + return result; + + const char* s = env->GetStringUTFChars(jstr, nullptr); + result = s; + env->ReleaseStringUTFChars(jstr, s); + return result; +} + +jstring ToJString(JNIEnv* env, const std::string& str) +{ + return env->NewStringUTF(str.c_str()); +} + +std::vector JStringArrayToVector(JNIEnv* env, jobjectArray array) +{ + const jsize size = env->GetArrayLength(array); + std::vector result; + result.reserve(size); + + for (jsize i = 0; i < size; ++i) + result.push_back(GetJString(env, (jstring)env->GetObjectArrayElement(array, i))); + + return result; +} diff --git a/Source/Android/jni/AndroidCommon/AndroidCommon.h b/Source/Android/jni/AndroidCommon/AndroidCommon.h index 7b7d1bfc6b..e60678a3e8 100644 --- a/Source/Android/jni/AndroidCommon/AndroidCommon.h +++ b/Source/Android/jni/AndroidCommon/AndroidCommon.h @@ -1,13 +1,13 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include - -#include - -std::string GetJString(JNIEnv* env, jstring jstr); -jstring ToJString(JNIEnv* env, const std::string& str); -std::vector JStringArrayToVector(JNIEnv* env, jobjectArray array); +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include + +std::string GetJString(JNIEnv* env, jstring jstr); +jstring ToJString(JNIEnv* env, const std::string& str); +std::vector JStringArrayToVector(JNIEnv* env, jobjectArray array); diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index 19b7147ba4..01f76f344a 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -1,170 +1,170 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include "jni/AndroidCommon/IDCache.h" - -#include - -static constexpr jint JNI_VERSION = JNI_VERSION_1_6; - -static JavaVM* s_java_vm; - -static jclass s_native_library_class; -static jmethodID s_display_alert_msg; -static jmethodID s_get_update_touch_pointer; - -static jclass s_game_file_class; -static jfieldID s_game_file_pointer; -static jmethodID s_game_file_constructor; - -static jclass s_game_file_cache_class; -static jfieldID s_game_file_cache_pointer; - -static jclass s_analytics_class; -static jmethodID s_send_analytics_report; -static jmethodID s_get_analytics_value; - -static jmethodID s_do_rumble; - -namespace IDCache -{ -JNIEnv* GetEnvForThread() -{ - thread_local static struct OwnedEnv - { - OwnedEnv() - { - status = s_java_vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); - if (status == JNI_EDETACHED) - s_java_vm->AttachCurrentThread(&env, nullptr); - } - - ~OwnedEnv() - { - if (status == JNI_EDETACHED) - s_java_vm->DetachCurrentThread(); - } - - int status; - JNIEnv* env = nullptr; - } owned; - return owned.env; -} - -jclass GetNativeLibraryClass() -{ - return s_native_library_class; -} - -jmethodID GetDisplayAlertMsg() -{ - return s_display_alert_msg; -} - -jmethodID GetUpdateTouchPointer() -{ - return s_get_update_touch_pointer; -} - -jclass GetAnalyticsClass() -{ - return s_analytics_class; -} - -jmethodID GetSendAnalyticsReport() -{ - return s_send_analytics_report; -} - -jmethodID GetAnalyticsValue() -{ - return s_get_analytics_value; -} -jclass GetGameFileClass() -{ - return s_game_file_class; -} - -jfieldID GetGameFilePointer() -{ - return s_game_file_pointer; -} - -jmethodID GetGameFileConstructor() -{ - return s_game_file_constructor; -} - -jclass GetGameFileCacheClass() -{ - return s_game_file_cache_class; -} - -jfieldID GetGameFileCachePointer() -{ - return s_game_file_cache_pointer; -} - -jmethodID GetDoRumble() -{ - return s_do_rumble; -} - -} // namespace IDCache - -#ifdef __cplusplus -extern "C" { -#endif - -jint JNI_OnLoad(JavaVM* vm, void* reserved) -{ - s_java_vm = vm; - - JNIEnv* env; - if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) - return JNI_ERR; - - const jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary"); - s_native_library_class = reinterpret_cast(env->NewGlobalRef(native_library_class)); - s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg", - "(Ljava/lang/String;Ljava/lang/String;Z)Z"); - s_do_rumble = env->GetStaticMethodID(s_native_library_class, "rumble", "(ID)V"); - s_get_update_touch_pointer = - env->GetStaticMethodID(s_native_library_class, "updateTouchPointer", "()V"); - - const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile"); - s_game_file_class = reinterpret_cast(env->NewGlobalRef(game_file_class)); - s_game_file_pointer = env->GetFieldID(game_file_class, "mPointer", "J"); - s_game_file_constructor = env->GetMethodID(game_file_class, "", "(J)V"); - - const jclass game_file_cache_class = - env->FindClass("org/dolphinemu/dolphinemu/model/GameFileCache"); - s_game_file_cache_class = reinterpret_cast(env->NewGlobalRef(game_file_cache_class)); - s_game_file_cache_pointer = env->GetFieldID(game_file_cache_class, "mPointer", "J"); - - const jclass analytics_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Analytics"); - s_analytics_class = reinterpret_cast(env->NewGlobalRef(analytics_class)); - s_send_analytics_report = - env->GetStaticMethodID(s_analytics_class, "sendReport", "(Ljava/lang/String;[B)V"); - s_get_analytics_value = env->GetStaticMethodID(s_analytics_class, "getValue", - "(Ljava/lang/String;)Ljava/lang/String;"); - - return JNI_VERSION; -} - -void JNI_OnUnload(JavaVM* vm, void* reserved) -{ - JNIEnv* env; - if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) - return; - - env->DeleteGlobalRef(s_native_library_class); - env->DeleteGlobalRef(s_game_file_class); - env->DeleteGlobalRef(s_game_file_cache_class); - env->DeleteGlobalRef(s_analytics_class); -} - -#ifdef __cplusplus -} -#endif +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "jni/AndroidCommon/IDCache.h" + +#include + +static constexpr jint JNI_VERSION = JNI_VERSION_1_6; + +static JavaVM* s_java_vm; + +static jclass s_native_library_class; +static jmethodID s_display_alert_msg; +static jmethodID s_get_update_touch_pointer; + +static jclass s_game_file_class; +static jfieldID s_game_file_pointer; +static jmethodID s_game_file_constructor; + +static jclass s_game_file_cache_class; +static jfieldID s_game_file_cache_pointer; + +static jclass s_analytics_class; +static jmethodID s_send_analytics_report; +static jmethodID s_get_analytics_value; + +static jmethodID s_do_rumble; + +namespace IDCache +{ +JNIEnv* GetEnvForThread() +{ + thread_local static struct OwnedEnv + { + OwnedEnv() + { + status = s_java_vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); + if (status == JNI_EDETACHED) + s_java_vm->AttachCurrentThread(&env, nullptr); + } + + ~OwnedEnv() + { + if (status == JNI_EDETACHED) + s_java_vm->DetachCurrentThread(); + } + + int status; + JNIEnv* env = nullptr; + } owned; + return owned.env; +} + +jclass GetNativeLibraryClass() +{ + return s_native_library_class; +} + +jmethodID GetDisplayAlertMsg() +{ + return s_display_alert_msg; +} + +jmethodID GetUpdateTouchPointer() +{ + return s_get_update_touch_pointer; +} + +jclass GetAnalyticsClass() +{ + return s_analytics_class; +} + +jmethodID GetSendAnalyticsReport() +{ + return s_send_analytics_report; +} + +jmethodID GetAnalyticsValue() +{ + return s_get_analytics_value; +} +jclass GetGameFileClass() +{ + return s_game_file_class; +} + +jfieldID GetGameFilePointer() +{ + return s_game_file_pointer; +} + +jmethodID GetGameFileConstructor() +{ + return s_game_file_constructor; +} + +jclass GetGameFileCacheClass() +{ + return s_game_file_cache_class; +} + +jfieldID GetGameFileCachePointer() +{ + return s_game_file_cache_pointer; +} + +jmethodID GetDoRumble() +{ + return s_do_rumble; +} + +} // namespace IDCache + +#ifdef __cplusplus +extern "C" { +#endif + +jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + s_java_vm = vm; + + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) + return JNI_ERR; + + const jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary"); + s_native_library_class = reinterpret_cast(env->NewGlobalRef(native_library_class)); + s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg", + "(Ljava/lang/String;Ljava/lang/String;Z)Z"); + s_do_rumble = env->GetStaticMethodID(s_native_library_class, "rumble", "(ID)V"); + s_get_update_touch_pointer = + env->GetStaticMethodID(s_native_library_class, "updateTouchPointer", "()V"); + + const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile"); + s_game_file_class = reinterpret_cast(env->NewGlobalRef(game_file_class)); + s_game_file_pointer = env->GetFieldID(game_file_class, "mPointer", "J"); + s_game_file_constructor = env->GetMethodID(game_file_class, "", "(J)V"); + + const jclass game_file_cache_class = + env->FindClass("org/dolphinemu/dolphinemu/model/GameFileCache"); + s_game_file_cache_class = reinterpret_cast(env->NewGlobalRef(game_file_cache_class)); + s_game_file_cache_pointer = env->GetFieldID(game_file_cache_class, "mPointer", "J"); + + const jclass analytics_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Analytics"); + s_analytics_class = reinterpret_cast(env->NewGlobalRef(analytics_class)); + s_send_analytics_report = + env->GetStaticMethodID(s_analytics_class, "sendReport", "(Ljava/lang/String;[B)V"); + s_get_analytics_value = env->GetStaticMethodID(s_analytics_class, "getValue", + "(Ljava/lang/String;)Ljava/lang/String;"); + + return JNI_VERSION; +} + +void JNI_OnUnload(JavaVM* vm, void* reserved) +{ + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) + return; + + env->DeleteGlobalRef(s_native_library_class); + env->DeleteGlobalRef(s_game_file_class); + env->DeleteGlobalRef(s_game_file_cache_class); + env->DeleteGlobalRef(s_analytics_class); +} + +#ifdef __cplusplus +} +#endif diff --git a/Source/Android/jni/AndroidCommon/IDCache.h b/Source/Android/jni/AndroidCommon/IDCache.h index e3ef7259c1..68cfdb80af 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.h +++ b/Source/Android/jni/AndroidCommon/IDCache.h @@ -1,31 +1,31 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include - -namespace IDCache -{ -static constexpr jint JNI_VERSION = JNI_VERSION_1_6; - -JNIEnv* GetEnvForThread(); - -jclass GetNativeLibraryClass(); -jmethodID GetDisplayAlertMsg(); -jmethodID GetDoRumble(); -jmethodID GetUpdateTouchPointer(); - -jclass GetAnalyticsClass(); -jmethodID GetSendAnalyticsReport(); -jmethodID GetAnalyticsValue(); - -jclass GetGameFileClass(); -jfieldID GetGameFilePointer(); -jmethodID GetGameFileConstructor(); - -jclass GetGameFileCacheClass(); -jfieldID GetGameFileCachePointer(); - -} // namespace IDCache +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +namespace IDCache +{ +static constexpr jint JNI_VERSION = JNI_VERSION_1_6; + +JNIEnv* GetEnvForThread(); + +jclass GetNativeLibraryClass(); +jmethodID GetDisplayAlertMsg(); +jmethodID GetDoRumble(); +jmethodID GetUpdateTouchPointer(); + +jclass GetAnalyticsClass(); +jmethodID GetSendAnalyticsReport(); +jmethodID GetAnalyticsValue(); + +jclass GetGameFileClass(); +jfieldID GetGameFilePointer(); +jmethodID GetGameFileConstructor(); + +jclass GetGameFileCacheClass(); +jfieldID GetGameFileCachePointer(); + +} // namespace IDCache diff --git a/Source/Android/jni/GameList/GameFile.cpp b/Source/Android/jni/GameList/GameFile.cpp index f1af2584c3..71b8076275 100644 --- a/Source/Android/jni/GameList/GameFile.cpp +++ b/Source/Android/jni/GameList/GameFile.cpp @@ -1,224 +1,224 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include "jni/GameList/GameFile.h" - -#include -#include -#include - -#include - -#include "DiscIO/Blob.h" -#include "DiscIO/Enums.h" -#include "UICommon/GameFile.h" -#include "jni/AndroidCommon/AndroidCommon.h" -#include "jni/AndroidCommon/IDCache.h" - -static std::shared_ptr* GetPointer(JNIEnv* env, jobject obj) -{ - return reinterpret_cast*>( - env->GetLongField(obj, IDCache::GetGameFilePointer())); -} - -static std::shared_ptr& GetRef(JNIEnv* env, jobject obj) -{ - return *GetPointer(env, obj); -} - -jobject GameFileToJava(JNIEnv* env, std::shared_ptr game_file) -{ - if (!game_file) - return nullptr; - - return env->NewObject( - IDCache::GetGameFileClass(), IDCache::GetGameFileConstructor(), - reinterpret_cast(new std::shared_ptr(std::move(game_file)))); -} - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_finalize(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCountry(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRegion(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPath(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameId(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDiscNumber(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRevision(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFile_getBlobTypeString(JNIEnv* env, jobject obj); -JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBlockSize(JNIEnv* env, - jobject obj); -JNIEXPORT jstring JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFile_getCompressionMethod(JNIEnv* env, jobject obj); -JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFile_shouldShowFileFormatDetails(JNIEnv* env, jobject obj); -JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getFileSize(JNIEnv* env, - jobject obj); -JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env, - jobject obj); -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env, - jobject obj); - -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_finalize(JNIEnv* env, - jobject obj) -{ - delete GetPointer(env, obj); -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform(JNIEnv* env, - jobject obj) -{ - return static_cast(GetRef(env, obj)->GetPlatform()); -} - -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env, - jobject obj) -{ - return ToJString(env, - GetRef(env, obj)->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom)); -} - -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env, - jobject obj) -{ - return ToJString( - env, GetRef(env, obj)->GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom)); -} - -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env, - jobject obj) -{ - return ToJString(env, DiscIO::GetCompanyFromID(GetRef(env, obj)->GetMakerID())); -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCountry(JNIEnv* env, - jobject obj) -{ - return static_cast(GetRef(env, obj)->GetCountry()); -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRegion(JNIEnv* env, - jobject obj) -{ - return static_cast(GetRef(env, obj)->GetRegion()); -} - -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPath(JNIEnv* env, - jobject obj) -{ - return ToJString(env, GetRef(env, obj)->GetFilePath()); -} - -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameId(JNIEnv* env, - jobject obj) -{ - return ToJString(env, GetRef(env, obj)->GetGameID()); -} - -JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameTdbId(JNIEnv* env, - jobject obj) -{ - return ToJString(env, GetRef(env, obj)->GetGameTDBID()); -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDiscNumber(JNIEnv* env, - jobject obj) -{ - return GetRef(env, obj)->GetDiscNumber(); -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRevision(JNIEnv* env, - jobject obj) -{ - return GetRef(env, obj)->GetRevision(); -} - -JNIEXPORT jstring JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFile_getBlobTypeString(JNIEnv* env, jobject obj) -{ - return ToJString(env, DiscIO::GetName(GetRef(env, obj)->GetBlobType(), true)); -} - -JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBlockSize(JNIEnv* env, - jobject obj) -{ - return GetRef(env, obj)->GetBlockSize(); -} - -JNIEXPORT jstring JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFile_getCompressionMethod(JNIEnv* env, jobject obj) -{ - return ToJString(env, GetRef(env, obj)->GetCompressionMethod()); -} - -JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFile_shouldShowFileFormatDetails(JNIEnv* env, jobject obj) -{ - return GetRef(env, obj)->ShouldShowFileFormatDetails(); -} - -JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getFileSize(JNIEnv* env, - jobject obj) -{ - return GetRef(env, obj)->GetFileSize(); -} - -JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env, - jobject obj) -{ - const std::vector& buffer = GetRef(env, obj)->GetBannerImage().buffer; - const jsize size = static_cast(buffer.size()); - const jintArray out_array = env->NewIntArray(size); - if (!out_array) - return nullptr; - env->SetIntArrayRegion(out_array, 0, size, reinterpret_cast(buffer.data())); - return out_array; -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env, - jobject obj) -{ - return static_cast(GetRef(env, obj)->GetBannerImage().width); -} - -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env, - jobject obj) -{ - return static_cast(GetRef(env, obj)->GetBannerImage().height); -} - -JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_parse(JNIEnv* env, - jobject obj, - jstring path) -{ - auto game_file = std::make_shared(GetJString(env, path)); - if (!game_file->IsValid()) - game_file.reset(); - - return GameFileToJava(env, game_file); -} - -#ifdef __cplusplus -} -#endif +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "jni/GameList/GameFile.h" + +#include +#include +#include + +#include + +#include "DiscIO/Blob.h" +#include "DiscIO/Enums.h" +#include "UICommon/GameFile.h" +#include "jni/AndroidCommon/AndroidCommon.h" +#include "jni/AndroidCommon/IDCache.h" + +static std::shared_ptr* GetPointer(JNIEnv* env, jobject obj) +{ + return reinterpret_cast*>( + env->GetLongField(obj, IDCache::GetGameFilePointer())); +} + +static std::shared_ptr& GetRef(JNIEnv* env, jobject obj) +{ + return *GetPointer(env, obj); +} + +jobject GameFileToJava(JNIEnv* env, std::shared_ptr game_file) +{ + if (!game_file) + return nullptr; + + return env->NewObject( + IDCache::GetGameFileClass(), IDCache::GetGameFileConstructor(), + reinterpret_cast(new std::shared_ptr(std::move(game_file)))); +} + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_finalize(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCountry(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRegion(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPath(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameId(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDiscNumber(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRevision(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFile_getBlobTypeString(JNIEnv* env, jobject obj); +JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBlockSize(JNIEnv* env, + jobject obj); +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFile_getCompressionMethod(JNIEnv* env, jobject obj); +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFile_shouldShowFileFormatDetails(JNIEnv* env, jobject obj); +JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getFileSize(JNIEnv* env, + jobject obj); +JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env, + jobject obj); +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env, + jobject obj); + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_finalize(JNIEnv* env, + jobject obj) +{ + delete GetPointer(env, obj); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform(JNIEnv* env, + jobject obj) +{ + return static_cast(GetRef(env, obj)->GetPlatform()); +} + +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env, + jobject obj) +{ + return ToJString(env, + GetRef(env, obj)->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom)); +} + +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env, + jobject obj) +{ + return ToJString( + env, GetRef(env, obj)->GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom)); +} + +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env, + jobject obj) +{ + return ToJString(env, DiscIO::GetCompanyFromID(GetRef(env, obj)->GetMakerID())); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCountry(JNIEnv* env, + jobject obj) +{ + return static_cast(GetRef(env, obj)->GetCountry()); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRegion(JNIEnv* env, + jobject obj) +{ + return static_cast(GetRef(env, obj)->GetRegion()); +} + +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPath(JNIEnv* env, + jobject obj) +{ + return ToJString(env, GetRef(env, obj)->GetFilePath()); +} + +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameId(JNIEnv* env, + jobject obj) +{ + return ToJString(env, GetRef(env, obj)->GetGameID()); +} + +JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameTdbId(JNIEnv* env, + jobject obj) +{ + return ToJString(env, GetRef(env, obj)->GetGameTDBID()); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDiscNumber(JNIEnv* env, + jobject obj) +{ + return GetRef(env, obj)->GetDiscNumber(); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRevision(JNIEnv* env, + jobject obj) +{ + return GetRef(env, obj)->GetRevision(); +} + +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFile_getBlobTypeString(JNIEnv* env, jobject obj) +{ + return ToJString(env, DiscIO::GetName(GetRef(env, obj)->GetBlobType(), true)); +} + +JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBlockSize(JNIEnv* env, + jobject obj) +{ + return GetRef(env, obj)->GetBlockSize(); +} + +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFile_getCompressionMethod(JNIEnv* env, jobject obj) +{ + return ToJString(env, GetRef(env, obj)->GetCompressionMethod()); +} + +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFile_shouldShowFileFormatDetails(JNIEnv* env, jobject obj) +{ + return GetRef(env, obj)->ShouldShowFileFormatDetails(); +} + +JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getFileSize(JNIEnv* env, + jobject obj) +{ + return GetRef(env, obj)->GetFileSize(); +} + +JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env, + jobject obj) +{ + const std::vector& buffer = GetRef(env, obj)->GetBannerImage().buffer; + const jsize size = static_cast(buffer.size()); + const jintArray out_array = env->NewIntArray(size); + if (!out_array) + return nullptr; + env->SetIntArrayRegion(out_array, 0, size, reinterpret_cast(buffer.data())); + return out_array; +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env, + jobject obj) +{ + return static_cast(GetRef(env, obj)->GetBannerImage().width); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env, + jobject obj) +{ + return static_cast(GetRef(env, obj)->GetBannerImage().height); +} + +JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_parse(JNIEnv* env, + jobject obj, + jstring path) +{ + auto game_file = std::make_shared(GetJString(env, path)); + if (!game_file->IsValid()) + game_file.reset(); + + return GameFileToJava(env, game_file); +} + +#ifdef __cplusplus +} +#endif diff --git a/Source/Android/jni/GameList/GameFile.h b/Source/Android/jni/GameList/GameFile.h index 9bf4f1cce4..4eac81a02a 100644 --- a/Source/Android/jni/GameList/GameFile.h +++ b/Source/Android/jni/GameList/GameFile.h @@ -1,17 +1,17 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include -#include - -#include - -namespace UICommon -{ -class GameFile; -} - -jobject GameFileToJava(JNIEnv* env, std::shared_ptr game_file); +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include + +namespace UICommon +{ +class GameFile; +} + +jobject GameFileToJava(JNIEnv* env, std::shared_ptr game_file); diff --git a/Source/Android/jni/GameList/GameFileCache.cpp b/Source/Android/jni/GameList/GameFileCache.cpp index 1e5c6a28c1..0d8aea8285 100644 --- a/Source/Android/jni/GameList/GameFileCache.cpp +++ b/Source/Android/jni/GameList/GameFileCache.cpp @@ -1,122 +1,122 @@ -// Copyright 2018 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include -#include - -#include - -#include "UICommon/GameFileCache.h" -#include "jni/AndroidCommon/AndroidCommon.h" -#include "jni/AndroidCommon/IDCache.h" -#include "jni/GameList/GameFile.h" - -namespace UICommon -{ -class GameFile; -} - -static UICommon::GameFileCache* GetPointer(JNIEnv* env, jobject obj) -{ - return reinterpret_cast( - env->GetLongField(obj, IDCache::GetGameFileCachePointer())); -} - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache( - JNIEnv* env, jobject obj, jstring path); -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env, - jobject obj); -JNIEXPORT jobjectArray JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGames(JNIEnv* env, jobject obj); -JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_addOrGet(JNIEnv* env, - jobject obj, - jstring path); -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update( - JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan); -JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env, - jobject obj); -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_load(JNIEnv* env, - jobject obj); -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_save(JNIEnv* env, - jobject obj); - -JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache( - JNIEnv* env, jobject obj, jstring path) -{ - return reinterpret_cast(new UICommon::GameFileCache(GetJString(env, path))); -} - -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env, - jobject obj) -{ - delete GetPointer(env, obj); -} - -JNIEXPORT jobjectArray JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGames(JNIEnv* env, jobject obj) -{ - const UICommon::GameFileCache* ptr = GetPointer(env, obj); - const jobjectArray array = - env->NewObjectArray(static_cast(ptr->GetSize()), IDCache::GetGameFileClass(), nullptr); - jsize i = 0; - GetPointer(env, obj)->ForEach([env, array, &i](const auto& game_file) { - env->SetObjectArrayElement(array, i++, GameFileToJava(env, game_file)); - }); - return array; -} - -JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_addOrGet(JNIEnv* env, - jobject obj, - jstring path) -{ - bool cache_changed = false; - return GameFileToJava(env, GetPointer(env, obj)->AddOrGet(GetJString(env, path), &cache_changed)); -} - -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update( - JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan) -{ - jsize size = env->GetArrayLength(folder_paths); - - std::vector folder_paths_vector; - folder_paths_vector.reserve(size); - - for (jsize i = 0; i < size; ++i) - { - const jstring path = reinterpret_cast(env->GetObjectArrayElement(folder_paths, i)); - folder_paths_vector.push_back(GetJString(env, path)); - env->DeleteLocalRef(path); - } - - return GetPointer(env, obj)->Update( - UICommon::FindAllGamePaths(folder_paths_vector, recursive_scan)); -} - -JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env, - jobject obj) -{ - return GetPointer(env, obj)->UpdateAdditionalMetadata(); -} - -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_load(JNIEnv* env, - jobject obj) -{ - return GetPointer(env, obj)->Load(); -} - -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_save(JNIEnv* env, - jobject obj) -{ - return GetPointer(env, obj)->Save(); -} - -#ifdef __cplusplus -} -#endif +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#include + +#include + +#include "UICommon/GameFileCache.h" +#include "jni/AndroidCommon/AndroidCommon.h" +#include "jni/AndroidCommon/IDCache.h" +#include "jni/GameList/GameFile.h" + +namespace UICommon +{ +class GameFile; +} + +static UICommon::GameFileCache* GetPointer(JNIEnv* env, jobject obj) +{ + return reinterpret_cast( + env->GetLongField(obj, IDCache::GetGameFileCachePointer())); +} + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache( + JNIEnv* env, jobject obj, jstring path); +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env, + jobject obj); +JNIEXPORT jobjectArray JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGames(JNIEnv* env, jobject obj); +JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_addOrGet(JNIEnv* env, + jobject obj, + jstring path); +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update( + JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan); +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env, + jobject obj); +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_load(JNIEnv* env, + jobject obj); +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_save(JNIEnv* env, + jobject obj); + +JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache( + JNIEnv* env, jobject obj, jstring path) +{ + return reinterpret_cast(new UICommon::GameFileCache(GetJString(env, path))); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env, + jobject obj) +{ + delete GetPointer(env, obj); +} + +JNIEXPORT jobjectArray JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGames(JNIEnv* env, jobject obj) +{ + const UICommon::GameFileCache* ptr = GetPointer(env, obj); + const jobjectArray array = + env->NewObjectArray(static_cast(ptr->GetSize()), IDCache::GetGameFileClass(), nullptr); + jsize i = 0; + GetPointer(env, obj)->ForEach([env, array, &i](const auto& game_file) { + env->SetObjectArrayElement(array, i++, GameFileToJava(env, game_file)); + }); + return array; +} + +JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_addOrGet(JNIEnv* env, + jobject obj, + jstring path) +{ + bool cache_changed = false; + return GameFileToJava(env, GetPointer(env, obj)->AddOrGet(GetJString(env, path), &cache_changed)); +} + +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update( + JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan) +{ + jsize size = env->GetArrayLength(folder_paths); + + std::vector folder_paths_vector; + folder_paths_vector.reserve(size); + + for (jsize i = 0; i < size; ++i) + { + const jstring path = reinterpret_cast(env->GetObjectArrayElement(folder_paths, i)); + folder_paths_vector.push_back(GetJString(env, path)); + env->DeleteLocalRef(path); + } + + return GetPointer(env, obj)->Update( + UICommon::FindAllGamePaths(folder_paths_vector, recursive_scan)); +} + +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env, + jobject obj) +{ + return GetPointer(env, obj)->UpdateAdditionalMetadata(); +} + +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_load(JNIEnv* env, + jobject obj) +{ + return GetPointer(env, obj)->Load(); +} + +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_save(JNIEnv* env, + jobject obj) +{ + return GetPointer(env, obj)->Save(); +} + +#ifdef __cplusplus +} +#endif