Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Remove hacks for Wii Remote extension setting, round 2
It's still not exactly pretty, but now all the mess is contained in one place and has a proper interface. Fixes https://bugs.dolphin-emu.org/issues/12218.
- Loading branch information
Showing
4 changed files
with
122 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...rc/main/java/org/dolphinemu/dolphinemu/features/settings/model/WiimoteProfileSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.dolphinemu.dolphinemu.features.settings.model; | ||
|
||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; | ||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; | ||
import org.dolphinemu.dolphinemu.utils.IniFile; | ||
|
||
import java.io.File; | ||
|
||
// This stuff is pretty ugly. It's a kind of workaround for certain controller settings | ||
// not actually being available as game-specific settings. | ||
public class WiimoteProfileSetting implements AbstractStringSetting | ||
{ | ||
private final int mPadID; | ||
|
||
private final String mSection; | ||
private final String mKey; | ||
private final String mDefaultValue; | ||
|
||
private final String mProfile; | ||
private final File mProfileFile; | ||
private final IniFile mProfileIni; | ||
|
||
public WiimoteProfileSetting(String gameID, int padID, String section, String key, | ||
String defaultValue) | ||
{ | ||
mPadID = padID; | ||
mSection = section; | ||
mKey = key; | ||
mDefaultValue = defaultValue; | ||
|
||
mProfile = gameID + "_Wii" + padID; | ||
mProfileFile = SettingsFile.getWiiProfile(mProfile); | ||
mProfileIni = loadProfile(); | ||
} | ||
|
||
@Override | ||
public boolean isOverridden(Settings settings) | ||
{ | ||
return isProfileEnabled(settings) && mProfileIni.exists(mSection, mKey); | ||
} | ||
|
||
@Override | ||
public boolean isRuntimeEditable() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean delete(Settings settings) | ||
{ | ||
if (!mProfileIni.deleteKey(mSection, mKey)) | ||
return false; | ||
|
||
mProfileIni.save(mProfileFile); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getString(Settings settings) | ||
{ | ||
if (isProfileEnabled(settings)) | ||
return mProfileIni.getString(mSection, mKey, mDefaultValue); | ||
else | ||
return mDefaultValue; | ||
} | ||
|
||
@Override | ||
public void setString(Settings settings, String newValue) | ||
{ | ||
mProfileIni.setString(mSection, mKey, newValue); | ||
|
||
mProfileIni.save(mProfileFile); | ||
enableProfile(settings); | ||
} | ||
|
||
private IniFile loadProfile() | ||
{ | ||
// If it doesn't exist, create it | ||
boolean profileExists = mProfileFile.exists(); | ||
if (!profileExists) | ||
{ | ||
String defaultWiiProfilePath = DirectoryInitialization.getUserDirectory() + | ||
"/Config/Profiles/Wiimote/WiimoteProfile.ini"; | ||
DirectoryInitialization.copyFile(defaultWiiProfilePath, mProfileFile.getPath()); | ||
} | ||
|
||
IniFile profileIni = new IniFile(mProfileFile); | ||
|
||
if (!profileExists) | ||
{ | ||
profileIni.setString(Settings.SECTION_PROFILE, "Device", | ||
"Android/" + (mPadID + 4) + "/Touchscreen"); | ||
} | ||
|
||
return profileIni; | ||
} | ||
|
||
private void enableProfile(Settings settings) | ||
{ | ||
settings.getSection(Settings.GAME_SETTINGS_PLACEHOLDER_FILE_NAME, Settings.SECTION_CONTROLS) | ||
.setString(SettingsFile.KEY_WIIMOTE_PROFILE + (mPadID + 1), mProfile); | ||
} | ||
|
||
private boolean isProfileEnabled(Settings settings) | ||
{ | ||
String enabledProfile = settings.getSection(Settings.GAME_SETTINGS_PLACEHOLDER_FILE_NAME, | ||
Settings.SECTION_CONTROLS) | ||
.getString(SettingsFile.KEY_WIIMOTE_PROFILE + (mPadID + 1), ""); | ||
|
||
return mProfile.equals(enabledProfile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters