2020-07-06 15:02:01 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-07-06 15:02:01 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include "UICommon/GameFileCache.h"
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
|
|
|
#include "jni/GameList/GameFile.h"
|
|
|
|
|
|
|
|
static UICommon::GameFileCache* GetPointer(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<UICommon::GameFileCache*>(
|
|
|
|
env->GetLongField(obj, IDCache::GetGameFileCachePointer()));
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2021-06-08 16:09:22 +00:00
|
|
|
JNIEXPORT jlong JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache(JNIEnv* env, jclass)
|
2020-07-06 15:02:01 +00:00
|
|
|
{
|
2021-06-08 16:09:22 +00:00
|
|
|
return reinterpret_cast<jlong>(new UICommon::GameFileCache());
|
2020-07-06 15:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
delete GetPointer(env, obj);
|
|
|
|
}
|
|
|
|
|
2021-08-24 12:36:08 +00:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGamePaths(
|
|
|
|
JNIEnv* env, jclass, jobjectArray folder_paths, jboolean recursive_scan)
|
|
|
|
{
|
|
|
|
return VectorToJStringArray(
|
|
|
|
env, UICommon::FindAllGamePaths(JStringArrayToVector(env, folder_paths), recursive_scan));
|
|
|
|
}
|
|
|
|
|
2021-02-20 18:41:41 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_getSize(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return static_cast<jint>(GetPointer(env, obj)->GetSize());
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:02:01 +00:00
|
|
|
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<jsize>(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(
|
2021-08-24 12:36:08 +00:00
|
|
|
JNIEnv* env, jobject obj, jobjectArray game_paths)
|
2020-07-06 15:02:01 +00:00
|
|
|
{
|
2021-08-24 12:36:08 +00:00
|
|
|
return GetPointer(env, obj)->Update(JStringArrayToVector(env, game_paths));
|
2020-07-06 15:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|