Merge pull request #8836 from Ebola16/REC

Android: Add recursive game paths to UI
This commit is contained in:
Tilka 2020-06-14 12:16:08 +01:00 committed by GitHub
commit 63c53ebc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 97 additions and 48 deletions

View File

@ -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<String> modifiedSettings)
{
if (TextUtils.isEmpty(gameId))
{
@ -183,6 +186,8 @@ public class Settings
SettingsFile.saveFile(fileName, iniSections, view);
}
if (modifiedSettings.contains(SettingsFile.KEY_DSP_ENGINE))
{
switch (NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
SettingsFile.KEY_DSP_ENGINE, DSP_HLE))
@ -191,7 +196,8 @@ public class Settings
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,
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
SettingsFile.KEY_DSP_ENABLE_JIT, "True");
break;
@ -199,7 +205,8 @@ public class Settings
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,
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
SettingsFile.KEY_DSP_ENABLE_JIT, "True");
break;
@ -207,14 +214,24 @@ public class Settings
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,
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
{

View File

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

View File

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

View File

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

View File

@ -182,7 +182,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mView.putSetting(new BooleanSetting(item.getKey(), item.getSection(), !checked));
}
mView.onSettingChanged();
mView.onSettingChanged(item.getKey());
}
public void onSingleChoiceClick(SingleChoiceSetting item, int position)
@ -294,7 +294,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mView.putSetting(setting);
}
mView.onSettingChanged();
mView.onSettingChanged(item.getKey());
});
dialog.setCanceledOnTouchOutside(false);
dialog.show();
@ -366,7 +366,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
sView.putSetting(resourcePackPath);
sView.putSetting(sdPath);
sView.onSettingChanged();
sView.onSettingChanged(null);
}
@Override
@ -378,7 +378,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
int value = getValueForSingleChoiceSelection(scSetting, which);
if (scSetting.getSelectedValue() != value)
mView.onSettingChanged();
mView.onSettingChanged(mClickedItem.getKey());
MenuTag menuTag = scSetting.getMenuTag();
if (menuTag != null)
@ -434,7 +434,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
int value = getValueForSingleChoiceDynamicDescriptionsSelection(scSetting, which);
if (scSetting.getSelectedValue() != value)
mView.onSettingChanged();
mView.onSettingChanged(mClickedItem.getKey());
// Get the backing Setting, which may be null (if for example it was missing from the file)
IntSetting setting = scSetting.setSelectedValue(value);
@ -450,7 +450,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
StringSingleChoiceSetting scSetting = (StringSingleChoiceSetting) mClickedItem;
String value = scSetting.getValueAt(which);
if (!scSetting.getSelectedValue().equals(value))
mView.onSettingChanged();
mView.onSettingChanged(mClickedItem.getKey());
StringSetting setting = scSetting.setSelectedValue(value);
if (setting != null)
@ -464,7 +464,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
{
SliderSetting sliderSetting = (SliderSetting) mClickedItem;
if (sliderSetting.getSelectedValue() != mSeekbarProgress)
mView.onSettingChanged();
mView.onSettingChanged(mClickedItem.getKey());
if (sliderSetting.isPercentSetting() || sliderSetting.getSetting() instanceof FloatSetting)
{

View File

@ -197,9 +197,9 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
}
@Override
public void onSettingChanged()
public void onSettingChanged(String key)
{
mActivity.onSettingChanged();
mActivity.onSettingChanged(key);
}
@Override

View File

@ -317,6 +317,7 @@ public final class SettingsFragmentPresenter
private void addPathsSettings(ArrayList<SettingsItem> 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,8 @@ 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, 0, 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));

View File

@ -73,8 +73,10 @@ public interface SettingsFragmentView
/**
* Have the fragment tell the containing Activity that a setting was modified.
*
* @param key Key of the modified setting, potentially null for multiple settings.
*/
void onSettingChanged();
void onSettingChanged(String key);
/**
* Have the fragment tell the containing Activity that a GCPad's setting was modified.

View File

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

View File

@ -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<String> 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();

View File

@ -165,6 +165,7 @@
<!-- Path Settings -->
<string name="paths_submenu">Paths</string>
<string name="search_subfolders">Search Subfolders for Game Files</string>
<string name="default_ISO">Default ISO</string>
<string name="wii_NAND_root">Wii NAND Root</string>
<string name="dump_path">Dump Path</string>

View File

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