From 77f539355da7efd5d8cfcd8620f801b8277bc8ff Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Sun, 31 May 2020 10:00:09 -0400 Subject: [PATCH 1/2] Android: Add recursive game paths to UI --- .../settings/ui/SettingsFragmentPresenter.java | 5 +++++ .../features/settings/utils/SettingsFile.java | 1 + .../dolphinemu/dolphinemu/model/GameFileCache.java | 12 ++++++++++-- Source/Android/app/src/main/res/values/strings.xml | 2 ++ Source/Android/jni/GameList/GameFileCache.cpp | 7 ++++--- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index d65a3f28f8..b6a1094f18 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -317,6 +317,7 @@ public final class SettingsFragmentPresenter private void addPathsSettings(ArrayList sl) { + Setting recursiveISOPaths = null; Setting defaultISO = null; Setting NANDRootPath = null; Setting dumpPath = null; @@ -326,6 +327,7 @@ public final class SettingsFragmentPresenter SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE); SettingSection generalSection = mSettings.getSection(Settings.SECTION_INI_GENERAL); + recursiveISOPaths = generalSection.getSetting(SettingsFile.KEY_RECURSIVE_ISO_PATHS); defaultISO = coreSection.getSetting(SettingsFile.KEY_DEFAULT_ISO); NANDRootPath = generalSection.getSetting(SettingsFile.KEY_NAND_ROOT_PATH); dumpPath = generalSection.getSetting(SettingsFile.KEY_DUMP_PATH); @@ -333,6 +335,9 @@ public final class SettingsFragmentPresenter resourcePackPath = generalSection.getSetting(SettingsFile.KEY_RESOURCE_PACK_PATH); wiiSDCardPath = generalSection.getSetting(SettingsFile.KEY_WII_SD_CARD_PATH); + sl.add(new CheckBoxSetting(SettingsFile.KEY_RECURSIVE_ISO_PATHS, Settings.SECTION_INI_GENERAL, + R.string.search_subfolders, R.string.search_subfolders_description, false, + recursiveISOPaths)); sl.add(new FilePicker(SettingsFile.FILE_NAME_DOLPHIN, SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE, R.string.default_ISO, 0, "", MainPresenter.REQUEST_GAME_FILE, defaultISO)); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java index bb47068d9a..e032e03d02 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java @@ -59,6 +59,7 @@ public final class SettingsFile public static final String KEY_SLOT_A_DEVICE = "SlotA"; public static final String KEY_SLOT_B_DEVICE = "SlotB"; public static final String KEY_ENABLE_SAVE_STATES = "EnableSaveStates"; + public static final String KEY_RECURSIVE_ISO_PATHS = "RecursiveISOPaths"; public static final String KEY_DEFAULT_ISO = "DefaultISO"; public static final String KEY_NAND_ROOT_PATH = "NANDRootPath"; public static final String KEY_DUMP_PATH = "DumpPath"; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java index 87837f5464..ec574ffaa4 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java @@ -4,6 +4,10 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import org.dolphinemu.dolphinemu.NativeLibrary; +import org.dolphinemu.dolphinemu.features.settings.model.Settings; +import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; + import java.io.File; import java.util.HashSet; import java.util.Set; @@ -66,13 +70,17 @@ public class GameFileCache */ public boolean scanLibrary(Context context) { + boolean recursiveScan = NativeLibrary + .GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_GENERAL, + SettingsFile.KEY_RECURSIVE_ISO_PATHS, "False").equals("True"); + removeNonExistentGameFolders(context); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); Set folderPathsSet = preferences.getStringSet(GAME_FOLDER_PATHS_PREFERENCE, EMPTY_SET); String[] folderPaths = folderPathsSet.toArray(new String[folderPathsSet.size()]); - boolean cacheChanged = update(folderPaths); + boolean cacheChanged = update(folderPaths, recursiveScan); cacheChanged |= updateAdditionalMetadata(); if (cacheChanged) { @@ -85,7 +93,7 @@ public class GameFileCache public native GameFile addOrGet(String gamePath); - private native boolean update(String[] folderPaths); + private native boolean update(String[] folderPaths, boolean recursiveScan); private native boolean updateAdditionalMetadata(); diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 082f296a74..12dca985e3 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -164,6 +164,8 @@ Paths + Search Subfolders for Game Files + Refresh library after changing this setting. Default ISO Wii NAND Root Dump Path diff --git a/Source/Android/jni/GameList/GameFileCache.cpp b/Source/Android/jni/GameList/GameFileCache.cpp index 4b3abf8c2f..1e5c6a28c1 100644 --- a/Source/Android/jni/GameList/GameFileCache.cpp +++ b/Source/Android/jni/GameList/GameFileCache.cpp @@ -37,7 +37,7 @@ JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_add jobject obj, jstring path); JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update( - JNIEnv* env, jobject obj, jobjectArray folder_paths); + JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan); JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env, jobject obj); @@ -80,7 +80,7 @@ JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_add } JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update( - JNIEnv* env, jobject obj, jobjectArray folder_paths) + JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan) { jsize size = env->GetArrayLength(folder_paths); @@ -94,7 +94,8 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_up env->DeleteLocalRef(path); } - return GetPointer(env, obj)->Update(UICommon::FindAllGamePaths(folder_paths_vector, false)); + return GetPointer(env, obj)->Update( + UICommon::FindAllGamePaths(folder_paths_vector, recursive_scan)); } JNIEXPORT jboolean JNICALL From 9ea8f297655b25949026a92cc8c51a591a47eb62 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Mon, 1 Jun 2020 07:43:19 -0400 Subject: [PATCH 2/2] Android: Conditionally respond to modified settings --- .../features/settings/model/Settings.java | 67 ++++++++++++------- .../settings/ui/SettingsActivity.java | 6 +- .../ui/SettingsActivityPresenter.java | 21 ++++-- .../settings/ui/SettingsActivityView.java | 4 +- .../features/settings/ui/SettingsAdapter.java | 14 ++-- .../settings/ui/SettingsFragment.java | 4 +- .../ui/SettingsFragmentPresenter.java | 3 +- .../settings/ui/SettingsFragmentView.java | 4 +- .../app/src/main/res/values/strings.xml | 1 - 9 files changed, 78 insertions(+), 46 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java index b0ffbb1dc9..df0dd985ab 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java @@ -1,15 +1,18 @@ package org.dolphinemu.dolphinemu.features.settings.model; +import android.content.Context; import android.text.TextUtils; import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView; import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; +import org.dolphinemu.dolphinemu.services.GameFileCacheService; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; public class Settings @@ -164,7 +167,7 @@ public class Settings loadSettings(view); } - public void saveSettings(SettingsActivityView view) + public void saveSettings(SettingsActivityView view, Context context, Set modifiedSettings) { if (TextUtils.isEmpty(gameId)) { @@ -183,38 +186,52 @@ public class Settings SettingsFile.saveFile(fileName, iniSections, view); } - switch (NativeLibrary - .GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENGINE, DSP_HLE)) + if (modifiedSettings.contains(SettingsFile.KEY_DSP_ENGINE)) { - case DSP_HLE: - NativeLibrary - .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, - SettingsFile.KEY_DSP_HLE, "True"); - NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENABLE_JIT, "True"); - break; + switch (NativeLibrary + .GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENGINE, DSP_HLE)) + { + case DSP_HLE: + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, + SettingsFile.KEY_DSP_HLE, "True"); + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENABLE_JIT, "True"); + break; - case DSP_LLE_RECOMPILER: - NativeLibrary - .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, - SettingsFile.KEY_DSP_HLE, "False"); - NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENABLE_JIT, "True"); - break; + case DSP_LLE_RECOMPILER: + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, + SettingsFile.KEY_DSP_HLE, "False"); + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENABLE_JIT, "True"); + break; - case DSP_LLE_INTERPRETER: - NativeLibrary - .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, - SettingsFile.KEY_DSP_HLE, "False"); - NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENABLE_JIT, "False"); - break; + case DSP_LLE_INTERPRETER: + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, + SettingsFile.KEY_DSP_HLE, "False"); + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENABLE_JIT, "False"); + break; + } } // Notify the native code of the changes NativeLibrary.ReloadConfig(); NativeLibrary.ReloadWiimoteConfig(); + + if (modifiedSettings.contains(SettingsFile.KEY_RECURSIVE_ISO_PATHS)) + { + // Refresh game library + GameFileCacheService.startRescan(context); + } + + modifiedSettings.clear(); } else { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java index e34460f532..947a5d9722 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java @@ -51,7 +51,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting Intent launcher = getIntent(); String gameID = launcher.getStringExtra(ARG_GAME_ID); MenuTag menuTag = (MenuTag) launcher.getSerializableExtra(ARG_MENU_TAG); - mPresenter.onCreate(savedInstanceState, menuTag, gameID); + mPresenter.onCreate(savedInstanceState, menuTag, gameID, getApplicationContext()); } @Override @@ -275,9 +275,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting } @Override - public void onSettingChanged() + public void onSettingChanged(String key) { - mPresenter.onSettingChanged(); + mPresenter.onSettingChanged(key); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java index 77ce9cee9c..a66391d8bb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java @@ -1,5 +1,6 @@ package org.dolphinemu.dolphinemu.features.settings.ui; +import android.content.Context; import android.content.IntentFilter; import android.os.Bundle; import android.text.TextUtils; @@ -11,6 +12,9 @@ import org.dolphinemu.dolphinemu.utils.DirectoryInitialization.DirectoryInitiali import org.dolphinemu.dolphinemu.utils.DirectoryStateReceiver; import org.dolphinemu.dolphinemu.utils.Log; +import java.util.HashSet; +import java.util.Set; + public final class SettingsActivityPresenter { private static final String KEY_SHOULD_SAVE = "should_save"; @@ -27,18 +31,22 @@ public final class SettingsActivityPresenter private MenuTag menuTag; private String gameId; + private Context context; + + private final Set modifiedSettings = new HashSet<>(); SettingsActivityPresenter(SettingsActivityView view) { mView = view; } - public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId) + public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId, Context context) { if (savedInstanceState == null) { this.menuTag = menuTag; this.gameId = gameId; + this.context = context; } else { @@ -126,7 +134,7 @@ public final class SettingsActivityPresenter public void clearSettings() { mSettings.clearSettings(); - onSettingChanged(); + onSettingChanged(null); } public void onStop(boolean finishing) @@ -140,7 +148,7 @@ public final class SettingsActivityPresenter if (mSettings != null && finishing && mShouldSave) { Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI..."); - mSettings.saveSettings(mView); + mSettings.saveSettings(mView, context, modifiedSettings); } } @@ -174,8 +182,13 @@ public final class SettingsActivityPresenter return false; } - public void onSettingChanged() + public void onSettingChanged(String key) { + if (key != null) + { + modifiedSettings.add(key); + } + mShouldSave = true; } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java index 71583aa989..3ad0c6b9cd 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java @@ -69,8 +69,10 @@ public interface SettingsActivityView /** * Called by a containing Fragment to tell the Activity that a setting was changed; * unless this has been called, the Activity will not save to disk. + * + * @param key Key of the modified setting. */ - void onSettingChanged(); + void onSettingChanged(String key); /** * Called by a containing Fragment to tell the containing Activity that a GCPad's setting 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 2c2e009a44..e13eb36eb6 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 @@ -182,7 +182,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter Paths Search Subfolders for Game Files - Refresh library after changing this setting. Default ISO Wii NAND Root Dump Path