2008-09-16 07:42:21 +02:00
|
|
|
/****************************************************************************
|
2008-09-17 04:27:55 +02:00
|
|
|
* Visual Boy Advance GX
|
2008-09-16 07:42:21 +02:00
|
|
|
*
|
|
|
|
* Tantric September 2008
|
|
|
|
*
|
|
|
|
* preferences.cpp
|
|
|
|
*
|
|
|
|
* Preferences save/load to XML file
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <mxml.h>
|
|
|
|
|
|
|
|
#include "vba.h"
|
2009-04-08 09:08:12 +02:00
|
|
|
#include "vbaconfig.h"
|
|
|
|
#include "menu.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
#include "memcardop.h"
|
|
|
|
#include "fileop.h"
|
2009-04-08 09:08:12 +02:00
|
|
|
#include "filebrowser.h"
|
2008-09-22 07:01:57 +02:00
|
|
|
#include "input.h"
|
2009-04-08 09:08:12 +02:00
|
|
|
#include "button_mapping.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Prepare Preferences Data
|
|
|
|
*
|
|
|
|
* This sets up the save buffer for saving.
|
|
|
|
***************************************************************************/
|
2009-01-06 06:33:13 +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-09-16 07:42:21 +02:00
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static char temp[20];
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static const char * toStr(int i)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
sprintf(temp, "%d", i);
|
|
|
|
return temp;
|
|
|
|
}
|
2008-12-30 01:10:12 +01:00
|
|
|
static const char * FtoStr(float i)
|
2008-10-24 08:16:15 +02:00
|
|
|
{
|
|
|
|
sprintf(temp, "%.2f", i);
|
|
|
|
return temp;
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static void createXMLSection(const char * name, const char * description)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
section = mxmlNewElement(data, "section");
|
|
|
|
mxmlElementSetAttr(section, "name", name);
|
|
|
|
mxmlElementSetAttr(section, "description", description);
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static void createXMLSetting(const char * name, const char * description, const char * value)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
item = mxmlNewElement(section, "setting");
|
|
|
|
mxmlElementSetAttr(item, "name", name);
|
|
|
|
mxmlElementSetAttr(item, "value", value);
|
|
|
|
mxmlElementSetAttr(item, "description", description);
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static void createXMLController(unsigned int controller[], const char * name, const char * description)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
item = mxmlNewElement(section, "controller");
|
|
|
|
mxmlElementSetAttr(item, "name", name);
|
|
|
|
mxmlElementSetAttr(item, "description", description);
|
|
|
|
|
|
|
|
// create buttons
|
2008-09-22 07:01:57 +02:00
|
|
|
for(int i=0; i < MAXJP; i++)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
elem = mxmlNewElement(item, "button");
|
|
|
|
mxmlElementSetAttr(elem, "number", toStr(i));
|
|
|
|
mxmlElementSetAttr(elem, "assignment", toStr(controller[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static const char * XMLSaveCallback(mxml_node_t *node, int where)
|
2008-09-16 07:42:21 +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:10:12 +01:00
|
|
|
static int
|
2008-09-16 07:42:21 +02:00
|
|
|
preparePrefsData (int method)
|
|
|
|
{
|
|
|
|
xml = mxmlNewXML("1.0");
|
|
|
|
mxmlSetWrapMargin(0); // disable line wrapping
|
|
|
|
|
|
|
|
data = mxmlNewElement(xml, "file");
|
2009-04-08 09:08:12 +02:00
|
|
|
mxmlElementSetAttr(data, "app", APPNAME);
|
|
|
|
mxmlElementSetAttr(data, "version", APPVERSION);
|
2008-09-16 07:42: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);
|
|
|
|
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
|
2008-09-17 03:54:21 +02:00
|
|
|
//createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
|
2008-10-11 10:06:36 +02:00
|
|
|
createXMLSetting("VerifySaves", "Verify Memory Card Saves", toStr(GCSettings.VerifySaves));
|
2008-09-16 07:42: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-04-08 09:08:12 +02:00
|
|
|
createXMLSection("Video", "Video Settings");
|
2008-10-11 10:06:36 +02:00
|
|
|
|
2008-10-24 08:16:15 +02:00
|
|
|
createXMLSetting("ZoomLevel", "Zoom Level", FtoStr(GCSettings.ZoomLevel));
|
|
|
|
createXMLSetting("render", "Video Filtering", toStr(GCSettings.render));
|
2009-03-04 08:01:04 +01:00
|
|
|
createXMLSetting("scaling", "Aspect Ratio Correction", toStr(GCSettings.scaling));
|
2009-01-26 08:11:02 +01:00
|
|
|
createXMLSetting("xshift", "Horizontal Video Shift", toStr(GCSettings.xshift));
|
|
|
|
createXMLSetting("yshift", "Vertical Video Shift", toStr(GCSettings.yshift));
|
2009-04-26 02:05:49 +02:00
|
|
|
createXMLSetting("colorize", "Colorize Mono Gameboy", toStr(GCSettings.colorize));
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2009-04-08 09:08:12 +02: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-09-16 07:42:21 +02:00
|
|
|
createXMLSection("Controller", "Controller Settings");
|
|
|
|
|
2009-03-04 08:01:04 +01:00
|
|
|
createXMLSetting("WiiControls", "Match Wii Game", toStr(GCSettings.WiiControls));
|
2009-04-08 09:08:12 +02:00
|
|
|
createXMLController(btnmap[CTRLR_GCPAD], "gcpadmap", "GameCube Pad");
|
|
|
|
createXMLController(btnmap[CTRLR_WIIMOTE], "wmpadmap", "Wiimote");
|
|
|
|
createXMLController(btnmap[CTRLR_CLASSIC], "ccpadmap", "Classic Controller");
|
|
|
|
createXMLController(btnmap[CTRLR_NUNCHUK], "ncpadmap", "Nunchuk");
|
|
|
|
createXMLController(btnmap[CTRLR_KEYBOARD], "kbpadmap", "Keyboard");
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSaveCallback);
|
|
|
|
|
|
|
|
mxmlDelete(xml);
|
|
|
|
|
|
|
|
return datasize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* loadXMLSetting
|
|
|
|
*
|
|
|
|
* Load XML elements into variables for an individual variable
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static void loadXMLSetting(char * var, const char * name, int maxsize)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
|
|
|
|
if(item)
|
2009-01-06 06:33:13 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "value");
|
|
|
|
if(tmp)
|
|
|
|
snprintf(var, maxsize, "%s", tmp);
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
2008-12-30 01:10:12 +01:00
|
|
|
static void loadXMLSetting(int * var, const char * name)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
|
|
|
|
if(item)
|
2009-01-06 06:33:13 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "value");
|
|
|
|
if(tmp)
|
|
|
|
*var = atoi(tmp);
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
2008-12-30 01:10:12 +01:00
|
|
|
static void loadXMLSetting(float * var, const char * name)
|
2008-10-24 08:16:15 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
|
|
|
|
if(item)
|
2009-01-06 06:33:13 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "value");
|
|
|
|
if(tmp)
|
|
|
|
*var = atof(tmp);
|
|
|
|
}
|
2008-10-24 08:16:15 +02:00
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* loadXMLController
|
|
|
|
*
|
|
|
|
* Load XML elements into variables for a controller mapping
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static void loadXMLController(unsigned int controller[], const char * name)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND);
|
|
|
|
|
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
// populate buttons
|
2008-09-22 07:01:57 +02:00
|
|
|
for(int i=0; i < MAXJP; i++)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
elem = mxmlFindElement(item, xml, "button", "number", toStr(i), MXML_DESCEND);
|
|
|
|
if(elem)
|
2009-01-06 06:33:13 +01:00
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(elem, "assignment");
|
|
|
|
if(tmp)
|
|
|
|
controller[i] = atoi(tmp);
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* decodePrefsData
|
|
|
|
*
|
|
|
|
* Decodes preferences - parses XML and loads preferences into the variables
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static bool
|
2008-09-16 07:42:21 +02:00
|
|
|
decodePrefsData (int method)
|
|
|
|
{
|
2009-01-06 06:33:13 +01:00
|
|
|
bool result = false;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
xml = mxmlLoadString(NULL, (char *)savebuffer, MXML_TEXT_CALLBACK);
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2009-01-06 06:33:13 +01:00
|
|
|
if(xml)
|
|
|
|
{
|
|
|
|
// check settings version
|
2009-04-08 09:08:12 +02:00
|
|
|
// we don't do anything with the version #, but we'll store it anyway
|
2009-01-06 06:33:13 +01:00
|
|
|
item = mxmlFindElement(xml, xml, "file", "version", NULL, MXML_DESCEND);
|
|
|
|
if(item) // a version entry exists
|
|
|
|
{
|
|
|
|
const char * version = mxmlElementGetAttr(item, "version");
|
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
if(version && strlen(version) == 5)
|
2009-01-06 06:33:13 +01:00
|
|
|
{
|
|
|
|
// 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';
|
|
|
|
int curMajor = APPVERSION[0] - '0';
|
|
|
|
int curMinor = APPVERSION[2] - '0';
|
|
|
|
int curPoint = APPVERSION[4] - '0';
|
|
|
|
|
|
|
|
// first we'll check that the versioning is valid
|
|
|
|
if(!(verMajor >= 0 && verMajor <= 9 &&
|
|
|
|
verMinor >= 0 && verMinor <= 9 &&
|
|
|
|
verPoint >= 0 && verPoint <= 9))
|
|
|
|
result = false;
|
2009-03-04 08:01:04 +01:00
|
|
|
else if(verPoint < 8 && verMajor == 1) // less than version 1.0.8
|
|
|
|
result = false; // reset settings (sorry, should update settings instead)
|
2009-01-06 06:33:13 +01:00
|
|
|
else if(verMajor > curMajor || verMinor > curMinor || verPoint > curPoint) // some future version
|
|
|
|
result = false; // reset settings
|
|
|
|
else
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2009-01-06 06:33:13 +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-04-08 09:08:12 +02:00
|
|
|
// Video Settings
|
2009-01-06 06:33:13 +01:00
|
|
|
|
|
|
|
loadXMLSetting(&GCSettings.ZoomLevel, "ZoomLevel");
|
|
|
|
loadXMLSetting(&GCSettings.render, "render");
|
2009-03-04 08:01:04 +01:00
|
|
|
loadXMLSetting(&GCSettings.scaling, "scaling");
|
2009-01-26 08:11:02 +01:00
|
|
|
loadXMLSetting(&GCSettings.xshift, "xshift");
|
|
|
|
loadXMLSetting(&GCSettings.yshift, "yshift");
|
2009-04-26 02:05:49 +02:00
|
|
|
loadXMLSetting(&GCSettings.colorize, "colorize");
|
2009-01-06 06:33:13 +01:00
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
// Menu Settings
|
|
|
|
|
|
|
|
loadXMLSetting(&GCSettings.WiimoteOrientation, "WiimoteOrientation");
|
|
|
|
loadXMLSetting(&GCSettings.ExitAction, "ExitAction");
|
|
|
|
loadXMLSetting(&GCSettings.MusicVolume, "MusicVolume");
|
|
|
|
loadXMLSetting(&GCSettings.SFXVolume, "SFXVolume");
|
|
|
|
|
2009-01-06 06:33:13 +01:00
|
|
|
// Controller Settings
|
|
|
|
|
2009-03-04 08:01:04 +01:00
|
|
|
loadXMLSetting(&GCSettings.WiiControls, "WiiControls");
|
2009-04-08 09:08:12 +02:00
|
|
|
loadXMLController(btnmap[CTRLR_GCPAD], "gcpadmap");
|
|
|
|
loadXMLController(btnmap[CTRLR_WIIMOTE], "wmpadmap");
|
|
|
|
loadXMLController(btnmap[CTRLR_CLASSIC], "ccpadmap");
|
|
|
|
loadXMLController(btnmap[CTRLR_NUNCHUK], "ncpadmap");
|
|
|
|
loadXMLController(btnmap[CTRLR_KEYBOARD], "kbpadmap");
|
2009-01-06 06:33:13 +01:00
|
|
|
}
|
|
|
|
mxmlDelete(xml);
|
|
|
|
}
|
|
|
|
return result;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Save Preferences
|
|
|
|
***************************************************************************/
|
|
|
|
bool
|
2008-12-19 00:21:51 +01:00
|
|
|
SavePrefs (bool silent)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
char filepath[1024];
|
|
|
|
int datasize;
|
|
|
|
int offset = 0;
|
|
|
|
|
2008-12-19 00:21:51 +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:23:48 +01:00
|
|
|
int method = autoSaveMethod(silent);
|
2008-09-29 09:35:26 +02:00
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
return false;
|
|
|
|
|
2008-11-12 08:53:25 +01:00
|
|
|
if(!MakeFilePath(filepath, FILE_PREF, method))
|
|
|
|
return false;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
if (!silent)
|
2008-12-18 19:58:30 +01:00
|
|
|
ShowAction ("Saving preferences...");
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
FixInvalidSettings();
|
|
|
|
|
2008-11-12 08:53:25 +01:00
|
|
|
AllocSaveBuffer ();
|
|
|
|
datasize = preparePrefsData (method);
|
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
// Set the comments
|
|
|
|
char prefscomment[2][32];
|
|
|
|
memset(prefscomment, 0, 64);
|
|
|
|
sprintf (prefscomment[0], "%s Prefs", APPNAME);
|
|
|
|
sprintf (prefscomment[1], "Preferences");
|
|
|
|
SetMCSaveComments(prefscomment);
|
|
|
|
}
|
|
|
|
|
2008-11-12 08:53:25 +01:00
|
|
|
offset = SaveFile(filepath, datasize, method, silent);
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
FreeSaveBuffer ();
|
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
CancelAction();
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
if (offset > 0)
|
|
|
|
{
|
|
|
|
if (!silent)
|
2009-04-08 09:08:12 +02:00
|
|
|
InfoPrompt("Preferences saved");
|
2008-09-16 07:42:21 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Load Preferences from specified method
|
|
|
|
***************************************************************************/
|
|
|
|
bool
|
|
|
|
LoadPrefsFromMethod (int method)
|
|
|
|
{
|
|
|
|
bool retval = false;
|
|
|
|
char filepath[1024];
|
|
|
|
int offset = 0;
|
|
|
|
|
2008-11-12 08:53:25 +01:00
|
|
|
if(!MakeFilePath(filepath, FILE_PREF, method))
|
|
|
|
return false;
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
AllocSaveBuffer ();
|
|
|
|
|
2008-11-12 08:53:25 +01:00
|
|
|
offset = LoadFile(filepath, method, SILENT);
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
retval = decodePrefsData (method);
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
FreeSaveBuffer ();
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Load Preferences
|
|
|
|
* Checks sources consecutively until we find a preference file
|
|
|
|
***************************************************************************/
|
2009-04-08 09:08:12 +02:00
|
|
|
static bool prefLoaded = false;
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
bool LoadPrefs()
|
|
|
|
{
|
2009-04-08 09:08:12 +02:00
|
|
|
if(prefLoaded) // already attempted loading
|
|
|
|
return true;
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
bool prefFound = false;
|
2008-12-18 19:58:30 +01:00
|
|
|
if(ChangeInterface(METHOD_SD, SILENT))
|
2008-09-16 07:42:21 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_SD);
|
2008-12-18 19:58:30 +01:00
|
|
|
if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
|
2008-09-16 07:42:21 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_USB);
|
2009-04-08 09:08:12 +02:00
|
|
|
if(!prefFound && TestMC(CARD_SLOTA, SILENT))
|
2008-09-16 07:42:21 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA);
|
2009-04-08 09:08:12 +02:00
|
|
|
if(!prefFound && TestMC(CARD_SLOTB, SILENT))
|
2008-09-16 07:42:21 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB);
|
2008-12-18 19:58:30 +01:00
|
|
|
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
|
2008-09-16 07:42:21 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(METHOD_SMB);
|
|
|
|
|
2009-04-08 09:08:12 +02:00
|
|
|
prefLoaded = true; // attempted to load preferences
|
|
|
|
|
|
|
|
if(prefFound)
|
|
|
|
FixInvalidSettings();
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
return prefFound;
|
|
|
|
}
|