Skip to content

Commit

Permalink
Add separate folder settings for saves, states, and cheats
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydr8gon committed Jul 25, 2024
1 parent 7a323b8 commit dff44ce
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 236 deletions.
110 changes: 61 additions & 49 deletions src/android/cpp/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,10 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_hydra_noods_FileBrowser_loadSetti
Setting("keyScreenSwap", &keyBinds[14], false)
};

// Add the platform settings
// Add the platform settings and load
ScreenLayout::addSettings();
Settings::add(platformSettings);

// Load the settings
if (Settings::load(path + "/noods.ini"))
return true;

// If this is the first time, set the path settings based on the root storage path
Settings::bios7Path = path + "/bios7.bin";
Settings::bios9Path = path + "/bios9.bin";
Settings::firmwarePath = path + "/firmware.bin";
Settings::gbaBiosPath = path + "/gba_bios.bin";
Settings::sdImagePath = path + "/sd.img";
Settings::save();
return false;
return Settings::load(path);
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_getNdsIcon(JNIEnv *env, jobject obj, jint fd, jobject bitmap)
Expand Down Expand Up @@ -167,33 +155,27 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_hydra_noods_FileBrowser_isGbaLoad
return gbaPath != "" || gbaRomFd != -1;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_setNdsPath(JNIEnv* env, jobject obj, jstring value)
extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_setNdsRom(JNIEnv* env, jobject obj, jstring romPath, jint romFd, jint saveFd, jint stateFd, jint cheatFd)
{
// Set the NDS ROM file path
const char *str = env->GetStringUTFChars(value, nullptr);
const char *str = env->GetStringUTFChars(romPath, nullptr);
ndsPath = str;
env->ReleaseStringUTFChars(value, str);
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_setGbaPath(JNIEnv* env, jobject obj, jstring value)
{
// Set the GBA ROM file path
const char *str = env->GetStringUTFChars(value, nullptr);
gbaPath = str;
env->ReleaseStringUTFChars(value, str);
}
env->ReleaseStringUTFChars(romPath, str);

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_setNdsFds(JNIEnv* env, jobject obj, jint romFd, jint saveFd, jint stateFd, jint cheatFd)
{
// Set the NDS ROM file descriptors
ndsRomFd = romFd;
ndsSaveFd = saveFd;
ndsStateFd = stateFd;
ndsCheatFd = cheatFd;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_setGbaFds(JNIEnv* env, jobject obj, jint romFd, jint saveFd, jint stateFd)
extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_FileBrowser_setGbaRom(JNIEnv* env, jobject obj, jstring romPath, jint romFd, jint saveFd, jint stateFd)
{
// Set the GBA ROM file path
const char *str = env->GetStringUTFChars(romPath, nullptr);
gbaPath = str;
env->ReleaseStringUTFChars(romPath, str);

// Set the GBA ROM file descriptors
gbaRomFd = romFd;
gbaSaveFd = saveFd;
Expand Down Expand Up @@ -352,6 +334,31 @@ extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getHighRes3D
return Settings::highRes3D;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getMicEnable(JNIEnv* env, jobject obj)
{
return micEnable;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getShowFpsCounter(JNIEnv* env, jobject obj)
{
return showFpsCounter;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getSavesFolder(JNIEnv* env, jobject obj)
{
return Settings::savesFolder;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getStatesFolder(JNIEnv* env, jobject obj)
{
return Settings::statesFolder;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getCheatsFolder(JNIEnv* env, jobject obj)
{
return Settings::cheatsFolder;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getScreenPosition(JNIEnv* env, jobject obj)
{
return ScreenLayout::screenPosition;
Expand Down Expand Up @@ -397,16 +404,6 @@ extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getScreenGho
return Settings::screenGhost;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getMicEnable(JNIEnv* env, jobject obj)
{
return micEnable;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getShowFpsCounter(JNIEnv* env, jobject obj)
{
return showFpsCounter;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getButtonScale(JNIEnv* env, jobject obj)
{
return buttonScale;
Expand Down Expand Up @@ -447,6 +444,31 @@ extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setHighRes3D
Settings::highRes3D = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setMicEnable(JNIEnv* env, jobject obj, jint value)
{
micEnable = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setShowFpsCounter(JNIEnv* env, jobject obj, jint value)
{
showFpsCounter = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setSavesFolder(JNIEnv* env, jobject obj, jint value)
{
Settings::savesFolder = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setStatesFolder(JNIEnv* env, jobject obj, jint value)
{
Settings::statesFolder = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setCheatsFolder(JNIEnv* env, jobject obj, jint value)
{
Settings::cheatsFolder = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setScreenPosition(JNIEnv* env, jobject obj, jint value)
{
ScreenLayout::screenPosition = value;
Expand Down Expand Up @@ -492,16 +514,6 @@ extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setScreenGho
Settings::screenGhost = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setMicEnable(JNIEnv* env, jobject obj, jint value)
{
micEnable = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setShowFpsCounter(JNIEnv* env, jobject obj, jint value)
{
showFpsCounter = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setButtonScale(JNIEnv* env, jobject obj, jint value)
{
buttonScale = value;
Expand Down
34 changes: 14 additions & 20 deletions src/android/java/com/hydra/noods/FileBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,8 @@ private void update()
// If a ROM of the other type is already loaded, ask if it should be loaded alongside the new ROM
if (ext.equals(".nds"))
{
if (scoped)
setNdsFds(getRomFd(file.getUri()), getSaveFd(file), getStateFd(file), getCheatFd(file));
else
setNdsPath(file.getUri().getPath());
Uri uri = file.getUri();
setNdsRom(uri.getPath(), getRomFd(uri), getSaveFd(file), getStateFd(file), getCheatFd(file));

if (isGbaLoaded())
{
Expand All @@ -440,8 +438,7 @@ public void onClick(DialogInterface dialog, int id)
@Override
public void onClick(DialogInterface dialog, int id)
{
setGbaPath("");
setGbaFds(-1, -1, -1);
setGbaRom("", -1, -1, -1);
tryStartCore();
}
});
Expand All @@ -451,8 +448,7 @@ public void onClick(DialogInterface dialog, int id)
@Override
public void onCancel(DialogInterface dialog)
{
setGbaPath("");
setGbaFds(-1, -1, -1);
setGbaRom("", -1, -1, -1);
tryStartCore();
}
});
Expand All @@ -463,10 +459,8 @@ public void onCancel(DialogInterface dialog)
}
else
{
if (scoped)
setGbaFds(getRomFd(file.getUri()), getSaveFd(file), getStateFd(file));
else
setGbaPath(file.getUri().getPath());
Uri uri = file.getUri();
setGbaRom(uri.getPath(), getRomFd(uri), getSaveFd(file), getStateFd(file));

if (isNdsLoaded())
{
Expand All @@ -488,8 +482,7 @@ public void onClick(DialogInterface dialog, int id)
@Override
public void onClick(DialogInterface dialog, int id)
{
setNdsPath("");
setNdsFds(-1, -1, -1, -1);
setNdsRom("", -1, -1, -1, -1);
tryStartCore();
}
});
Expand All @@ -499,8 +492,7 @@ public void onClick(DialogInterface dialog, int id)
@Override
public void onCancel(DialogInterface dialog)
{
setNdsPath("");
setNdsFds(-1, -1, -1, -1);
setNdsRom("", -1, -1, -1, -1);
tryStartCore();
}
});
Expand Down Expand Up @@ -593,6 +585,7 @@ private int getRomFd(Uri romUri)
try
{
// Get a descriptor for the file in scoped mode
if (!scoped) return -1;
return getContentResolver().openFileDescriptor(romUri, "r").detachFd();
}
catch (Exception e)
Expand All @@ -611,6 +604,7 @@ private int getSaveFd(DocumentFile rom)
try
{
// Get a descriptor for the file in scoped mode
if (!scoped || SettingsMenu.getSavesFolder() == 1) return -1;
return getContentResolver().openFileDescriptor(uri, "rw").detachFd();
}
catch (Exception e)
Expand Down Expand Up @@ -645,6 +639,7 @@ private int getStateFd(DocumentFile rom)
try
{
// Get a descriptor for the file in scoped mode
if (!scoped || SettingsMenu.getStatesFolder() == 1) return -1;
return getContentResolver().openFileDescriptor(uri, "rw").detachFd();
}
catch (Exception e)
Expand All @@ -666,6 +661,7 @@ private int getCheatFd(DocumentFile rom)
try
{
// Get a descriptor for the file in scoped mode
if (!scoped || SettingsMenu.getCheatsFolder() == 1) return -1;
return getContentResolver().openFileDescriptor(uri, "rw").detachFd();
}
catch (Exception e)
Expand All @@ -683,8 +679,6 @@ private int getCheatFd(DocumentFile rom)
public static native int startCore();
public static native boolean isNdsLoaded();
public static native boolean isGbaLoaded();
public static native void setNdsPath(String value);
public static native void setGbaPath(String value);
public static native void setNdsFds(int romFd, int saveFd, int stateFd, int cheatFd);
public static native void setGbaFds(int romFd, int saveFd, int stateFd);
public static native void setNdsRom(String romPath, int romFd, int saveFd, int stateFd, int cheatFd);
public static native void setGbaRom(String romPath, int romFd, int saveFd, int stateFd);
}
30 changes: 21 additions & 9 deletions src/android/java/com/hydra/noods/SettingsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ protected void onCreate(Bundle savedInstanceState)
editor.putBoolean("threaded_2d", (getThreaded2D() == 0) ? false : true);
editor.putString("threaded_3d", Integer.toString(getThreaded3D()));
editor.putBoolean("high_res_3d", (getHighRes3D() == 0) ? false : true);
editor.putBoolean("mic_enable", (getMicEnable() == 0) ? false : true);
editor.putBoolean("show_fps_counter", (getShowFpsCounter() == 0) ? false : true);
editor.putBoolean("saves_folder", (getSavesFolder() == 0) ? false : true);
editor.putBoolean("states_folder", (getStatesFolder() == 0) ? false : true);
editor.putBoolean("cheats_folder", (getCheatsFolder() == 0) ? false : true);
editor.putString("screen_position", Integer.toString(getScreenPosition()));
editor.putString("screen_rotation", Integer.toString(getScreenRotation()));
editor.putString("screen_arrangement", Integer.toString(getScreenArrangement()));
Expand All @@ -96,8 +101,6 @@ protected void onCreate(Bundle savedInstanceState)
editor.putBoolean("integer_scale", (getIntegerScale() == 0) ? false : true);
editor.putBoolean("gba_crop", (getGbaCrop() == 0) ? false : true);
editor.putBoolean("screen_ghost", (getScreenGhost() == 0) ? false : true);
editor.putBoolean("mic_enable", (getMicEnable() == 0) ? false : true);
editor.putBoolean("show_fps_counter", (getShowFpsCounter() == 0) ? false : true);
editor.putInt("button_scale", getButtonScale());
editor.putInt("button_spacing", getButtonSpacing());
editor.putInt("vibrate_strength", getVibrateStrength());
Expand Down Expand Up @@ -138,7 +141,12 @@ public void onBackPressed()
setFpsLimiter(Integer.parseInt(prefs.getString("fps_limiter", "1")));
setThreaded2D(prefs.getBoolean("threaded_2d", true) ? 1 : 0);
setThreaded3D(Integer.parseInt(prefs.getString("threaded_3d", "1")));
setHighRes3D(prefs.getBoolean("high_res_3d", true) ? 1 : 0);
setHighRes3D(prefs.getBoolean("high_res_3d", false) ? 1 : 0);
setMicEnable(prefs.getBoolean("mic_enable", false) ? 1 : 0);
setShowFpsCounter(prefs.getBoolean("show_fps_counter", false) ? 1 : 0);
setSavesFolder(prefs.getBoolean("saves_folder", false) ? 1 : 0);
setStatesFolder(prefs.getBoolean("states_folder", true) ? 1 : 0);
setCheatsFolder(prefs.getBoolean("cheats_folder", true) ? 1 : 0);
setScreenPosition(Integer.parseInt(prefs.getString("screen_position", "0")));
setScreenRotation(Integer.parseInt(prefs.getString("screen_rotation", "0")));
setScreenArrangement(Integer.parseInt(prefs.getString("screen_arrangement", "0")));
Expand All @@ -148,8 +156,6 @@ public void onBackPressed()
setIntegerScale(prefs.getBoolean("integer_scale", false) ? 1 : 0);
setGbaCrop(prefs.getBoolean("gba_crop", true) ? 1 : 0);
setScreenGhost(prefs.getBoolean("screen_ghost", false) ? 1 : 0);
setMicEnable(prefs.getBoolean("mic_enable", false) ? 1 : 0);
setShowFpsCounter(prefs.getBoolean("show_fps_counter", false) ? 1 : 0);
setButtonScale(prefs.getInt("button_scale", 5));
setButtonSpacing(prefs.getInt("button_spacing", 10));
setVibrateStrength(prefs.getInt("vibrate_strength", 1));
Expand All @@ -164,6 +170,11 @@ public void onBackPressed()
public static native int getThreaded2D();
public static native int getThreaded3D();
public static native int getHighRes3D();
public static native int getMicEnable();
public static native int getShowFpsCounter();
public static native int getSavesFolder();
public static native int getStatesFolder();
public static native int getCheatsFolder();
public static native int getScreenPosition();
public static native int getScreenRotation();
public static native int getScreenArrangement();
Expand All @@ -173,8 +184,6 @@ public void onBackPressed()
public static native int getIntegerScale();
public static native int getGbaCrop();
public static native int getScreenGhost();
public static native int getMicEnable();
public static native int getShowFpsCounter();
public static native int getButtonScale();
public static native int getButtonSpacing();
public static native int getVibrateStrength();
Expand All @@ -183,6 +192,11 @@ public void onBackPressed()
public static native void setThreaded2D(int value);
public static native void setThreaded3D(int value);
public static native void setHighRes3D(int value);
public static native void setMicEnable(int value);
public static native void setShowFpsCounter(int value);
public static native void setSavesFolder(int value);
public static native void setStatesFolder(int value);
public static native void setCheatsFolder(int value);
public static native void setScreenPosition(int value);
public static native void setScreenRotation(int value);
public static native void setScreenArrangement(int value);
Expand All @@ -192,8 +206,6 @@ public void onBackPressed()
public static native void setIntegerScale(int value);
public static native void setGbaCrop(int value);
public static native void setScreenGhost(int value);
public static native void setMicEnable(int value);
public static native void setShowFpsCounter(int value);
public static native void setButtonScale(int value);
public static native void setButtonSpacing(int value);
public static native void setVibrateStrength(int value);
Expand Down
Loading

0 comments on commit dff44ce

Please sign in to comment.