Merge pull request #9653 from JosJuice/android-import-nand

Android: Add "Import BootMii NAND Backup"
This commit is contained in:
Léo Lam 2021-04-19 21:57:40 +02:00 committed by GitHub
commit cf80ed7f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 4 deletions

View File

@ -226,6 +226,11 @@ public final class MainActivity extends AppCompatActivity
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

View File

@ -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;
@ -119,6 +120,11 @@ public final class MainPresenter
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;
@ -184,7 +190,7 @@ public final class MainPresenter
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;
@ -198,7 +204,7 @@ public final class MainPresenter
CompletableFuture<Boolean> canOverwriteFuture = new CompletableFuture<>();
runOnThreadAndShowResult(R.string.import_in_progress, () ->
runOnThreadAndShowResult(R.string.import_in_progress, 0, () ->
{
BooleanSupplier canOverwrite = () ->
{
@ -248,13 +254,38 @@ public final class MainPresenter
});
}
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();

View File

@ -264,6 +264,11 @@ public final class TvMainActivity extends FragmentActivity
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
@ -378,6 +383,10 @@ public final class TvMainActivity extends FragmentActivity
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));

View File

@ -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);
}

View File

@ -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>

View File

@ -336,7 +336,9 @@
<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>
@ -344,6 +346,7 @@
<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>

View File

@ -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)
@ -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 "";
});
}
}