2008-08-06 03:09:59 +02:00
|
|
|
/****************************************************************************
|
2008-09-12 07:28:40 +02:00
|
|
|
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
2008-09-12 07:28:40 +02:00
|
|
|
* Tantric September 2008
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
|
|
|
* preferences.cpp
|
|
|
|
*
|
2008-09-12 07:28:40 +02:00
|
|
|
* Preferences save/load to XML file
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
2008-08-22 22:23:32 +02:00
|
|
|
#include <mxml.h>
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-08-22 04:47:08 +02:00
|
|
|
#include "snes9xGX.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
#include "images/saveicon.h"
|
2009-03-11 18:28:37 +01:00
|
|
|
#include "menu.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
#include "memcardop.h"
|
2008-08-07 07:19:17 +02:00
|
|
|
#include "fileop.h"
|
2009-03-11 18:28:37 +01:00
|
|
|
#include "filebrowser.h"
|
2008-09-27 09:13:52 +02:00
|
|
|
#include "input.h"
|
2009-03-11 18:28:37 +01:00
|
|
|
#include "button_mapping.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Prepare Preferences Data
|
|
|
|
*
|
2008-08-07 05:25:02 +02:00
|
|
|
* This sets up the save buffer for saving.
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2009-01-05 23:23:41 +01: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-08-20 09:58:55 +02:00
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static char temp[20];
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static const char * toStr(int i)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
sprintf(temp, "%d", i);
|
|
|
|
return temp;
|
|
|
|
}
|
2008-12-30 01:08:17 +01:00
|
|
|
static const char * FtoStr(float i)
|
2008-10-24 07:11:01 +02:00
|
|
|
{
|
|
|
|
sprintf(temp, "%.2f", i);
|
|
|
|
return temp;
|
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static void createXMLSection(const char * name, const char * description)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
section = mxmlNewElement(data, "section");
|
|
|
|
mxmlElementSetAttr(section, "name", name);
|
|
|
|
mxmlElementSetAttr(section, "description", description);
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static void createXMLSetting(const char * name, const char * description, const char * value)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
item = mxmlNewElement(section, "setting");
|
|
|
|
mxmlElementSetAttr(item, "name", name);
|
|
|
|
mxmlElementSetAttr(item, "value", value);
|
|
|
|
mxmlElementSetAttr(item, "description", description);
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static void createXMLController(unsigned int controller[], const char * name, const char * description)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
item = mxmlNewElement(section, "controller");
|
|
|
|
mxmlElementSetAttr(item, "name", name);
|
|
|
|
mxmlElementSetAttr(item, "description", description);
|
|
|
|
|
|
|
|
// create buttons
|
2008-09-27 09:13:52 +02:00
|
|
|
for(int i=0; i < MAXJP; i++)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
elem = mxmlNewElement(item, "button");
|
|
|
|
mxmlElementSetAttr(elem, "number", toStr(i));
|
|
|
|
mxmlElementSetAttr(elem, "assignment", toStr(controller[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static const char * XMLSaveCallback(mxml_node_t *node, int where)
|
2008-08-22 04:47:08 +02:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = node->value.element.name;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static int
|
2008-08-20 09:58:55 +02:00
|
|
|
preparePrefsData (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-20 09:58:55 +02:00
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
// add save icon and comments for Memory Card saves
|
|
|
|
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
offset = sizeof (saveicon);
|
|
|
|
|
|
|
|
// Copy in save icon
|
|
|
|
memcpy (savebuffer, saveicon, offset);
|
|
|
|
|
|
|
|
// And the comments
|
2009-01-05 23:23:41 +01:00
|
|
|
char prefscomment[2][32];
|
2008-12-22 10:20:35 +01:00
|
|
|
memset(prefscomment, 0, 64);
|
2008-12-24 09:02:04 +01:00
|
|
|
sprintf (prefscomment[0], "%s Prefs", APPNAME);
|
2008-08-22 04:47:08 +02:00
|
|
|
sprintf (prefscomment[1], "Preferences");
|
2008-08-20 09:58:55 +02:00
|
|
|
memcpy (savebuffer + offset, prefscomment, 64);
|
|
|
|
offset += 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
xml = mxmlNewXML("1.0");
|
2008-08-22 04:47:08 +02:00
|
|
|
mxmlSetWrapMargin(0); // disable line wrapping
|
2008-08-20 09:58:55 +02:00
|
|
|
|
|
|
|
data = mxmlNewElement(xml, "file");
|
2008-12-24 09:02:04 +01:00
|
|
|
mxmlElementSetAttr(data, "app",APPNAME);
|
|
|
|
mxmlElementSetAttr(data, "version",APPVERSION);
|
2008-08-20 09:58:55 +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);
|
|
|
|
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
|
|
|
|
createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
|
|
|
|
createXMLSetting("VerifySaves", "Verify Memory Card Saves", toStr(GCSettings.VerifySaves));
|
|
|
|
|
|
|
|
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-11 18:28:37 +01:00
|
|
|
createXMLSection("Video", "Video Settings");
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-10-24 07:11:01 +02:00
|
|
|
createXMLSetting("ZoomLevel", "Zoom Level", FtoStr(GCSettings.ZoomLevel));
|
2008-08-20 09:58:55 +02:00
|
|
|
createXMLSetting("render", "Video Filtering", toStr(GCSettings.render));
|
2008-09-30 08:43:34 +02:00
|
|
|
createXMLSetting("widescreen", "Aspect Ratio Correction", toStr(GCSettings.widescreen));
|
2009-01-30 08:25:30 +01:00
|
|
|
createXMLSetting("FilterMethod", "Filter Method", toStr(GCSettings.FilterMethod));
|
2008-09-30 08:43:34 +02:00
|
|
|
createXMLSetting("xshift", "Horizontal Video Shift", toStr(GCSettings.xshift));
|
|
|
|
createXMLSetting("yshift", "Vertical Video Shift", toStr(GCSettings.yshift));
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
createXMLSection("Menu", "Menu Settings");
|
|
|
|
|
|
|
|
createXMLSetting("WiimoteOrientation", "Wiimote Orientation", toStr(GCSettings.WiimoteOrientation));
|
|
|
|
createXMLSetting("ExitAction", "Exit Action", toStr(GCSettings.ExitAction));
|
|
|
|
createXMLSetting("MusicVolume", "Music Volume", toStr(GCSettings.MusicVolume));
|
|
|
|
createXMLSetting("SFXVolume", "Sound Effects Volume", toStr(GCSettings.SFXVolume));
|
|
|
|
|
2008-08-20 09:58:55 +02:00
|
|
|
createXMLSection("Controller", "Controller Settings");
|
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
createXMLSetting("Controller", "Controller", toStr(GCSettings.Controller));
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
createXMLController(btnmap[CTRL_PAD][CTRLR_GCPAD], "btnmap_pad_gcpad", "SNES Pad - GameCube Controller");
|
|
|
|
createXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote", "SNES Pad - Wiimote");
|
|
|
|
createXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic", "SNES Pad - Classic Controller");
|
|
|
|
createXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk", "SNES Pad - Nunchuk + Wiimote");
|
|
|
|
createXMLController(btnmap[CTRL_SCOPE][CTRLR_GCPAD], "btnmap_scope_gcpad", "Superscope - GameCube Controller");
|
|
|
|
createXMLController(btnmap[CTRL_SCOPE][CTRLR_WIIMOTE], "btnmap_scope_wiimote", "Superscope - Wiimote");
|
|
|
|
createXMLController(btnmap[CTRL_MOUSE][CTRLR_GCPAD], "btnmap_mouse_gcpad", "MMouse - GameCube Controller");
|
|
|
|
createXMLController(btnmap[CTRL_MOUSE][CTRLR_WIIMOTE], "btnmap_mouse_wiimote", "Mouse - Wiimote");
|
|
|
|
createXMLController(btnmap[CTRL_JUST][CTRLR_GCPAD], "btnmap_just_gcpad", "Justifier - GameCube Controller");
|
|
|
|
createXMLController(btnmap[CTRL_JUST][CTRLR_WIIMOTE], "btnmap_just_wiimote", "Justifier - Wiimote");
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-09-30 08:43:34 +02:00
|
|
|
int datasize = mxmlSaveString(xml, (char *)savebuffer+offset, (SAVEBUFFERSIZE-offset), XMLSaveCallback);
|
2008-08-20 09:58:55 +02:00
|
|
|
|
|
|
|
mxmlDelete(xml);
|
|
|
|
|
|
|
|
return datasize;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2008-09-12 07:28:40 +02:00
|
|
|
* loadXMLSetting
|
|
|
|
*
|
|
|
|
* Load XML elements into variables for an individual variable
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static void loadXMLSetting(char * var, const char * name, int maxsize)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
|
|
|
|
if(item)
|
2009-01-05 23:23:41 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "value");
|
|
|
|
if(tmp)
|
|
|
|
snprintf(var, maxsize, "%s", tmp);
|
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
}
|
2008-12-30 01:08:17 +01:00
|
|
|
static void loadXMLSetting(int * var, const char * name)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
|
|
|
|
if(item)
|
2009-01-05 23:23:41 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "value");
|
|
|
|
if(tmp)
|
|
|
|
*var = atoi(tmp);
|
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
}
|
2008-12-30 01:08:17 +01:00
|
|
|
static void loadXMLSetting(float * var, const char * name)
|
2008-10-24 07:11:01 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
|
|
|
|
if(item)
|
2009-01-05 23:23:41 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "value");
|
|
|
|
if(tmp)
|
|
|
|
*var = atof(tmp);
|
|
|
|
}
|
2008-10-24 07:11:01 +02:00
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* loadXMLController
|
|
|
|
*
|
|
|
|
* Load XML elements into variables for a controller mapping
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static void loadXMLController(unsigned int controller[], const char * name)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND);
|
|
|
|
|
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
// populate buttons
|
2008-09-27 09:13:52 +02:00
|
|
|
for(int i=0; i < MAXJP; i++)
|
2008-08-20 09:58:55 +02:00
|
|
|
{
|
|
|
|
elem = mxmlFindElement(item, xml, "button", "number", toStr(i), MXML_DESCEND);
|
|
|
|
if(elem)
|
2009-01-05 23:23:41 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(elem, "assignment");
|
|
|
|
if(tmp)
|
|
|
|
controller[i] = atoi(tmp);
|
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* decodePrefsData
|
|
|
|
*
|
|
|
|
* Decodes preferences - parses XML and loads preferences into the variables
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static bool
|
2008-08-20 09:58:55 +02:00
|
|
|
decodePrefsData (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2009-01-05 23:23:41 +01:00
|
|
|
bool result = false;
|
2008-08-20 09:58:55 +02:00
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
// skip save icon and comments for Memory Card saves
|
|
|
|
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
offset = sizeof (saveicon);
|
2009-01-05 23:23:41 +01:00
|
|
|
offset += 64; // sizeof comment
|
2008-08-20 09:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xml = mxmlLoadString(NULL, (char *)savebuffer+offset, MXML_TEXT_CALLBACK);
|
|
|
|
|
2009-01-05 23:23:41 +01:00
|
|
|
if(xml)
|
|
|
|
{
|
|
|
|
// check settings version
|
|
|
|
// we don't do anything with the version #, but we'll store it anyway
|
|
|
|
item = mxmlFindElement(xml, xml, "file", "version", NULL, MXML_DESCEND);
|
|
|
|
if(item) // a version entry exists
|
|
|
|
{
|
|
|
|
const char * version = mxmlElementGetAttr(item, "version");
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2009-01-05 23:23:41 +01:00
|
|
|
if(version)
|
|
|
|
{
|
|
|
|
result = true; // assume version is valid
|
|
|
|
}
|
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2009-01-05 23:23:41 +01:00
|
|
|
if(result)
|
|
|
|
{
|
|
|
|
// File Settings
|
|
|
|
|
|
|
|
loadXMLSetting(&GCSettings.AutoLoad, "AutoLoad");
|
|
|
|
loadXMLSetting(&GCSettings.AutoSave, "AutoSave");
|
|
|
|
loadXMLSetting(&GCSettings.LoadMethod, "LoadMethod");
|
|
|
|
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
|
|
|
|
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
|
|
|
|
loadXMLSetting(GCSettings.SaveFolder, "SaveFolder", sizeof(GCSettings.SaveFolder));
|
|
|
|
loadXMLSetting(GCSettings.CheatFolder, "CheatFolder", sizeof(GCSettings.CheatFolder));
|
|
|
|
loadXMLSetting(&GCSettings.VerifySaves, "VerifySaves");
|
|
|
|
|
|
|
|
// Network Settings
|
|
|
|
|
|
|
|
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-11 18:28:37 +01:00
|
|
|
// Video Settings
|
2009-01-05 23:23:41 +01:00
|
|
|
|
|
|
|
loadXMLSetting(&GCSettings.ZoomLevel, "ZoomLevel");
|
|
|
|
loadXMLSetting(&GCSettings.render, "render");
|
|
|
|
loadXMLSetting(&GCSettings.widescreen, "widescreen");
|
2009-01-30 08:25:30 +01:00
|
|
|
loadXMLSetting(&GCSettings.FilterMethod, "FilterMethod");
|
2009-01-05 23:23:41 +01:00
|
|
|
loadXMLSetting(&GCSettings.xshift, "xshift");
|
|
|
|
loadXMLSetting(&GCSettings.yshift, "yshift");
|
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
// Menu Settings
|
|
|
|
|
|
|
|
loadXMLSetting(&GCSettings.WiimoteOrientation, "WiimoteOrientation");
|
|
|
|
loadXMLSetting(&GCSettings.ExitAction, "ExitAction");
|
|
|
|
loadXMLSetting(&GCSettings.MusicVolume, "MusicVolume");
|
|
|
|
loadXMLSetting(&GCSettings.SFXVolume, "SFXVolume");
|
2009-01-05 23:23:41 +01:00
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
// Controller Settings
|
2009-01-05 23:23:41 +01:00
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
loadXMLSetting(&GCSettings.Controller, "Controller");
|
|
|
|
|
|
|
|
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_NUNCHUK], "btnmap_pad_nunchuk");
|
|
|
|
loadXMLController(btnmap[CTRL_SCOPE][CTRLR_GCPAD], "btnmap_scope_gcpad");
|
|
|
|
loadXMLController(btnmap[CTRL_SCOPE][CTRLR_WIIMOTE], "btnmap_scope_wiimote");
|
|
|
|
loadXMLController(btnmap[CTRL_MOUSE][CTRLR_GCPAD], "btnmap_mouse_gcpad");
|
|
|
|
loadXMLController(btnmap[CTRL_MOUSE][CTRLR_WIIMOTE], "btnmap_mouse_wiimote");
|
|
|
|
loadXMLController(btnmap[CTRL_JUST][CTRLR_GCPAD], "btnmap_just_gcpad");
|
|
|
|
loadXMLController(btnmap[CTRL_JUST][CTRLR_WIIMOTE], "btnmap_just_wiimote");
|
2009-01-05 23:23:41 +01:00
|
|
|
}
|
|
|
|
mxmlDelete(xml);
|
|
|
|
}
|
|
|
|
return result;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Save Preferences
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
bool
|
2008-12-19 00:22:32 +01:00
|
|
|
SavePrefs (bool silent)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-11-12 08:50:39 +01:00
|
|
|
char filepath[1024];
|
|
|
|
int datasize;
|
|
|
|
int offset = 0;
|
|
|
|
|
2008-12-19 00:22:32 +01:00
|
|
|
// We'll save using the first available method (probably SD) since this
|
|
|
|
// is the method preferences will be loaded from by default
|
2008-12-22 10:20:35 +01:00
|
|
|
int method = autoSaveMethod(silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
return false;
|
|
|
|
|
2008-11-12 08:50:39 +01:00
|
|
|
if(!MakeFilePath(filepath, FILE_PREF, method))
|
|
|
|
return false;
|
2008-08-07 05:25:02 +02:00
|
|
|
|
|
|
|
if (!silent)
|
2008-12-18 19:36:30 +01:00
|
|
|
ShowAction ("Saving preferences...");
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-11-12 08:50:39 +01:00
|
|
|
AllocSaveBuffer ();
|
|
|
|
datasize = preparePrefsData (method);
|
|
|
|
|
|
|
|
offset = SaveFile(filepath, datasize, method, silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-09-27 09:13:52 +02:00
|
|
|
FreeSaveBuffer ();
|
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
CancelAction();
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
if (offset > 0)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-20 09:58:55 +02:00
|
|
|
if (!silent)
|
2009-03-11 18:28:37 +01:00
|
|
|
InfoPrompt("Preferences saved");
|
2008-08-20 09:58:55 +02:00
|
|
|
return true;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
2008-08-20 09:58:55 +02:00
|
|
|
return false;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-09-04 04:42:27 +02:00
|
|
|
* Load Preferences from specified method
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
bool
|
2008-09-04 05:02:29 +02:00
|
|
|
LoadPrefsFromMethod (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
bool retval = false;
|
|
|
|
char filepath[1024];
|
|
|
|
int offset = 0;
|
|
|
|
|
2008-11-12 08:50:39 +01:00
|
|
|
if(!MakeFilePath(filepath, FILE_PREF, method))
|
|
|
|
return false;
|
|
|
|
|
2008-09-27 09:13:52 +02:00
|
|
|
AllocSaveBuffer ();
|
|
|
|
|
2008-11-12 08:50:39 +01:00
|
|
|
offset = LoadFile(filepath, method, SILENT);
|
2008-08-07 05:25:02 +02:00
|
|
|
|
|
|
|
if (offset > 0)
|
2008-08-20 09:58:55 +02:00
|
|
|
retval = decodePrefsData (method);
|
2008-09-04 04:42:27 +02:00
|
|
|
|
2008-09-27 09:13:52 +02:00
|
|
|
FreeSaveBuffer ();
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
return retval;
|
|
|
|
}
|
2008-09-04 04:42:27 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Load Preferences
|
|
|
|
* Checks sources consecutively until we find a preference file
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2009-03-11 18:28:37 +01:00
|
|
|
static bool prefLoaded = false;
|
|
|
|
|
2008-09-04 04:42:27 +02:00
|
|
|
bool LoadPrefs()
|
|
|
|
{
|
2009-03-11 18:28:37 +01:00
|
|
|
if(prefLoaded) // already attempted loading
|
|
|
|
return true;
|
|
|
|
|
2008-09-04 04:42:27 +02:00
|
|
|
bool prefFound = false;
|
2008-12-18 19:36:30 +01:00
|
|
|
if(ChangeInterface(METHOD_SD, SILENT))
|
2008-09-04 04:42:27 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_SD);
|
2008-12-18 19:36:30 +01:00
|
|
|
if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
|
2008-09-04 04:42:27 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_USB);
|
2009-03-11 18:28:37 +01:00
|
|
|
if(!prefFound && TestMC(CARD_SLOTA, SILENT))
|
2008-09-04 04:42:27 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA);
|
2009-03-11 18:28:37 +01:00
|
|
|
if(!prefFound && TestMC(CARD_SLOTB, SILENT))
|
2008-09-04 04:42:27 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB);
|
2008-12-18 19:36:30 +01:00
|
|
|
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
|
2008-09-04 04:42:27 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_SMB);
|
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
prefLoaded = true; // attempted to load preferences
|
|
|
|
|
2008-09-04 04:42:27 +02:00
|
|
|
return prefFound;
|
|
|
|
}
|