2018-06-01 07:36:29 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "jni/GameList/GameFile.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include "DiscIO/Enums.h"
|
|
|
|
#include "UICommon/GameFile.h"
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
|
|
|
|
|
|
|
static std::shared_ptr<const UICommon::GameFile>* GetPointer(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<std::shared_ptr<const UICommon::GameFile>*>(
|
|
|
|
env->GetLongField(obj, IDCache::GetGameFilePointer()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::shared_ptr<const UICommon::GameFile>& GetRef(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
return *GetPointer(env, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject GameFileToJava(JNIEnv* env, std::shared_ptr<const UICommon::GameFile> game_file)
|
|
|
|
{
|
|
|
|
if (!game_file)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return env->NewObject(
|
|
|
|
IDCache::GetGameFileClass(), IDCache::GetGameFileConstructor(),
|
|
|
|
reinterpret_cast<jlong>(new std::shared_ptr<const UICommon::GameFile>(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);
|
2018-08-05 20:11:33 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRegion(JNIEnv* env,
|
|
|
|
jobject obj);
|
2018-06-01 07:36:29 +00:00
|
|
|
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);
|
2018-12-25 12:33:22 +00:00
|
|
|
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);
|
2018-06-01 07:36:29 +00:00
|
|
|
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<jint>(GetRef(env, obj)->GetPlatform());
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
2019-09-25 09:36:45 +00:00
|
|
|
return ToJString(env,
|
|
|
|
GetRef(env, obj)->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom));
|
2018-06-01 07:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
2019-09-25 09:36:45 +00:00
|
|
|
return ToJString(
|
|
|
|
env, GetRef(env, obj)->GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom));
|
2018-06-01 07:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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<jint>(GetRef(env, obj)->GetCountry());
|
|
|
|
}
|
|
|
|
|
2018-08-05 20:11:33 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRegion(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return static_cast<jint>(GetRef(env, obj)->GetRegion());
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:49:06 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameTdbId(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return ToJString(env, GetRef(env, obj)->GetGameTDBID());
|
|
|
|
}
|
|
|
|
|
2018-12-25 12:33:22 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDiscNumber(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return env, GetRef(env, obj)->GetDiscNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getRevision(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return env, GetRef(env, obj)->GetRevision();
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
const std::vector<u32>& buffer = GetRef(env, obj)->GetBannerImage().buffer;
|
|
|
|
const jsize size = static_cast<jsize>(buffer.size());
|
|
|
|
const jintArray out_array = env->NewIntArray(size);
|
|
|
|
if (!out_array)
|
|
|
|
return nullptr;
|
|
|
|
env->SetIntArrayRegion(out_array, 0, size, reinterpret_cast<const jint*>(buffer.data()));
|
|
|
|
return out_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return static_cast<jint>(GetRef(env, obj)->GetBannerImage().width);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return static_cast<jint>(GetRef(env, obj)->GetBannerImage().height);
|
|
|
|
}
|
|
|
|
|
2019-07-18 10:42:09 +00:00
|
|
|
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_parse(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring path)
|
|
|
|
{
|
|
|
|
auto game_file = std::make_shared<UICommon::GameFile>(GetJString(env, path));
|
|
|
|
if (!game_file->IsValid())
|
|
|
|
game_file.reset();
|
|
|
|
|
|
|
|
return GameFileToJava(env, game_file);
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|