Android: Implement save overwrite confirmation
This commit is contained in:
parent
cd4ccda51c
commit
347551a01d
|
@ -18,11 +18,14 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
|||
import org.dolphinemu.dolphinemu.model.GameFileCache;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
|
||||
import org.dolphinemu.dolphinemu.utils.BooleanSupplier;
|
||||
import org.dolphinemu.dolphinemu.utils.ContentHandler;
|
||||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.WiiUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class MainPresenter
|
||||
|
@ -168,9 +171,41 @@ public final class MainPresenter
|
|||
|
||||
public void importWiiSave(String path)
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N)
|
||||
return; // TODO
|
||||
|
||||
final Activity mainPresenterActivity = (Activity) mContext;
|
||||
|
||||
CompletableFuture<Boolean> canOverwriteFuture = new CompletableFuture<>();
|
||||
|
||||
runOnThreadAndShowResult(R.string.import_in_progress, () ->
|
||||
{
|
||||
int result = WiiUtils.importWiiSave(path);
|
||||
BooleanSupplier canOverwrite = () ->
|
||||
{
|
||||
mainPresenterActivity.runOnUiThread(() ->
|
||||
{
|
||||
AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(mContext, R.style.DolphinDialogBase);
|
||||
builder.setMessage(R.string.wii_save_exists);
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton(R.string.yes, (dialog, i) -> canOverwriteFuture.complete(true));
|
||||
builder.setNegativeButton(R.string.no, (dialog, i) -> canOverwriteFuture.complete(false));
|
||||
builder.show();
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
return canOverwriteFuture.get();
|
||||
}
|
||||
catch (ExecutionException | InterruptedException e)
|
||||
{
|
||||
// Shouldn't happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
|
||||
int result = WiiUtils.importWiiSave(path, canOverwrite);
|
||||
|
||||
int message;
|
||||
switch (result)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
public interface BooleanSupplier
|
||||
{
|
||||
boolean get();
|
||||
}
|
|
@ -10,5 +10,5 @@ public final class WiiUtils
|
|||
|
||||
public static native boolean installWAD(String file);
|
||||
|
||||
public static native int importWiiSave(String file);
|
||||
public static native int importWiiSave(String file, BooleanSupplier canOverwrite);
|
||||
}
|
||||
|
|
|
@ -333,6 +333,7 @@
|
|||
<string name="import_in_progress">Importing...</string>
|
||||
<string name="wad_install_success">Successfully installed this title to the NAND.</string>
|
||||
<string name="wad_install_failure">Failed to install this title to the NAND.</string>
|
||||
<string name="wii_save_exists">Save data for this title already exists in the NAND. Consider backing up the current data before overwriting.\nOverwrite now?</string>
|
||||
<string name="wii_save_import_success">Successfully imported save file.</string>
|
||||
<string name="wii_save_import_error">Failed to import save file. Your NAND may be corrupt, or something is preventing access to files within it.</string>
|
||||
<string name="wii_save_import_corruped_source">Failed to import save file. The given file appears to be corrupted or is not a valid Wii save.</string>
|
||||
|
|
|
@ -56,6 +56,9 @@ static jmethodID s_network_helper_get_network_ip_address;
|
|||
static jmethodID s_network_helper_get_network_prefix_length;
|
||||
static jmethodID s_network_helper_get_network_gateway;
|
||||
|
||||
static jclass s_boolean_supplier_class;
|
||||
static jmethodID s_boolean_supplier_get;
|
||||
|
||||
namespace IDCache
|
||||
{
|
||||
JNIEnv* GetEnvForThread()
|
||||
|
@ -261,6 +264,11 @@ jmethodID GetNetworkHelperGetNetworkGateway()
|
|||
return s_network_helper_get_network_gateway;
|
||||
}
|
||||
|
||||
jmethodID GetBooleanSupplierGet()
|
||||
{
|
||||
return s_boolean_supplier_get;
|
||||
}
|
||||
|
||||
} // namespace IDCache
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -361,6 +369,11 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|||
s_network_helper_get_network_gateway =
|
||||
env->GetStaticMethodID(s_network_helper_class, "GetNetworkGateway", "()I");
|
||||
|
||||
const jclass boolean_supplier_class =
|
||||
env->FindClass("org/dolphinemu/dolphinemu/utils/BooleanSupplier");
|
||||
s_boolean_supplier_class = reinterpret_cast<jclass>(env->NewGlobalRef(boolean_supplier_class));
|
||||
s_boolean_supplier_get = env->GetMethodID(s_boolean_supplier_class, "get", "()Z");
|
||||
|
||||
return JNI_VERSION;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,4 +56,6 @@ jmethodID GetNetworkHelperGetNetworkIpAddress();
|
|||
jmethodID GetNetworkHelperGetNetworkPrefixLength();
|
||||
jmethodID GetNetworkHelperGetNetworkGateway();
|
||||
|
||||
jmethodID GetBooleanSupplierGet();
|
||||
|
||||
} // namespace IDCache
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <jni.h>
|
||||
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
#include "Core/HW/WiiSave.h"
|
||||
#include "Core/WiiUtils.h"
|
||||
|
@ -44,12 +45,14 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_install
|
|||
return static_cast<jboolean>(WiiUtils::InstallWAD(path));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_importWiiSave(JNIEnv* env,
|
||||
jclass,
|
||||
jstring jFile)
|
||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_importWiiSave(
|
||||
JNIEnv* env, jclass, jstring jFile, jobject jCanOverwrite)
|
||||
{
|
||||
const std::string path = GetJString(env, jFile);
|
||||
const auto can_overwrite = [] { return true; }; // TODO
|
||||
const auto can_overwrite = [&] {
|
||||
const jmethodID get = IDCache::GetBooleanSupplierGet();
|
||||
return static_cast<bool>(env->CallBooleanMethod(jCanOverwrite, get));
|
||||
};
|
||||
|
||||
return ConvertCopyResult(WiiSave::Import(path, can_overwrite));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue