2020-07-06 14:57:49 +00:00
|
|
|
// Copyright 2020 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-07-06 14:57:49 +00:00
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
|
|
|
|
|
|
|
static IniFile::Section* GetSectionPointer(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<IniFile::Section*>(
|
|
|
|
env->GetLongField(obj, IDCache::GetIniFileSectionPointer()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IniFile* GetIniFilePointer(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<IniFile*>(env->GetLongField(obj, IDCache::GetIniFilePointer()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static jobject SectionToJava(JNIEnv* env, jobject ini_file, IniFile::Section* section)
|
|
|
|
{
|
|
|
|
if (!section)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return env->NewObject(IDCache::GetIniFileSectionClass(), IDCache::GetIniFileSectionConstructor(),
|
|
|
|
ini_file, reinterpret_cast<jlong>(section));
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:26:38 +00:00
|
|
|
template <typename T>
|
|
|
|
static T GetInSection(JNIEnv* env, jobject obj, jstring key, T default_value)
|
|
|
|
{
|
|
|
|
T result;
|
|
|
|
GetSectionPointer(env, obj)->Get(GetJString(env, key), &result, default_value);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void SetInSection(JNIEnv* env, jobject obj, jstring key, T new_value)
|
|
|
|
{
|
|
|
|
GetSectionPointer(env, obj)->Set(GetJString(env, key), new_value);
|
|
|
|
}
|
|
|
|
|
2020-07-06 14:57:49 +00:00
|
|
|
template <typename T>
|
|
|
|
static T Get(JNIEnv* env, jobject obj, jstring section_name, jstring key, T default_value)
|
|
|
|
{
|
|
|
|
T result;
|
|
|
|
GetIniFilePointer(env, obj)
|
|
|
|
->GetOrCreateSection(GetJString(env, section_name))
|
|
|
|
->Get(GetJString(env, key), &result, default_value);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void Set(JNIEnv* env, jobject obj, jstring section_name, jstring key, T new_value)
|
|
|
|
{
|
|
|
|
GetIniFilePointer(env, obj)
|
|
|
|
->GetOrCreateSection(GetJString(env, section_name))
|
|
|
|
->Set(GetJString(env, key), new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2020-07-07 10:26:38 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_exists(
|
|
|
|
JNIEnv* env, jobject obj, jstring key)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(GetSectionPointer(env, obj)->Exists(GetJString(env, key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_delete(
|
|
|
|
JNIEnv* env, jobject obj, jstring key)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(GetSectionPointer(env, obj)->Delete(GetJString(env, key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getString(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jstring default_value)
|
|
|
|
{
|
|
|
|
return ToJString(env, GetInSection(env, obj, key, GetJString(env, default_value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getBoolean(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jboolean default_value)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(GetInSection(env, obj, key, static_cast<bool>(default_value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getInt(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jint default_value)
|
|
|
|
{
|
|
|
|
return GetInSection(env, obj, key, default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getFloat(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jfloat default_value)
|
|
|
|
{
|
|
|
|
return GetInSection(env, obj, key, default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setString(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jstring new_value)
|
|
|
|
{
|
|
|
|
SetInSection(env, obj, key, GetJString(env, new_value));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setBoolean(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jboolean new_value)
|
|
|
|
{
|
|
|
|
SetInSection(env, obj, key, static_cast<bool>(new_value));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setInt(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jint new_value)
|
|
|
|
{
|
|
|
|
SetInSection(env, obj, key, new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setFloat(
|
|
|
|
JNIEnv* env, jobject obj, jstring key, jfloat new_value)
|
|
|
|
{
|
|
|
|
SetInSection(env, obj, key, new_value);
|
|
|
|
}
|
|
|
|
|
2020-07-06 14:57:49 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_load(
|
|
|
|
JNIEnv* env, jobject obj, jstring path, jboolean keep_current_data)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(
|
|
|
|
GetIniFilePointer(env, obj)->Load(GetJString(env, path), keep_current_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_save(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring path)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(GetIniFilePointer(env, obj)->Save(GetJString(env, path)));
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:26:38 +00:00
|
|
|
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getOrCreateSection(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name)
|
|
|
|
{
|
|
|
|
return SectionToJava(
|
|
|
|
env, obj, GetIniFilePointer(env, obj)->GetOrCreateSection(GetJString(env, section_name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_exists__Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(GetIniFilePointer(env, obj)->Exists(GetJString(env, section_name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_utils_IniFile_exists__Ljava_lang_String_2Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(
|
|
|
|
GetIniFilePointer(env, obj)->Exists(GetJString(env, section_name), GetJString(env, key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_deleteSection(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(
|
|
|
|
GetIniFilePointer(env, obj)->DeleteSection(GetJString(env, section_name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_deleteKey(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(
|
|
|
|
GetIniFilePointer(env, obj)->DeleteKey(GetJString(env, section_name), GetJString(env, key)));
|
|
|
|
}
|
|
|
|
|
2020-07-06 14:57:49 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getString(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key, jstring default_value)
|
|
|
|
{
|
|
|
|
return ToJString(env, Get(env, obj, section_name, key, GetJString(env, default_value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getBoolean(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key, jboolean default_value)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(Get(env, obj, section_name, key, static_cast<bool>(default_value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getInt(JNIEnv* env, jobject obj,
|
|
|
|
jstring section_name,
|
|
|
|
jstring key,
|
|
|
|
jint default_value)
|
|
|
|
{
|
|
|
|
return Get(env, obj, section_name, key, default_value);
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:26:38 +00:00
|
|
|
JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getFloat(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key, jfloat default_value)
|
|
|
|
{
|
|
|
|
return Get(env, obj, section_name, key, default_value);
|
|
|
|
}
|
|
|
|
|
2020-07-06 14:57:49 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setString(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key, jstring new_value)
|
|
|
|
{
|
|
|
|
Set(env, obj, section_name, key, GetJString(env, new_value));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setBoolean(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key, jboolean new_value)
|
|
|
|
{
|
|
|
|
Set(env, obj, section_name, key, static_cast<bool>(new_value));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setInt(JNIEnv* env, jobject obj,
|
|
|
|
jstring section_name,
|
|
|
|
jstring key,
|
|
|
|
jint new_value)
|
|
|
|
{
|
|
|
|
Set(env, obj, section_name, key, new_value);
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:26:38 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setFloat(
|
|
|
|
JNIEnv* env, jobject obj, jstring section_name, jstring key, jfloat new_value)
|
|
|
|
{
|
|
|
|
Set(env, obj, section_name, key, new_value);
|
|
|
|
}
|
|
|
|
|
2020-07-06 14:57:49 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_finalize(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
delete GetIniFilePointer(env, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_newIniFile(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jobject)
|
2020-07-06 14:57:49 +00:00
|
|
|
{
|
|
|
|
return reinterpret_cast<jlong>(new IniFile);
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:26:38 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_copyIniFile(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jobject,
|
2020-07-07 10:26:38 +00:00
|
|
|
jobject other)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<jlong>(new IniFile(*GetIniFilePointer(env, other)));
|
|
|
|
}
|
2020-07-06 14:57:49 +00:00
|
|
|
}
|