Skip to content

Commit

Permalink
Android: Add "Import BootMii NAND Backup"
Browse files Browse the repository at this point in the history
  • Loading branch information
JosJuice committed Apr 19, 2021
1 parent 5322256 commit ceacd09
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
Expand Up @@ -226,6 +226,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
FileBrowserHelper.runAfterExtensionCheck(this, uri, FileBrowserHelper.BIN_EXTENSION,
() -> mPresenter.importWiiSave(result.getData().toString()));
break;

case MainPresenter.REQUEST_NAND_BIN_FILE:
FileBrowserHelper.runAfterExtensionCheck(this, uri, FileBrowserHelper.BIN_EXTENSION,
() -> mPresenter.importNANDBin(result.getData().toString()));
break;
}
}
else
Expand Down
Expand Up @@ -35,6 +35,7 @@ public final class MainPresenter
public static final int REQUEST_SD_FILE = 3;
public static final int REQUEST_WAD_FILE = 4;
public static final int REQUEST_WII_SAVE_FILE = 5;
public static final int REQUEST_NAND_BIN_FILE = 6;

private static boolean sShouldRescanLibrary = true;

Expand Down Expand Up @@ -119,6 +120,11 @@ public boolean handleOptionSelection(int itemId, Context context)
new AfterDirectoryInitializationRunner().run(context, true,
() -> mView.launchOpenFileActivity(REQUEST_WII_SAVE_FILE));
return true;

case R.id.menu_import_nand_backup:
new AfterDirectoryInitializationRunner().run(context, true,
() -> mView.launchOpenFileActivity(REQUEST_NAND_BIN_FILE));
return true;
}

return false;
Expand Down Expand Up @@ -184,7 +190,7 @@ public void onDirectorySelected(Intent result)

public void installWAD(String path)
{
runOnThreadAndShowResult(R.string.import_in_progress, () ->
runOnThreadAndShowResult(R.string.import_in_progress, 0, () ->
{
boolean success = WiiUtils.installWAD(path);
int message = success ? R.string.wad_install_success : R.string.wad_install_failure;
Expand All @@ -198,7 +204,7 @@ public void importWiiSave(String path)

CompletableFuture<Boolean> canOverwriteFuture = new CompletableFuture<>();

runOnThreadAndShowResult(R.string.import_in_progress, () ->
runOnThreadAndShowResult(R.string.import_in_progress, 0, () ->
{
BooleanSupplier canOverwrite = () ->
{
Expand Down Expand Up @@ -248,13 +254,38 @@ public void importWiiSave(String path)
});
}

private void runOnThreadAndShowResult(int progressMessage, Supplier<String> f)
public void importNANDBin(String path)
{
AlertDialog.Builder builder =
new AlertDialog.Builder(mContext, R.style.DolphinDialogBase);

builder.setMessage(R.string.nand_import_warning);
builder.setNegativeButton(R.string.no, (dialog, i) -> dialog.dismiss());
builder.setPositiveButton(R.string.yes, (dialog, i) ->
{
dialog.dismiss();

runOnThreadAndShowResult(R.string.import_in_progress, R.string.do_not_close_app, () ->
{
// ImportNANDBin doesn't provide any result value, unfortunately...
// It does however show a panic alert if something goes wrong.
WiiUtils.importNANDBin(path);
return null;
});
});

builder.show();
}

private void runOnThreadAndShowResult(int progressTitle, int progressMessage, Supplier<String> f)
{
final Activity mainPresenterActivity = (Activity) mContext;

AlertDialog progressDialog = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase)
.create();
progressDialog.setTitle(progressMessage);
progressDialog.setTitle(progressTitle);
if (progressMessage != 0)
progressDialog.setMessage(mContext.getResources().getString(progressMessage));
progressDialog.setCancelable(false);
progressDialog.show();

Expand Down
Expand Up @@ -264,6 +264,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
FileBrowserHelper.runAfterExtensionCheck(this, uri, FileBrowserHelper.BIN_EXTENSION,
() -> mPresenter.importWiiSave(result.getData().toString()));
break;

case MainPresenter.REQUEST_NAND_BIN_FILE:
FileBrowserHelper.runAfterExtensionCheck(this, uri, FileBrowserHelper.BIN_EXTENSION,
() -> mPresenter.importNANDBin(result.getData().toString()));
break;
}
}
else
Expand Down Expand Up @@ -378,6 +383,10 @@ private ListRow buildSettingsRow()
R.drawable.ic_folder,
R.string.grid_menu_import_wii_save));

rowItems.add(new TvSettingsItem(R.id.menu_import_nand_backup,
R.drawable.ic_folder,
R.string.grid_menu_import_nand_backup));

// Create a header for this row.
HeaderItem header =
new HeaderItem(R.string.preferences_settings, getString(R.string.preferences_settings));
Expand Down
Expand Up @@ -11,4 +11,6 @@ public final class WiiUtils
public static native boolean installWAD(String file);

public static native int importWiiSave(String file, BooleanSupplier canOverwrite);

public static native void importNANDBin(String file);
}
5 changes: 5 additions & 0 deletions Source/Android/app/src/main/res/menu/menu_game_grid.xml
Expand Up @@ -30,4 +30,9 @@
android:title="@string/grid_menu_import_wii_save"
app:showAsAction="never"/>

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

</menu>
3 changes: 3 additions & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -336,14 +336,17 @@
<string name="grid_menu_open_file">Open File</string>
<string name="grid_menu_install_wad">Install WAD</string>
<string name="grid_menu_import_wii_save">Import Wii Save</string>
<string name="grid_menu_import_nand_backup">Import BootMii NAND Backup</string>
<string name="import_in_progress">Importing...</string>
<string name="do_not_close_app">Do not close the app!</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>
<string name="wii_save_import_title_missing">Failed to import save file. Please launch the game once, then try again.</string>
<string name="nand_import_warning">Merging a new NAND over your currently selected NAND will overwrite any channels and savegames that already exist. This process is not reversible, so it is recommended that you keep backups of both NANDs. Are you sure you want to continue?</string>

<!-- Game Properties Screen -->
<string name="properties_details">Details</string>
Expand Down
23 changes: 23 additions & 0 deletions Source/Android/jni/WiiUtils.cpp
Expand Up @@ -11,6 +11,7 @@

#include "Core/HW/WiiSave.h"
#include "Core/WiiUtils.h"
#include "DiscIO/NANDImporter.h"

// The hardcoded values here must match WiiUtils.java
static jint ConvertCopyResult(WiiSave::CopyResult result)
Expand Down Expand Up @@ -56,4 +57,26 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_importWiiSa

return ConvertCopyResult(WiiSave::Import(path, can_overwrite));
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_importNANDBin(JNIEnv* env,
jclass,
jstring jFile)
{
const std::string path = GetJString(env, jFile);

return DiscIO::NANDImporter().ImportNANDBin(
path,
[] {
// This callback gets called every now and then in case we want to update the GUI. However,
// we have no way of knowing what the current progress is, so we can't do anything
// especially useful. DolphinQt chooses to show the elapsed time, for reference.
},
[] {
// This callback gets called if the NAND file does not have decryption keys appended to it.
// We're supposed to ask the user for a separate file containing keys, but this is probably
// more work to implement on Android than it's worth, as this case almost never comes up.
PanicAlertFmtT("The decryption keys need to be appended to the NAND backup file.");
return "";
});
}
}

0 comments on commit ceacd09

Please sign in to comment.