Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8748 from Ebola16/WAD
Android: Add Install WAD to menu_game_grid
  • Loading branch information
leoetlino committed Apr 27, 2020
2 parents 75e79ec + c5c080b commit b175e9e
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 8 deletions.
Expand Up @@ -447,6 +447,8 @@ public static native String GetConfig(String configFile, String Section, String

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,
Expand Down Expand Up @@ -509,7 +511,7 @@ public static boolean displayAlertMsg(final String caption, final String text,
}

// 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)
Expand Down
Expand Up @@ -322,6 +322,9 @@ public void onFilePickerFileClick(SettingsItem item)
case MainPresenter.REQUEST_GAME_FILE:
extensions = FileBrowserHelper.GAME_EXTENSIONS;
break;
case MainPresenter.REQUEST_WAD_FILE:
extensions = FileBrowserHelper.WAD_EXTENSION;
break;
default:
throw new InvalidParameterException("Unhandled request code");
}
Expand Down
Expand Up @@ -262,7 +262,6 @@ public boolean isConfiguringControls()
}

private final String[] mGamePaths;
private Thread mEmulationThread;
private State state;
private Surface mSurface;
private boolean mRunWhenSurfaceIsValid;
Expand Down Expand Up @@ -399,7 +398,7 @@ private void runWithValidSurface()
mRunWhenSurfaceIsValid = false;
if (state == State.STOPPED)
{
mEmulationThread = new Thread(() ->
Thread emulationThread = new Thread(() ->
{
NativeLibrary.SurfaceChanged(mSurface);
if (loadPreviousTemporaryState)
Expand All @@ -413,8 +412,7 @@ private void runWithValidSurface()
NativeLibrary.Run(mGamePaths);
}
}, "NativeEmulation");
mEmulationThread.start();

emulationThread.start();
}
else if (state == State.PAUSED)
{
Expand Down
Expand Up @@ -155,6 +155,13 @@ public void launchOpenFileActivity()
FileBrowserHelper.GAME_EXTENSIONS);
}

@Override
public void launchInstallWAD()
{
FileBrowserHelper.openFilePicker(this, MainPresenter.REQUEST_WAD_FILE, false,
FileBrowserHelper.WAD_EXTENSION);
}

/**
* @param requestCode An int describing whether the Activity that is returning did so successfully.
* @param resultCode An int describing what Activity is giving us this callback.
Expand All @@ -181,6 +188,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
EmulationActivity.launchFile(this, FileBrowserHelper.getSelectedFiles(result));
}
break;

case MainPresenter.REQUEST_WAD_FILE:
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
mPresenter.installWAD(FileBrowserHelper.getSelectedPath(result));
}
break;
}
}

Expand Down
@@ -1,13 +1,17 @@
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;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.model.GameFileCache;
Expand All @@ -18,6 +22,7 @@
public static final int REQUEST_DIRECTORY = 1;
public static final int REQUEST_GAME_FILE = 2;
public static final int REQUEST_SD_FILE = 3;
public static final int REQUEST_WAD_FILE = 4;

private final MainView mView;
private final Context mContext;
Expand Down Expand Up @@ -92,6 +97,10 @@ public boolean handleOptionSelection(int itemId, Context context)
case R.id.menu_open_file:
mView.launchOpenFileActivity();
return true;

case R.id.menu_install_wad:
mView.launchInstallWAD();
return true;
}

return false;
Expand All @@ -111,4 +120,33 @@ public void onDirectorySelected(String dir)
{
mDirToAdd = dir;
}

public void installWAD(String 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(() ->
{
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();
}
}
Expand Up @@ -23,6 +23,8 @@

void launchOpenFileActivity();

void launchInstallWAD();

/**
* To be called when the game file cache is updated.
*/
Expand Down
Expand Up @@ -150,6 +150,13 @@ public void launchOpenFileActivity()
FileBrowserHelper.GAME_EXTENSIONS);
}

@Override
public void launchInstallWAD()
{
FileBrowserHelper.openFilePicker(this, MainPresenter.REQUEST_WAD_FILE, false,
FileBrowserHelper.WAD_EXTENSION);
}

@Override
public void showGames()
{
Expand Down Expand Up @@ -187,6 +194,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
EmulationActivity.launchFile(this, FileBrowserHelper.getSelectedFiles(result));
}
break;

case MainPresenter.REQUEST_WAD_FILE:
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
mPresenter.installWAD(FileBrowserHelper.getSelectedPath(result));
}
break;
}
}

Expand Down
Expand Up @@ -27,6 +27,9 @@
public static final HashSet<String> RAW_EXTENSION = new HashSet<>(Collections.singletonList(
"raw"));

public static final HashSet<String> WAD_EXTENSION = new HashSet<>(Collections.singletonList(
"wad"));

public static void openDirectoryPicker(FragmentActivity activity, HashSet<String> extensions)
{
Intent i = new Intent(activity, CustomFilePickerActivity.class);
Expand Down
12 changes: 9 additions & 3 deletions Source/Android/app/src/main/res/menu/menu_game_grid.xml
Expand Up @@ -31,10 +31,16 @@
android:title="@string/grid_menu_refresh"
android:icon="@drawable/ic_refresh"
app:showAsAction="ifRoom"/>

<item
android:id="@+id/menu_open_file"
android:icon="@android:drawable/ic_media_play"
android:title="Open File"
app:showAsAction="ifRoom" />
android:title="@string/grid_menu_open_file"
app:showAsAction="ifRoom"/>

<item
android:id="@+id/menu_install_wad"
android:title="@string/grid_menu_install_wad"
app:showAsAction="never"/>

</menu>
</menu>
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -288,6 +288,10 @@
<string name="grid_menu_gcpad_settings">GameCube Input</string>
<string name="grid_menu_wiimote_settings">Wii Input</string>
<string name="grid_menu_refresh">Refresh Library</string>
<string name="grid_menu_open_file">Open File</string>
<string name="grid_menu_install_wad">Install WAD</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>

<!-- Add Directory Screen-->
<string name="add_directory_title">Add Folder to Library</string>
Expand Down
9 changes: 9 additions & 0 deletions Source/Android/jni/MainAndroid.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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<jboolean>(WiiUtils::InstallWAD(path));
}

#ifdef __cplusplus
}
#endif

0 comments on commit b175e9e

Please sign in to comment.