Skip to content
Permalink
Browse files
Merge pull request #8836 from Ebola16/REC
Android: Add recursive game paths to UI
  • Loading branch information
Tilka committed Jun 14, 2020
2 parents cb54fc7 + 9ea8f29 commit 63c53eb
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 50 deletions.
@@ -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 void loadSettings(String gameId, SettingsActivityView view)
loadSettings(view);
}

public void saveSettings(SettingsActivityView view)
public void saveSettings(SettingsActivityView view, Context context, Set<String> modifiedSettings)
{
if (TextUtils.isEmpty(gameId))
{
@@ -183,38 +186,52 @@ public void saveSettings(SettingsActivityView view)
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;

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;
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_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
{
@@ -51,7 +51,7 @@ protected void onCreate(Bundle savedInstanceState)
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 void popBackStack()
}

@Override
public void onSettingChanged()
public void onSettingChanged(String key)
{
mPresenter.onSettingChanged();
mPresenter.onSettingChanged(key);
}

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

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 Settings getSettings()
public void clearSettings()
{
mSettings.clearSettings();
onSettingChanged();
onSettingChanged(null);
}

public void onStop(boolean finishing)
@@ -140,7 +148,7 @@ public void onStop(boolean finishing)
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 boolean handleOptionsItem(int itemId)
return false;
}

public void onSettingChanged()
public void onSettingChanged(String key)
{
if (key != null)
{
modifiedSettings.add(key);
}

mShouldSave = true;
}

@@ -69,8 +69,10 @@
/**
* 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
@@ -182,7 +182,7 @@ public void onBooleanClick(CheckBoxSetting item, int position, boolean checked)
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 void onInputBindingClick(final InputBindingSetting item, final int positi
mView.putSetting(setting);
}

mView.onSettingChanged();
mView.onSettingChanged(item.getKey());
});
dialog.setCanceledOnTouchOutside(false);
dialog.show();
@@ -366,7 +366,7 @@ public static void resetPaths()
sView.putSetting(resourcePackPath);
sView.putSetting(sdPath);

sView.onSettingChanged();
sView.onSettingChanged(null);
}

@Override
@@ -378,7 +378,7 @@ public void onClick(DialogInterface dialog, int which)

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 @@ else if (mClickedItem instanceof SingleChoiceSettingDynamicDescriptions)

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 @@ else if (mClickedItem instanceof StringSingleChoiceSetting)
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 @@ else if (mClickedItem instanceof SliderSetting)
{
SliderSetting sliderSetting = (SliderSetting) mClickedItem;
if (sliderSetting.getSelectedValue() != mSeekbarProgress)
mView.onSettingChanged();
mView.onSettingChanged(mClickedItem.getKey());

if (sliderSetting.isPercentSetting() || sliderSetting.getSetting() instanceof FloatSetting)
{
@@ -197,9 +197,9 @@ public void putSetting(Setting setting)
}

@Override
public void onSettingChanged()
public void onSettingChanged(String key)
{
mActivity.onSettingChanged();
mActivity.onSettingChanged(key);
}

@Override
@@ -317,6 +317,7 @@ private void addAudioSettings(ArrayList<SettingsItem> sl)

private void addPathsSettings(ArrayList<SettingsItem> sl)
{
Setting recursiveISOPaths = null;
Setting defaultISO = null;
Setting NANDRootPath = null;
Setting dumpPath = null;
@@ -326,13 +327,16 @@ private void addPathsSettings(ArrayList<SettingsItem> sl)

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);
loadPath = generalSection.getSetting(SettingsFile.KEY_LOAD_PATH);
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));
@@ -73,8 +73,10 @@

/**
* 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.
@@ -59,6 +59,7 @@
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";
@@ -4,6 +4,10 @@
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 @@ private void removeNonExistentGameFolders(Context context)
*/
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 boolean scanLibrary(Context context)

public native GameFile addOrGet(String gamePath);

private native boolean update(String[] folderPaths);
private native boolean update(String[] folderPaths, boolean recursiveScan);

private native boolean updateAdditionalMetadata();

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

0 comments on commit 63c53eb

Please sign in to comment.