From 2d6d0c86cc71a1d3b1a2b865c6abd8cb7ace8665 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Fri, 17 Apr 2020 05:25:08 -0400 Subject: [PATCH 1/2] Android: Add Install WAD to menu_game_grid --- .../dolphinemu/dolphinemu/NativeLibrary.java | 2 ++ .../features/settings/ui/SettingsAdapter.java | 3 +++ .../dolphinemu/ui/main/MainActivity.java | 15 +++++++++++++++ .../dolphinemu/ui/main/MainPresenter.java | 19 +++++++++++++++++++ .../dolphinemu/ui/main/MainView.java | 2 ++ .../dolphinemu/ui/main/TvMainActivity.java | 15 +++++++++++++++ .../dolphinemu/utils/FileBrowserHelper.java | 3 +++ .../app/src/main/res/menu/menu_game_grid.xml | 12 +++++++++--- .../app/src/main/res/values/strings.xml | 4 ++++ Source/Android/jni/MainAndroid.cpp | 9 +++++++++ 10 files changed, 81 insertions(+), 3 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index f04fee5c67..89ded1289d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -447,6 +447,8 @@ public final class NativeLibrary public static native void ReloadWiimoteConfig(); + public static native boolean InstallWAD(String file); + private static boolean alertResult = false; public static boolean displayAlertMsg(final String caption, final String text, diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index 30e410bb5b..001bba3b5e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -322,6 +322,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter RAW_EXTENSION = new HashSet<>(Collections.singletonList( "raw")); + public static final HashSet WAD_EXTENSION = new HashSet<>(Collections.singletonList( + "wad")); + public static void openDirectoryPicker(FragmentActivity activity, HashSet extensions) { Intent i = new Intent(activity, CustomFilePickerActivity.class); diff --git a/Source/Android/app/src/main/res/menu/menu_game_grid.xml b/Source/Android/app/src/main/res/menu/menu_game_grid.xml index 72facc4eaa..43b835b294 100644 --- a/Source/Android/app/src/main/res/menu/menu_game_grid.xml +++ b/Source/Android/app/src/main/res/menu/menu_game_grid.xml @@ -31,10 +31,16 @@ android:title="@string/grid_menu_refresh" android:icon="@drawable/ic_refresh" app:showAsAction="ifRoom"/> + + android:title="@string/grid_menu_open_file" + app:showAsAction="ifRoom"/> - \ No newline at end of file + + + diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 74a6399d27..c508beb4c6 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -288,6 +288,10 @@ GameCube Input Wii Input Refresh Library + Open File + Install WAD + Successfully installed this title to the NAND. + Failed to install this title to the NAND. Add Folder to Library diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 122f3fd6d9..adcba61345 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -43,6 +43,7 @@ #include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/Profiler.h" #include "Core/State.h" +#include "Core/WiiUtils.h" #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" @@ -733,6 +734,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(J Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); }); } +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_InstallWAD(JNIEnv* env, + jobject obj, + jstring jFile) +{ + const std::string path = GetJString(env, jFile); + return static_cast(WiiUtils::InstallWAD(path)); +} + #ifdef __cplusplus } #endif From c5c080b235bec64afe1379290ae538a532aaae95 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Thu, 23 Apr 2020 19:31:41 -0400 Subject: [PATCH 2/2] Android: Run installWAD on separate thread --- .../dolphinemu/dolphinemu/NativeLibrary.java | 2 +- .../fragments/EmulationFragment.java | 6 ++-- .../dolphinemu/ui/main/MainPresenter.java | 33 +++++++++++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 89ded1289d..f37169ddee 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -511,7 +511,7 @@ public final class NativeLibrary } // Show the AlertDialog on the main thread. - emulationActivity.runOnUiThread(() -> builder.show()); + emulationActivity.runOnUiThread(builder::show); // Wait for the lock to notify that it is complete. synchronized (lock) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java index 881fd3c554..ebb4dd48ef 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java @@ -262,7 +262,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C } private final String[] mGamePaths; - private Thread mEmulationThread; private State state; private Surface mSurface; private boolean mRunWhenSurfaceIsValid; @@ -399,7 +398,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C mRunWhenSurfaceIsValid = false; if (state == State.STOPPED) { - mEmulationThread = new Thread(() -> + Thread emulationThread = new Thread(() -> { NativeLibrary.SurfaceChanged(mSurface); if (loadPreviousTemporaryState) @@ -413,8 +412,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C NativeLibrary.Run(mGamePaths); } }, "NativeEmulation"); - mEmulationThread.start(); - + emulationThread.start(); } else if (state == State.PAUSED) { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index f7cb972624..b107f415d6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -1,11 +1,13 @@ package org.dolphinemu.dolphinemu.ui.main; +import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.widget.Toast; +import androidx.appcompat.app.AlertDialog; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import org.dolphinemu.dolphinemu.BuildConfig; @@ -121,13 +123,30 @@ public final class MainPresenter public void installWAD(String file) { - if (NativeLibrary.InstallWAD(file)) + final Activity mainPresenterActivity = (Activity) mContext; + + AlertDialog dialog = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase).create(); + dialog.setTitle("Installing WAD"); + dialog.setMessage("Installing..."); + dialog.setCancelable(false); + dialog.show(); + + Thread installWADThread = new Thread(() -> { - Toast.makeText(mContext, R.string.wad_install_success, Toast.LENGTH_SHORT).show(); - } - else - { - Toast.makeText(mContext, R.string.wad_install_failure, Toast.LENGTH_SHORT).show(); - } + if (NativeLibrary.InstallWAD(file)) + { + mainPresenterActivity.runOnUiThread( + () -> Toast.makeText(mContext, R.string.wad_install_success, Toast.LENGTH_SHORT) + .show()); + } + else + { + mainPresenterActivity.runOnUiThread( + () -> Toast.makeText(mContext, R.string.wad_install_failure, Toast.LENGTH_SHORT) + .show()); + } + mainPresenterActivity.runOnUiThread(dialog::dismiss); + }, "InstallWAD"); + installWADThread.start(); } }