Android: Add safeguards around skip ipl setting
A user shouldn't be able to disable "skip ipl" when they don't have a bios file. This finds the ipl file and tells the setting when toggling is allowed. Additionally, if the user previously disabled the option and then deletes their ipl file, they will be allowed to enable it but toggling will be disabled afterwards.
This commit is contained in:
parent
bbb83054af
commit
860f56150a
|
@ -54,6 +54,12 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder
|
|||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
protected static void showIplNotAvailableError()
|
||||
{
|
||||
Toast.makeText(DolphinApplication.getAppContext(), R.string.ipl_not_found, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the adapter to set this ViewHolder's child views to display the list item
|
||||
* it must now represent.
|
||||
|
|
|
@ -7,13 +7,20 @@ import android.view.View;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemSettingSwitchBinding;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SwitchSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class SwitchSettingViewHolder extends SettingViewHolder
|
||||
{
|
||||
private SwitchSetting mItem;
|
||||
private boolean iplExists = false;
|
||||
|
||||
private final ListItemSettingSwitchBinding mBinding;
|
||||
|
||||
|
@ -32,11 +39,43 @@ public final class SwitchSettingViewHolder extends SettingViewHolder
|
|||
mBinding.textSettingDescription.setText(item.getDescription());
|
||||
|
||||
mBinding.settingSwitch.setChecked(mItem.isChecked(getAdapter().getSettings()));
|
||||
mBinding.settingSwitch.setEnabled(true);
|
||||
|
||||
mBinding.settingSwitch.setEnabled(mItem.isEditable());
|
||||
// Check for IPL to make sure user can skip.
|
||||
if (mItem.getSetting() == BooleanSetting.MAIN_SKIP_IPL)
|
||||
{
|
||||
ArrayList<String> iplDirs = new ArrayList<>(Arrays.asList("USA", "JAP", "EUR"));
|
||||
for (String dir : iplDirs)
|
||||
{
|
||||
File iplFile = new File(DirectoryInitialization.getUserDirectory(),
|
||||
File.separator + "GC" + File.separator + dir + File.separator + "IPL.bin");
|
||||
if (iplFile.exists())
|
||||
{
|
||||
iplExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mItem.isChecked(getAdapter().getSettings()))
|
||||
{
|
||||
mBinding.settingSwitch.setEnabled(iplExists);
|
||||
}
|
||||
else
|
||||
{
|
||||
mBinding.settingSwitch.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
mBinding.settingSwitch.setOnCheckedChangeListener((buttonView, isChecked) ->
|
||||
{
|
||||
// If a user has skip IPL disabled previously and deleted their IPL file, we need to allow
|
||||
// them to skip it or else their game will appear broken. However, once this is enabled, we
|
||||
// need to disable the option again to prevent the same issue from occurring.
|
||||
if (mItem.getSetting() == BooleanSetting.MAIN_SKIP_IPL && !iplExists && isChecked)
|
||||
{
|
||||
mBinding.settingSwitch.setEnabled(false);
|
||||
}
|
||||
|
||||
getAdapter().onBooleanClick(mItem, mBinding.settingSwitch.isChecked());
|
||||
|
||||
setStyle(mBinding.textSettingName, mItem);
|
||||
|
@ -54,6 +93,15 @@ public final class SwitchSettingViewHolder extends SettingViewHolder
|
|||
return;
|
||||
}
|
||||
|
||||
if (mItem.getSetting() == BooleanSetting.MAIN_SKIP_IPL && !iplExists)
|
||||
{
|
||||
if (mItem.isChecked(getAdapter().getSettings()))
|
||||
{
|
||||
showIplNotAvailableError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mBinding.settingSwitch.toggle();
|
||||
}
|
||||
|
||||
|
|
|
@ -642,6 +642,7 @@ It can efficiently compress both junk data and encrypted Wii data.
|
|||
<string name="path_not_changeable_scoped_storage">Due to the Scoped Storage policy in Android 11 and newer, you can\'t change this path.</string>
|
||||
<string name="load_settings">Loading Settings…</string>
|
||||
<string name="setting_not_runtime_editable">This setting can\'t be changed while a game is running.</string>
|
||||
<string name="ipl_not_found">IPL not found</string>
|
||||
<string name="setting_clear_info">Long press a setting to clear it.</string>
|
||||
<string name="setting_clear_confirm">Do you want to restore this setting to its default value?</string>
|
||||
<string name="setting_cleared">Setting cleared</string>
|
||||
|
|
Loading…
Reference in New Issue