fceugx/source/preferences.cpp

664 lines
22 KiB
C++
Raw Permalink Normal View History

2008-09-02 03:57:21 +02:00
/****************************************************************************
2009-07-22 04:05:49 +02:00
* FCE Ultra
2008-09-02 03:57:21 +02:00
* Nintendo Wii/Gamecube Port
*
2023-01-30 22:07:47 +01:00
* Tantric 2008-2023
2008-09-02 03:57:21 +02:00
*
2009-03-28 18:23:08 +01:00
* preferences.cpp
2008-09-02 03:57:21 +02:00
*
* Preferences save/load preferences utilities
****************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <string.h>
2011-01-20 03:53:13 +01:00
#include <dirent.h>
#include <sys/stat.h>
2008-09-02 03:57:21 +02:00
#include <ogcsys.h>
#include <mxml.h>
2010-03-22 00:49:24 +01:00
#include "fceugx.h"
#include "filelist.h"
2009-03-28 18:23:08 +01:00
#include "button_mapping.h"
#include "filebrowser.h"
#include "menu.h"
2008-09-02 03:57:21 +02:00
#include "fileop.h"
#include "gcvideo.h"
2008-09-02 03:57:21 +02:00
#include "pad.h"
2010-01-25 22:04:44 +01:00
struct SGCSettings GCSettings;
2008-09-02 03:57:21 +02:00
/****************************************************************************
* Prepare Preferences Data
*
* This sets up the save buffer for saving.
2009-10-02 00:21:25 +02:00
***************************************************************************/
static mxml_node_t *xml = NULL;
static mxml_node_t *data = NULL;
static mxml_node_t *section = NULL;
static mxml_node_t *item = NULL;
static mxml_node_t *elem = NULL;
2008-09-02 03:57:21 +02:00
static char temp[200];
2008-09-02 03:57:21 +02:00
static const char * toStr(int i)
2008-09-02 03:57:21 +02:00
{
sprintf(temp, "%d", i);
return temp;
}
static const char * FtoStr(float i)
2008-10-24 07:38:46 +02:00
{
sprintf(temp, "%.2f", i);
return temp;
}
static void createXMLSection(const char * name, const char * description)
2008-09-02 03:57:21 +02:00
{
section = mxmlNewElement(data, "section");
mxmlElementSetAttr(section, "name", name);
mxmlElementSetAttr(section, "description", description);
}
static void createXMLSetting(const char * name, const char * description, const char * value)
2008-09-02 03:57:21 +02:00
{
item = mxmlNewElement(section, "setting");
mxmlElementSetAttr(item, "name", name);
mxmlElementSetAttr(item, "value", value);
mxmlElementSetAttr(item, "description", description);
}
static void createXMLController(u32 controller[], const char * name, const char * description)
2008-09-02 03:57:21 +02:00
{
item = mxmlNewElement(section, "controller");
mxmlElementSetAttr(item, "name", name);
mxmlElementSetAttr(item, "description", description);
// create buttons
2009-10-02 00:21:25 +02:00
for(int i=0; i < MAXJP; i++)
2008-09-02 03:57:21 +02:00
{
elem = mxmlNewElement(item, "button");
mxmlElementSetAttr(elem, "number", toStr(i));
mxmlElementSetAttr(elem, "assignment", toStr(controller[i]));
}
}
static const char * XMLSaveCallback(mxml_node_t *node, int where)
2008-09-02 03:57:21 +02:00
{
const char *name;
2023-07-30 21:32:30 +02:00
name = mxmlGetElement(node);
2008-09-02 03:57:21 +02:00
if(where == MXML_WS_BEFORE_CLOSE)
{
if(!strcmp(name, "file") || !strcmp(name, "section"))
return ("\n");
else if(!strcmp(name, "controller"))
return ("\n\t");
}
if (where == MXML_WS_BEFORE_OPEN)
{
if(!strcmp(name, "file"))
return ("\n");
else if(!strcmp(name, "section"))
return ("\n\n");
else if(!strcmp(name, "setting") || !strcmp(name, "controller"))
return ("\n\t");
else if(!strcmp(name, "button"))
return ("\n\t\t");
}
return (NULL);
}
static int
2009-10-02 00:21:25 +02:00
preparePrefsData ()
2008-09-02 03:57:21 +02:00
{
xml = mxmlNewXML("1.0");
mxmlSetWrapMargin(0); // disable line wrapping
data = mxmlNewElement(xml, "file");
2009-10-02 00:21:25 +02:00
mxmlElementSetAttr(data, "app", APPNAME);
mxmlElementSetAttr(data, "version", APPVERSION);
2008-09-02 03:57:21 +02:00
createXMLSection("File", "File Settings");
createXMLSetting("AutoLoad", "Auto Load", toStr(GCSettings.AutoLoad));
createXMLSetting("AutoSave", "Auto Save", toStr(GCSettings.AutoSave));
createXMLSetting("LoadMethod", "Load Method", toStr(GCSettings.LoadMethod));
createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod));
createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder);
2014-10-24 04:51:36 +02:00
createXMLSetting("LastFileLoaded", "Last File Loaded", GCSettings.LastFileLoaded);
2008-09-02 03:57:21 +02:00
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
createXMLSetting("AppendAuto", "Append Auto to .SAV Files", toStr(GCSettings.AppendAuto));
2009-07-22 03:58:45 +02:00
createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
2009-10-07 08:59:10 +02:00
createXMLSetting("gamegenie", "Game Genie", toStr(GCSettings.gamegenie));
2014-10-24 04:51:36 +02:00
createXMLSetting("ScreenshotsFolder", "Screenshots Folder", GCSettings.ScreenshotsFolder);
2019-01-05 10:54:09 +01:00
createXMLSetting("CoverFolder", "Covers Folder", GCSettings.CoverFolder);
createXMLSetting("ArtworkFolder", "Artwork Folder", GCSettings.ArtworkFolder);
2008-09-02 03:57:21 +02:00
createXMLSection("Network", "Network Settings");
createXMLSetting("smbip", "Share Computer IP", GCSettings.smbip);
createXMLSetting("smbshare", "Share Name", GCSettings.smbshare);
createXMLSetting("smbuser", "Share Username", GCSettings.smbuser);
createXMLSetting("smbpwd", "Share Password", GCSettings.smbpwd);
2009-03-28 18:23:08 +01:00
createXMLSection("Video", "Video Settings");
2008-09-02 03:57:21 +02:00
2009-04-27 09:49:30 +02:00
createXMLSetting("videomode", "Video Mode", toStr(GCSettings.videomode));
2008-09-02 03:57:21 +02:00
createXMLSetting("currpal", "Palette", toStr(GCSettings.currpal));
createXMLSetting("timing", "Timing", toStr(GCSettings.timing));
createXMLSetting("spritelimit", "Sprite Limit", toStr(GCSettings.spritelimit));
2009-11-16 09:14:38 +01:00
createXMLSetting("zoomHor", "Horizontal Zoom Level", FtoStr(GCSettings.zoomHor));
createXMLSetting("zoomVert", "Vertical Zoom Level", FtoStr(GCSettings.zoomVert));
createXMLSetting("render", "Video Filtering", toStr(GCSettings.render));
createXMLSetting("widescreen", "Aspect Ratio Correction", toStr(GCSettings.widescreen));
2008-11-20 17:58:44 +01:00
createXMLSetting("hideoverscan", "Video Cropping", toStr(GCSettings.hideoverscan));
2009-01-26 08:10:20 +01:00
createXMLSetting("xshift", "Horizontal Video Shift", toStr(GCSettings.xshift));
createXMLSetting("yshift", "Vertical Video Shift", toStr(GCSettings.yshift));
createXMLSetting("TurboModeEnabled", "Turbo Mode Enabled", toStr(GCSettings.TurboModeEnabled));
createXMLSetting("TurboModeButton", "Turbo Mode Button", toStr(GCSettings.TurboModeButton));
createXMLSetting("GamepadMenuToggle", "Gamepad Menu Toggle", toStr(GCSettings.GamepadMenuToggle));
2008-09-02 03:57:21 +02:00
2009-03-28 18:23:08 +01:00
createXMLSection("Menu", "Menu Settings");
#ifdef HW_RVL
2009-03-28 18:23:08 +01:00
createXMLSetting("WiimoteOrientation", "Wiimote Orientation", toStr(GCSettings.WiimoteOrientation));
#endif
2009-03-28 18:23:08 +01:00
createXMLSetting("ExitAction", "Exit Action", toStr(GCSettings.ExitAction));
createXMLSetting("MusicVolume", "Music Volume", toStr(GCSettings.MusicVolume));
createXMLSetting("SFXVolume", "Sound Effects Volume", toStr(GCSettings.SFXVolume));
2009-05-30 08:28:00 +02:00
createXMLSetting("Rumble", "Rumble", toStr(GCSettings.Rumble));
2010-01-25 22:04:44 +01:00
createXMLSetting("language", "Language", toStr(GCSettings.language));
2019-01-05 10:54:09 +01:00
createXMLSetting("PreviewImage", "Preview Image", toStr(GCSettings.PreviewImage));
createXMLSetting("HideRAMSaving", "Hide RAM Saving", toStr(GCSettings.HideRAMSaving));
2009-03-28 18:23:08 +01:00
2008-09-02 03:57:21 +02:00
createXMLSection("Controller", "Controller Settings");
2009-03-28 18:23:08 +01:00
createXMLSetting("Controller", "Controller", toStr(GCSettings.Controller));
2008-10-02 01:10:30 +02:00
createXMLSetting("crosshair", "Zapper Crosshair", toStr(GCSettings.crosshair));
2009-03-28 18:23:08 +01:00
createXMLController(btnmap[CTRL_PAD][CTRLR_GCPAD], "btnmap_pad_gcpad", "NES Pad - GameCube Controller");
createXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote", "NES Pad - Wiimote");
createXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic", "NES Pad - Classic Controller");
createXMLController(btnmap[CTRL_PAD][CTRLR_WUPC], "btnmap_pad_wupc", "NES Pad - Wii U Pro Controller");
createXMLController(btnmap[CTRL_PAD][CTRLR_WIIDRC], "btnmap_pad_wiidrc", "NES Pad - Wii U Gamepad");
2009-03-28 18:23:08 +01:00
createXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk", "NES Pad - Nunchuk + Wiimote");
createXMLController(btnmap[CTRL_ZAPPER][CTRLR_GCPAD], "btnmap_zapper_gcpad", "Zapper - GameCube Controller");
createXMLController(btnmap[CTRL_ZAPPER][CTRLR_WIIMOTE], "btnmap_zapper_wiimote", "Zapper - Wiimote");
2008-09-02 03:57:21 +02:00
int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSaveCallback);
mxmlDelete(xml);
return datasize;
}
/****************************************************************************
2009-10-02 00:21:25 +02:00
* loadXMLSetting
*
* Load XML elements into variables for an individual variable
***************************************************************************/
2009-01-25 08:01:50 +01:00
static void loadXMLSetting(char * var, const char * name, int maxsize)
2008-09-02 03:57:21 +02:00
{
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
if(item)
{
const char * tmp = mxmlElementGetAttr(item, "value");
if(tmp)
snprintf(var, maxsize, "%s", tmp);
}
2008-09-02 03:57:21 +02:00
}
2009-01-25 08:01:50 +01:00
static void loadXMLSetting(int * var, const char * name)
2008-09-02 03:57:21 +02:00
{
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
if(item)
{
const char * tmp = mxmlElementGetAttr(item, "value");
if(tmp)
*var = atoi(tmp);
}
2008-09-02 03:57:21 +02:00
}
2009-01-25 08:01:50 +01:00
static void loadXMLSetting(float * var, const char * name)
2008-10-24 07:38:46 +02:00
{
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
if(item)
{
const char * tmp = mxmlElementGetAttr(item, "value");
if(tmp)
*var = atof(tmp);
}
2008-10-24 07:38:46 +02:00
}
2008-09-02 03:57:21 +02:00
2009-10-02 00:21:25 +02:00
/****************************************************************************
* loadXMLController
*
* Load XML elements into variables for a controller mapping
***************************************************************************/
static void loadXMLController(u32 controller[], const char * name)
2008-09-02 03:57:21 +02:00
{
item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND);
if(item)
{
// populate buttons
2009-10-02 00:21:25 +02:00
for(int i=0; i < MAXJP; i++)
2008-09-02 03:57:21 +02:00
{
elem = mxmlFindElement(item, xml, "button", "number", toStr(i), MXML_DESCEND);
if(elem)
{
const char * tmp = mxmlElementGetAttr(elem, "assignment");
if(tmp)
controller[i] = atoi(tmp);
}
2008-09-02 03:57:21 +02:00
}
}
}
2009-10-02 00:21:25 +02:00
/****************************************************************************
* decodePrefsData
*
* Decodes preferences - parses XML and loads preferences into the variables
***************************************************************************/
static bool
2009-10-02 00:21:25 +02:00
decodePrefsData ()
2008-09-02 03:57:21 +02:00
{
bool result = false;
2008-09-02 03:57:21 +02:00
2009-03-28 18:23:08 +01:00
xml = mxmlLoadString(NULL, (char *)savebuffer, MXML_TEXT_CALLBACK);
2008-09-02 03:57:21 +02:00
if(xml)
{
// check settings version
item = mxmlFindElement(xml, xml, "file", "version", NULL, MXML_DESCEND);
if(item) // a version entry exists
{
2009-10-02 00:21:25 +02:00
const char * version = mxmlElementGetAttr(item, "version");
2009-10-02 00:21:25 +02:00
if(version && strlen(version) == 5)
{
// this code assumes version in format X.X.X
// XX.X.X, X.XX.X, or X.X.XX will NOT work
int verMajor = version[0] - '0';
int verMinor = version[2] - '0';
int verPoint = version[4] - '0';
// check that the versioning is valid
if(!(verMajor >= 3 && verMajor <= 9 &&
verMinor >= 0 && verMinor <= 9 &&
verPoint >= 0 && verPoint <= 9))
result = false;
else
result = true;
}
}
2008-09-02 03:57:21 +02:00
if(result)
{
// File Settings
2009-01-25 08:01:50 +01:00
loadXMLSetting(&GCSettings.AutoLoad, "AutoLoad");
loadXMLSetting(&GCSettings.AutoSave, "AutoSave");
loadXMLSetting(&GCSettings.LoadMethod, "LoadMethod");
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
2014-10-24 04:51:36 +02:00
loadXMLSetting(GCSettings.LastFileLoaded, "LastFileLoaded", sizeof(GCSettings.LastFileLoaded));
2009-01-25 08:01:50 +01:00
loadXMLSetting(GCSettings.SaveFolder, "SaveFolder", sizeof(GCSettings.SaveFolder));
loadXMLSetting(&GCSettings.AppendAuto, "AppendAuto");
2009-07-22 03:58:45 +02:00
loadXMLSetting(GCSettings.CheatFolder, "CheatFolder", sizeof(GCSettings.CheatFolder));
2009-10-07 08:59:10 +02:00
loadXMLSetting(&GCSettings.gamegenie, "gamegenie");
2014-10-24 04:51:36 +02:00
loadXMLSetting(GCSettings.ScreenshotsFolder, "ScreenshotsFolder", sizeof(GCSettings.ScreenshotsFolder));
2019-01-05 10:54:09 +01:00
loadXMLSetting(GCSettings.CoverFolder, "CoverFolder", sizeof(GCSettings.CoverFolder));
loadXMLSetting(GCSettings.ArtworkFolder, "ArtworkFolder", sizeof(GCSettings.ArtworkFolder));
// Network Settings
2009-01-25 08:01:50 +01:00
loadXMLSetting(GCSettings.smbip, "smbip", sizeof(GCSettings.smbip));
loadXMLSetting(GCSettings.smbshare, "smbshare", sizeof(GCSettings.smbshare));
loadXMLSetting(GCSettings.smbuser, "smbuser", sizeof(GCSettings.smbuser));
loadXMLSetting(GCSettings.smbpwd, "smbpwd", sizeof(GCSettings.smbpwd));
2009-03-28 18:23:08 +01:00
// Video Settings
2009-04-27 09:49:30 +02:00
loadXMLSetting(&GCSettings.videomode, "videomode");
2009-01-25 08:01:50 +01:00
loadXMLSetting(&GCSettings.currpal, "currpal");
loadXMLSetting(&GCSettings.timing, "timing");
loadXMLSetting(&GCSettings.spritelimit, "spritelimit");
2009-11-16 09:14:38 +01:00
loadXMLSetting(&GCSettings.zoomHor, "zoomHor");
loadXMLSetting(&GCSettings.zoomVert, "zoomVert");
2009-01-25 08:01:50 +01:00
loadXMLSetting(&GCSettings.render, "render");
loadXMLSetting(&GCSettings.widescreen, "widescreen");
loadXMLSetting(&GCSettings.hideoverscan, "hideoverscan");
2009-01-26 08:10:20 +01:00
loadXMLSetting(&GCSettings.xshift, "xshift");
loadXMLSetting(&GCSettings.yshift, "yshift");
// Other Mappings
loadXMLSetting(&GCSettings.TurboModeEnabled, "TurboModeEnabled");
loadXMLSetting(&GCSettings.TurboModeButton, "TurboModeButton");
loadXMLSetting(&GCSettings.GamepadMenuToggle, "GamepadMenuToggle");
2009-03-28 18:23:08 +01:00
// Menu Settings
loadXMLSetting(&GCSettings.WiimoteOrientation, "WiimoteOrientation");
loadXMLSetting(&GCSettings.ExitAction, "ExitAction");
loadXMLSetting(&GCSettings.MusicVolume, "MusicVolume");
loadXMLSetting(&GCSettings.SFXVolume, "SFXVolume");
2009-05-30 08:28:00 +02:00
loadXMLSetting(&GCSettings.Rumble, "Rumble");
2010-01-25 22:04:44 +01:00
loadXMLSetting(&GCSettings.language, "language");
2019-01-05 10:54:09 +01:00
loadXMLSetting(&GCSettings.PreviewImage, "PreviewImage");
loadXMLSetting(&GCSettings.HideRAMSaving, "HideRAMSaving");
2016-09-18 05:43:24 +02:00
// Controller Settings
2009-10-02 00:21:25 +02:00
2009-03-28 18:23:08 +01:00
loadXMLSetting(&GCSettings.Controller, "Controller");
2009-01-25 08:01:50 +01:00
loadXMLSetting(&GCSettings.crosshair, "crosshair");
2009-03-28 18:23:08 +01:00
loadXMLController(btnmap[CTRL_PAD][CTRLR_GCPAD], "btnmap_pad_gcpad");
loadXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote");
loadXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic");
loadXMLController(btnmap[CTRL_PAD][CTRLR_WUPC], "btnmap_pad_wupc");
loadXMLController(btnmap[CTRL_PAD][CTRLR_WIIDRC], "btnmap_pad_wiidrc");
2009-03-28 18:23:08 +01:00
loadXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk");
loadXMLController(btnmap[CTRL_ZAPPER][CTRLR_GCPAD], "btnmap_zapper_gcpad");
loadXMLController(btnmap[CTRL_ZAPPER][CTRLR_WIIMOTE], "btnmap_zapper_wiimote");
}
mxmlDelete(xml);
}
return result;
2008-09-02 03:57:21 +02:00
}
2010-01-25 22:04:44 +01:00
/****************************************************************************
* FixInvalidSettings
*
* Attempts to correct at least some invalid settings - the ones that
* might cause crashes
***************************************************************************/
void FixInvalidSettings()
{
if(GCSettings.LoadMethod > 7)
2010-01-25 22:04:44 +01:00
GCSettings.LoadMethod = DEVICE_AUTO;
if(GCSettings.SaveMethod > 7)
2010-01-25 22:04:44 +01:00
GCSettings.SaveMethod = DEVICE_AUTO;
if(!(GCSettings.zoomHor > 0.5 && GCSettings.zoomHor < 1.5))
GCSettings.zoomHor = 1.0;
if(!(GCSettings.zoomVert > 0.5 && GCSettings.zoomVert < 1.5))
GCSettings.zoomVert = 1.0;
if(!(GCSettings.xshift > -50 && GCSettings.xshift < 50))
GCSettings.xshift = 0;
if(!(GCSettings.yshift > -50 && GCSettings.yshift < 50))
GCSettings.yshift = 0;
if(!(GCSettings.MusicVolume >= 0 && GCSettings.MusicVolume <= 100))
2018-08-13 00:37:15 +02:00
GCSettings.MusicVolume = 20;
2010-01-25 22:04:44 +01:00
if(!(GCSettings.SFXVolume >= 0 && GCSettings.SFXVolume <= 100))
GCSettings.SFXVolume = 40;
2010-08-29 23:44:03 +02:00
if(GCSettings.language < 0 || GCSettings.language >= LANG_LENGTH)
2010-01-25 22:04:44 +01:00
GCSettings.language = LANG_ENGLISH;
if(GCSettings.Controller > CTRL_PAD4 || GCSettings.Controller < CTRL_ZAPPER)
GCSettings.Controller = CTRL_PAD2;
if(!(GCSettings.render >= 0 && GCSettings.render < 5))
GCSettings.render = 4;
2020-11-09 00:36:36 +01:00
if(GCSettings.timing < 0 || GCSettings.timing > 3)
2010-04-12 23:15:11 +02:00
GCSettings.timing = 2;
2010-01-25 22:04:44 +01:00
if(!(GCSettings.videomode >= 0 && GCSettings.videomode < 5))
GCSettings.videomode = 0;
}
/****************************************************************************
* DefaultSettings
*
* Sets all the defaults!
***************************************************************************/
void
DefaultSettings ()
{
memset (&GCSettings, 0, sizeof (GCSettings));
ResetControls(); // controller button mappings
2016-12-10 20:37:33 +01:00
GCSettings.currpal = 1; // color palette
2010-04-12 23:15:11 +02:00
GCSettings.timing = 2; // 0 - NTSC, 1 - PAL, 2 - Automatic
2010-01-25 22:04:44 +01:00
GCSettings.videomode = 0; // automatic video mode detection
GCSettings.Controller = CTRL_PAD2; // NES pad, Four Score, Zapper
GCSettings.crosshair = 1; // show zapper crosshair
GCSettings.spritelimit = 1; // enforce 8 sprite limit
2016-09-18 05:43:24 +02:00
GCSettings.gamegenie = 0; // Off
2010-01-25 22:04:44 +01:00
2018-08-27 04:30:26 +02:00
GCSettings.render = 3; // Filtered (sharp)
GCSettings.hideoverscan = 3; // hide both
2010-01-25 22:04:44 +01:00
GCSettings.widescreen = 0;
#ifdef HW_RVL
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
GCSettings.widescreen = 1;
#endif
2010-01-25 22:04:44 +01:00
GCSettings.zoomHor = 1.0; // horizontal zoom level
GCSettings.zoomVert = 1.0; // vertical zoom level
GCSettings.xshift = 0; // horizontal video shift
GCSettings.yshift = 0; // vertical video shift
GCSettings.WiimoteOrientation = 0;
GCSettings.AutoloadGame = 0;
2016-12-10 20:37:33 +01:00
GCSettings.ExitAction = 0; // Auto
2018-08-13 00:37:15 +02:00
GCSettings.MusicVolume = 20;
2010-01-25 22:04:44 +01:00
GCSettings.SFXVolume = 40;
2016-12-10 20:37:33 +01:00
GCSettings.Rumble = 1; // Enabled
2019-01-05 10:54:09 +01:00
GCSettings.PreviewImage = 0;
GCSettings.HideRAMSaving = 0;
2019-01-05 10:54:09 +01:00
2010-01-25 22:33:50 +01:00
#ifdef HW_RVL
2010-01-25 22:04:44 +01:00
GCSettings.language = CONF_GetLanguage();
2010-03-16 00:35:15 +01:00
if(GCSettings.language == LANG_TRAD_CHINESE)
GCSettings.language = LANG_SIMP_CHINESE;
2010-01-25 22:33:50 +01:00
#else
GCSettings.language = LANG_ENGLISH;
#endif
2010-01-25 22:04:44 +01:00
GCSettings.LoadMethod = DEVICE_AUTO; // Auto, SD, DVD, USB, Network (SMB)
GCSettings.SaveMethod = DEVICE_AUTO; // Auto, SD, USB, Network (SMB)
sprintf (GCSettings.LoadFolder, "%s/roms", APPFOLDER); // Path to game files
sprintf (GCSettings.SaveFolder, "%s/saves", APPFOLDER); // Path to save files
sprintf (GCSettings.CheatFolder, "%s/cheats", APPFOLDER); // Path to cheat files
2016-09-18 05:43:24 +02:00
sprintf (GCSettings.ScreenshotsFolder, "%s/screenshots", APPFOLDER); // Path to screenshots files
2019-01-05 10:54:09 +01:00
sprintf (GCSettings.CoverFolder, "%s/covers", APPFOLDER); // Path to cover files
sprintf (GCSettings.ArtworkFolder, "%s/artwork", APPFOLDER); // Path to artwork files
2010-01-25 22:04:44 +01:00
GCSettings.AutoLoad = 1; // Auto Load RAM
GCSettings.AutoSave = 1; // Auto Save RAM
GCSettings.TurboModeEnabled = 1; // Enabled by default
GCSettings.TurboModeButton = 0; // Default is Right Analog Stick (0)
GCSettings.GamepadMenuToggle = 0; // 0 = All options (default), 1 = Home / C-Stick left, 2 = R+L+Start
2010-01-25 22:04:44 +01:00
}
2008-09-02 03:57:21 +02:00
/****************************************************************************
* Save Preferences
***************************************************************************/
2009-10-02 00:21:25 +02:00
static char prefpath[MAXPATHLEN] = { 0 };
2008-09-02 03:57:21 +02:00
bool
SavePrefs (bool silent)
2008-09-02 03:57:21 +02:00
{
2009-10-02 00:21:25 +02:00
char filepath[MAXPATHLEN];
2008-11-12 09:40:09 +01:00
int datasize;
int offset = 0;
2009-10-02 00:21:25 +02:00
int device = 0;
2009-10-06 08:38:32 +02:00
2009-10-02 00:21:25 +02:00
if(prefpath[0] != 0)
{
sprintf(filepath, "%s/%s", prefpath, PREF_FILE_NAME);
2009-10-02 00:21:25 +02:00
FindDevice(filepath, &device);
}
else if(appPath[0] != 0)
{
2009-10-05 03:33:15 +02:00
sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME);
strcpy(prefpath, appPath);
2009-10-02 00:21:25 +02:00
FindDevice(filepath, &device);
}
else
{
2009-10-06 08:38:32 +02:00
device = autoSaveMethod(silent);
2009-10-02 00:21:25 +02:00
if(device == 0)
return false;
sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER);
2011-01-20 03:53:13 +01:00
DIR *dir = opendir(filepath);
2010-08-14 07:54:00 +02:00
if (!dir)
{
2010-08-14 07:54:00 +02:00
if(mkdir(filepath, 0777) != 0)
return false;
sprintf(filepath, "%s%s/roms", pathPrefix[device], APPFOLDER);
2010-08-14 07:54:00 +02:00
if(mkdir(filepath, 0777) != 0)
return false;
sprintf(filepath, "%s%s/saves", pathPrefix[device], APPFOLDER);
2010-08-14 07:54:00 +02:00
if(mkdir(filepath, 0777) != 0)
return false;
}
else
{
2011-01-20 03:53:13 +01:00
closedir(dir);
}
2009-11-29 08:55:21 +01:00
sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME);
sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER);
2009-10-02 00:21:25 +02:00
}
2009-10-06 08:38:32 +02:00
2009-10-02 00:21:25 +02:00
if(device == 0)
2008-11-12 09:40:09 +01:00
return false;
2008-09-02 03:57:21 +02:00
if (!silent)
ShowAction ("Saving preferences...");
2008-09-02 03:57:21 +02:00
2009-03-28 18:23:08 +01:00
FixInvalidSettings();
AllocSaveBuffer ();
2009-10-02 00:21:25 +02:00
datasize = preparePrefsData ();
offset = SaveFile(filepath, datasize, silent);
2008-09-02 03:57:21 +02:00
FreeSaveBuffer ();
2009-03-28 18:23:08 +01:00
CancelAction();
2008-09-02 03:57:21 +02:00
if (offset > 0)
{
if (!silent)
2009-10-02 00:21:25 +02:00
InfoPrompt("Preferences saved");
2008-09-02 03:57:21 +02:00
return true;
}
return false;
}
/****************************************************************************
2009-10-02 00:21:25 +02:00
* Load Preferences from specified filepath
***************************************************************************/
2008-09-02 03:57:21 +02:00
bool
LoadPrefsFromMethod (char * path)
2008-09-02 03:57:21 +02:00
{
bool retval = false;
int offset = 0;
char filepath[MAXPATHLEN];
sprintf(filepath, "%s/%s", path, PREF_FILE_NAME);
2008-09-02 03:57:21 +02:00
AllocSaveBuffer ();
2009-10-02 00:21:25 +02:00
offset = LoadFile(filepath, SILENT);
2008-09-02 03:57:21 +02:00
if (offset > 0)
2009-10-02 00:21:25 +02:00
retval = decodePrefsData ();
FreeSaveBuffer ();
2009-10-02 00:21:25 +02:00
if(retval)
2009-12-23 08:23:08 +01:00
{
strcpy(prefpath, path);
2009-12-23 08:23:08 +01:00
if(appPath[0] == 0)
strcpy(appPath, prefpath);
}
2008-09-02 03:57:21 +02:00
return retval;
}
/****************************************************************************
* Load Preferences
* Checks sources consecutively until we find a preference file
***************************************************************************/
2009-03-28 18:23:08 +01:00
static bool prefLoaded = false;
bool LoadPrefs()
{
2009-03-28 18:23:08 +01:00
if(prefLoaded) // already attempted loading
return true;
bool prefFound = false;
2009-12-23 08:23:08 +01:00
char filepath[5][MAXPATHLEN];
2009-10-02 00:21:25 +02:00
int numDevices;
2009-10-06 08:38:32 +02:00
2009-10-02 00:21:25 +02:00
#ifdef HW_RVL
2009-12-23 08:23:08 +01:00
numDevices = 5;
sprintf(filepath[0], "%s", appPath);
2009-12-23 08:23:08 +01:00
sprintf(filepath[1], "sd:/apps/%s", APPFOLDER);
sprintf(filepath[2], "usb:/apps/%s", APPFOLDER);
sprintf(filepath[3], "sd:/%s", APPFOLDER);
sprintf(filepath[4], "usb:/%s", APPFOLDER);
2009-10-02 00:21:25 +02:00
for(int i=0; i<numDevices; i++)
{
2009-10-02 00:21:25 +02:00
prefFound = LoadPrefsFromMethod(filepath[i]);
if(prefFound)
break;
}
2021-02-07 00:04:50 +01:00
#else
if(ChangeInterface(DEVICE_SD_SLOTA, SILENT)) {
sprintf(filepath[0], "carda:/%s", APPFOLDER);
prefFound = LoadPrefsFromMethod(filepath[0]);
}
else if(ChangeInterface(DEVICE_SD_SLOTB, SILENT)) {
sprintf(filepath[0], "cardb:/%s", APPFOLDER);
prefFound = LoadPrefsFromMethod(filepath[0]);
}
else if(ChangeInterface(DEVICE_SD_PORT2, SILENT)) {
sprintf(filepath[0], "port2:/%s", APPFOLDER);
prefFound = LoadPrefsFromMethod(filepath[0]);
}
#endif
2009-03-28 18:23:08 +01:00
prefLoaded = true; // attempted to load preferences
if(prefFound)
FixInvalidSettings();
2018-08-13 00:37:15 +02:00
// attempt to create directories if they don't exist
if((GCSettings.LoadMethod == DEVICE_SD && ChangeInterface(DEVICE_SD, SILENT))
|| (GCSettings.LoadMethod == DEVICE_USB && ChangeInterface(DEVICE_USB, SILENT)))
{
char dirPath[MAXPATHLEN];
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ScreenshotsFolder);
CreateDirectory(dirPath);
2019-01-05 10:54:09 +01:00
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.CoverFolder);
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ArtworkFolder);
CreateDirectory(dirPath);
2018-08-13 00:37:15 +02:00
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.CheatFolder);
CreateDirectory(dirPath);
}
if(GCSettings.videomode > 0) {
ResetVideo_Menu();
}
#ifdef HW_RVL
bg_music = (u8 * )bg_music_ogg;
bg_music_size = bg_music_ogg_size;
LoadBgMusic();
#endif
ChangeLanguage();
return prefFound;
}