diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java index 0bdccda214..00d98643b8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java @@ -21,6 +21,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.StringSetting; import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity; import org.dolphinemu.dolphinemu.model.GameFile; +import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.utils.AlertDialogItemsBuilder; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; @@ -101,6 +102,12 @@ public class GamePropertiesDialog extends DialogFragment ConvertActivity.launch(getContext(), path)); } + if (isDisc && isWii) + { + itemsBuilder.add(R.string.properties_system_update, (dialog, i) -> + MainPresenter.launchDiscUpdate(path, requireActivity())); + } + itemsBuilder.add(R.string.properties_edit_game_settings, (dialog, i) -> SettingsActivity.launch(getContext(), MenuTag.SETTINGS, gameId, revision, isWii)); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java index fc915e5422..dddcd204f8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java @@ -31,8 +31,8 @@ public class OnlineUpdateRegionSelectDialogFragment extends DialogFragment new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class); viewModel.setRegion(which); - OnlineUpdateProgressBarDialogFragment progressBarFragment = - new OnlineUpdateProgressBarDialogFragment(); + SystemUpdateProgressBarDialogFragment progressBarFragment = + new SystemUpdateProgressBarDialogFragment(); progressBarFragment .show(getParentFragmentManager(), "OnlineUpdateProgressBarDialogFragment"); progressBarFragment.setCancelable(false); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateProgressBarDialogFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java similarity index 82% rename from Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateProgressBarDialogFragment.java rename to Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java index adcdc8a419..2cb520552a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateProgressBarDialogFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java @@ -14,7 +14,7 @@ import androidx.lifecycle.ViewModelProvider; import org.dolphinemu.dolphinemu.R; -public class OnlineUpdateProgressBarDialogFragment extends DialogFragment +public class SystemUpdateProgressBarDialogFragment extends DialogFragment { @NonNull @Override @@ -74,7 +74,7 @@ public class OnlineUpdateProgressBarDialogFragment extends DialogFragment return; } - OnlineUpdateResultFragment progressBarFragment = new OnlineUpdateResultFragment(); + SystemUpdateResultFragment progressBarFragment = new SystemUpdateResultFragment(); progressBarFragment.show(getParentFragmentManager(), "OnlineUpdateResultFragment"); getActivity().setRequestedOrientation(orientation); @@ -84,28 +84,7 @@ public class OnlineUpdateProgressBarDialogFragment extends DialogFragment if (savedInstanceState == null) { - final String region; - int selectedItem = viewModel.getRegion(); - - switch (selectedItem) - { - case 0: - region = "EUR"; - break; - case 1: - region = "JPN"; - break; - case 2: - region = "KOR"; - break; - case 3: - region = "USA"; - break; - default: - region = ""; - break; - } - viewModel.startUpdate(region); + viewModel.startUpdate(); } return progressDialog; } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateResultFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java similarity index 98% rename from Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateResultFragment.java rename to Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java index 15a546a276..298b4ac0ed 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateResultFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java @@ -13,7 +13,7 @@ import androidx.lifecycle.ViewModelProvider; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.utils.WiiUtils; -public class OnlineUpdateResultFragment extends DialogFragment +public class SystemUpdateResultFragment extends DialogFragment { private int mResult; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateViewModel.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateViewModel.java index 3c9b13fbc7..a249b01ee7 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateViewModel.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateViewModel.java @@ -5,6 +5,7 @@ package org.dolphinemu.dolphinemu.features.sysupdate.ui; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; +import org.dolphinemu.dolphinemu.utils.WiiUpdateCallback; import org.dolphinemu.dolphinemu.utils.WiiUtils; import java.util.concurrent.ExecutorService; @@ -21,6 +22,7 @@ public class SystemUpdateViewModel extends ViewModel private boolean mCanceled = false; private int mRegion; + private String mDiscPath; public SystemUpdateViewModel() { @@ -37,6 +39,16 @@ public class SystemUpdateViewModel extends ViewModel return mRegion; } + public void setDiscPath(String discPath) + { + mDiscPath = discPath; + } + + public String getDiscPath() + { + return mDiscPath; + } + public MutableLiveData getProgressData() { return mProgressData; @@ -62,21 +74,55 @@ public class SystemUpdateViewModel extends ViewModel mCanceled = true; } - public void startUpdate(String region) + public void startUpdate() + { + if (!mDiscPath.isEmpty()) + { + startDiscUpdate(mDiscPath); + } + else + { + final String region; + switch (mRegion) + { + case 0: + region = "EUR"; + break; + case 1: + region = "JPN"; + break; + case 2: + region = "KOR"; + break; + case 3: + region = "USA"; + break; + default: + region = ""; + break; + } + startOnlineUpdate(region); + } + } + + public void startOnlineUpdate(String region) { mCanceled = false; executor.execute(() -> { - int result = WiiUtils.doOnlineUpdate(region, ((processed, total, titleId) -> - { - mProgressData.postValue(processed); - mTotalData.postValue(total); - mTitleIdData.postValue(titleId); + int result = WiiUtils.doOnlineUpdate(region, constructCallback()); + mResultData.postValue(result); + }); + } - return !mCanceled; - })); + public void startDiscUpdate(String path) + { + mCanceled = false; + executor.execute(() -> + { + int result = WiiUtils.doDiscUpdate(path, constructCallback()); mResultData.postValue(result); }); } @@ -88,5 +134,19 @@ public class SystemUpdateViewModel extends ViewModel mTitleIdData.setValue(0l); mResultData.setValue(-1); mCanceled = false; + mRegion = -1; + mDiscPath = ""; + } + + private WiiUpdateCallback constructCallback() + { + return (processed, total, titleId) -> + { + mProgressData.postValue(processed); + mTotalData.postValue(total); + mTitleIdData.postValue(titleId); + + return !mCanceled; + }; } } 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 7ec06868f3..ecc69fbaf1 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 @@ -17,7 +17,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; -import org.dolphinemu.dolphinemu.features.sysupdate.ui.OnlineUpdateProgressBarDialogFragment; +import org.dolphinemu.dolphinemu.features.sysupdate.ui.SystemUpdateProgressBarDialogFragment; import org.dolphinemu.dolphinemu.features.sysupdate.ui.SystemMenuNotInstalledDialogFragment; import org.dolphinemu.dolphinemu.features.sysupdate.ui.SystemUpdateViewModel; import org.dolphinemu.dolphinemu.model.GameFileCache; @@ -280,11 +280,7 @@ public final class MainPresenter SystemUpdateViewModel viewModel = new ViewModelProvider(mActivity).get(SystemUpdateViewModel.class); viewModel.setRegion(-1); - OnlineUpdateProgressBarDialogFragment progressBarFragment = - new OnlineUpdateProgressBarDialogFragment(); - progressBarFragment - .show(mActivity.getSupportFragmentManager(), "OnlineUpdateProgressBarDialogFragment"); - progressBarFragment.setCancelable(false); + launchUpdateProgressBarFragment(mActivity); } else { @@ -295,6 +291,23 @@ public final class MainPresenter } } + public static void launchDiscUpdate(String path, FragmentActivity activity) + { + SystemUpdateViewModel viewModel = + new ViewModelProvider(activity).get(SystemUpdateViewModel.class); + viewModel.setDiscPath(path); + launchUpdateProgressBarFragment(activity); + } + + private static void launchUpdateProgressBarFragment(FragmentActivity activity) + { + SystemUpdateProgressBarDialogFragment progressBarFragment = + new SystemUpdateProgressBarDialogFragment(); + progressBarFragment + .show(activity.getSupportFragmentManager(), "SystemUpdateProgressBarDialogFragment"); + progressBarFragment.setCancelable(false); + } + private void launchWiiSystemMenu() { WiiUtils.isSystemMenuInstalled(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/WiiUtils.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/WiiUtils.java index 42e11a67c0..44103f7483 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/WiiUtils.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/WiiUtils.java @@ -28,6 +28,8 @@ public final class WiiUtils public static native int doOnlineUpdate(String region, WiiUpdateCallback callback); + public static native int doDiscUpdate(String path, WiiUpdateCallback callback); + public static native boolean isSystemMenuInstalled(); public static native String getSystemMenuVersion(); diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 6bc37084ef..301e336481 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -433,6 +433,7 @@ Start with Riivolution Patches Set as Default ISO Convert File + Perform System Update Edit Game Settings Edit Cheats Clear Game Settings and Cheats diff --git a/Source/Android/jni/WiiUtils.cpp b/Source/Android/jni/WiiUtils.cpp index 42332feea2..08e93897e2 100644 --- a/Source/Android/jni/WiiUtils.cpp +++ b/Source/Android/jni/WiiUtils.cpp @@ -63,7 +63,7 @@ static jint ConvertUpdateResult(WiiUtils::UpdateResult result) return 8; default: ASSERT(false); - return 1; + return 7; } static_assert(static_cast(WiiUtils::UpdateResult::NumberOfEntries) == 9); @@ -132,6 +132,27 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_doOnlineUpd return ConvertUpdateResult(result); } +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_doDiscUpdate(JNIEnv* env, + jclass, + jstring jPath, + jobject jCallback) +{ + const std::string path = GetJString(env, jPath); + + jobject jCallbackGlobal = env->NewGlobalRef(jCallback); + Common::ScopeGuard scope_guard([jCallbackGlobal, env] { env->DeleteGlobalRef(jCallbackGlobal); }); + + const auto callback = [&jCallbackGlobal](int processed, int total, u64 title_id) { + JNIEnv* env = IDCache::GetEnvForThread(); + return static_cast(env->CallBooleanMethod( + jCallbackGlobal, IDCache::GetWiiUpdateCallbackFunction(), processed, total, title_id)); + }; + + WiiUtils::UpdateResult result = WiiUtils::DoDiscUpdate(callback, path); + + return ConvertUpdateResult(result); +} + JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_isSystemMenuInstalled(JNIEnv* env, jclass) {