2021-01-17 21:15:13 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
2021-01-18 11:22:26 +00:00
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
2021-01-17 21:15:13 +00:00
|
|
|
|
2021-01-17 22:16:23 +00:00
|
|
|
#include "Core/HW/WiiSave.h"
|
2021-01-17 21:15:13 +00:00
|
|
|
#include "Core/WiiUtils.h"
|
|
|
|
|
2021-01-17 22:16:23 +00:00
|
|
|
// The hardcoded values here must match WiiUtils.java
|
|
|
|
static jint ConvertCopyResult(WiiSave::CopyResult result)
|
|
|
|
{
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case WiiSave::CopyResult::Success:
|
|
|
|
return 0;
|
|
|
|
case WiiSave::CopyResult::Error:
|
|
|
|
return 1;
|
|
|
|
case WiiSave::CopyResult::Cancelled:
|
|
|
|
return 2;
|
|
|
|
case WiiSave::CopyResult::CorruptedSource:
|
|
|
|
return 3;
|
|
|
|
case WiiSave::CopyResult::TitleMissing:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static_assert(static_cast<int>(WiiSave::CopyResult::NumberOfEntries) == 5);
|
|
|
|
}
|
|
|
|
|
2021-01-17 21:15:13 +00:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_installWAD(JNIEnv* env,
|
|
|
|
jclass,
|
|
|
|
jstring jFile)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jFile);
|
|
|
|
return static_cast<jboolean>(WiiUtils::InstallWAD(path));
|
|
|
|
}
|
2021-01-17 22:16:23 +00:00
|
|
|
|
2021-01-18 11:22:26 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_importWiiSave(
|
|
|
|
JNIEnv* env, jclass, jstring jFile, jobject jCanOverwrite)
|
2021-01-17 22:16:23 +00:00
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jFile);
|
2021-01-18 11:22:26 +00:00
|
|
|
const auto can_overwrite = [&] {
|
|
|
|
const jmethodID get = IDCache::GetBooleanSupplierGet();
|
|
|
|
return static_cast<bool>(env->CallBooleanMethod(jCanOverwrite, get));
|
|
|
|
};
|
2021-01-17 22:16:23 +00:00
|
|
|
|
|
|
|
return ConvertCopyResult(WiiSave::Import(path, can_overwrite));
|
|
|
|
}
|
2021-01-17 21:15:13 +00:00
|
|
|
}
|