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>
|
2011-01-20 03:53:27 +01:00
|
|
|
#include <dirent.h>
|
2008-09-16 07:42:21 +02:00
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <mxml.h>
|
|
|
|
|
2010-03-22 00:49:59 +01:00
|
|
|
#include "vbagx.h"
|
2009-04-08 09:08:12 +02:00
|
|
|
#include "menu.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
#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"
|
2009-05-27 19:31:18 +02:00
|
|
|
#include "gamesettings.h"
|
|
|
|
|
2010-01-25 22:06:27 +01:00
|
|
|
struct SGCSettings GCSettings;
|
2009-06-01 09:20:23 +02:00
|
|
|
static gamePalette *palettes = NULL;
|
2009-05-29 22:04:11 +02:00
|
|
|
static int loadedPalettes = 0;
|
|
|
|
|
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
|
|
|
|
2009-10-02 00:42:02 +02:00
|
|
|
static mxml_node_t *mxmlFindNewElement(mxml_node_t *parent, const char *nodename, const char *attr=NULL, const char *value=NULL)
|
|
|
|
{
|
2009-05-27 19:31:18 +02:00
|
|
|
mxml_node_t *node = mxmlFindElement(parent, xml, nodename, attr, value, MXML_DESCEND);
|
2009-10-02 00:42:02 +02:00
|
|
|
if (!node)
|
|
|
|
{
|
2009-05-27 19:31:18 +02:00
|
|
|
node = mxmlNewElement(parent, nodename);
|
|
|
|
if (attr && value) mxmlElementSetAttr(node, attr, value);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2009-05-27 19:31:18 +02:00
|
|
|
static const char * toHex(u32 i)
|
|
|
|
{
|
|
|
|
sprintf(temp, "0x%06X", 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);
|
|
|
|
}
|
|
|
|
|
2009-05-27 19:31:18 +02:00
|
|
|
static const char * XMLSavePalCallback(mxml_node_t *node, int where)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = node->value.element.name;
|
|
|
|
|
|
|
|
if(where == MXML_WS_BEFORE_CLOSE)
|
|
|
|
{
|
|
|
|
if(!strcmp(name, "palette") || !strcmp(name, "game"))
|
|
|
|
return ("\n");
|
|
|
|
else if(!strcmp(name, "bkgr") || !strcmp(name, "wind") || !strcmp(name, "obj0") || !strcmp(name, "obj1"))
|
|
|
|
return ("\n\t");
|
|
|
|
}
|
|
|
|
if (where == MXML_WS_BEFORE_OPEN)
|
|
|
|
{
|
|
|
|
if(!strcmp(name, "palette"))
|
|
|
|
return ("\n");
|
|
|
|
else if(!strcmp(name, "game"))
|
|
|
|
return ("\n\n");
|
|
|
|
else if(!strcmp(name, "bkgr") || !strcmp(name, "wind") || !strcmp(name, "obj0") || !strcmp(name, "obj1"))
|
|
|
|
return ("\n\t");
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:10:12 +01:00
|
|
|
static int
|
2009-10-02 00:42:02 +02:00
|
|
|
preparePrefsData ()
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
|
|
|
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);
|
2016-12-10 21:47:27 +01:00
|
|
|
createXMLSetting("ScreenshotsFolder", "Screenshots Folder", GCSettings.ScreenshotsFolder);
|
|
|
|
createXMLSetting("CoverFolder", "Covers Folder", GCSettings.CoverFolder);
|
|
|
|
createXMLSetting("ArtworkFolder", "Artworks Folder", GCSettings.ArtworkFolder);
|
|
|
|
createXMLSetting("ImageFolder", "Image Folder", GCSettings.ImageFolder);
|
|
|
|
|
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
|
|
|
|
2009-04-27 09:49:46 +02:00
|
|
|
createXMLSetting("videomode", "Video Mode", toStr(GCSettings.videomode));
|
2009-11-16 10:02:17 +01:00
|
|
|
createXMLSetting("gbaZoomHor", "GBA Horizontal Zoom Level", FtoStr(GCSettings.gbaZoomHor));
|
|
|
|
createXMLSetting("gbaZoomVert", "GBA Vertical Zoom Level", FtoStr(GCSettings.gbaZoomVert));
|
|
|
|
createXMLSetting("gbZoomHor", "GB Horizontal Zoom Level", FtoStr(GCSettings.gbZoomHor));
|
|
|
|
createXMLSetting("gbZoomVert", "GB Vertical Zoom Level", FtoStr(GCSettings.gbZoomVert));
|
2008-10-24 08:16:15 +02:00
|
|
|
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));
|
2009-05-30 08:27:47 +02:00
|
|
|
createXMLSetting("Rumble", "Rumble", toStr(GCSettings.Rumble));
|
2010-01-25 22:06:27 +01:00
|
|
|
createXMLSetting("language", "Language", toStr(GCSettings.language));
|
2016-12-10 21:47:27 +01:00
|
|
|
createXMLSetting("PreviewImage", "Preview Image", toStr(GCSettings.PreviewImage));
|
|
|
|
|
|
|
|
createXMLSection("Emulation", "Emulation Settings");
|
2009-04-08 09:08:12 +02:00
|
|
|
|
2016-12-10 21:47:27 +01:00
|
|
|
createXMLSetting("BasicPalette", "Basic Color Palette for GB", toStr(GCSettings.BasicPalette));
|
|
|
|
|
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");
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSaveCallback);
|
|
|
|
|
|
|
|
mxmlDelete(xml);
|
|
|
|
|
|
|
|
return datasize;
|
|
|
|
}
|
|
|
|
|
2009-05-27 19:31:18 +02:00
|
|
|
static void createXMLPalette(gamePalette *p, bool overwrite, const char *newname = NULL)
|
|
|
|
{
|
2009-10-02 00:42:02 +02:00
|
|
|
if (!newname)
|
|
|
|
newname = p->gameName;
|
2009-05-27 19:31:18 +02:00
|
|
|
section = mxmlFindElement(xml, xml, "game", "name", newname, MXML_DESCEND);
|
2009-10-02 00:42:02 +02:00
|
|
|
if (section && !overwrite)
|
|
|
|
{
|
2009-05-27 19:31:18 +02:00
|
|
|
return;
|
2009-10-02 00:42:02 +02:00
|
|
|
}
|
|
|
|
else if (!section)
|
|
|
|
{
|
2009-05-27 19:31:18 +02:00
|
|
|
section = mxmlNewElement(data, "game");
|
|
|
|
}
|
|
|
|
mxmlElementSetAttr(section, "name", newname);
|
|
|
|
mxmlElementSetAttr(section, "use", "1");
|
|
|
|
item = mxmlFindNewElement(section, "bkgr");
|
|
|
|
mxmlElementSetAttr(item, "c0", toHex(p->palette[0]));
|
|
|
|
mxmlElementSetAttr(item, "c1", toHex(p->palette[1]));
|
|
|
|
mxmlElementSetAttr(item, "c2", toHex(p->palette[2]));
|
|
|
|
mxmlElementSetAttr(item, "c3", toHex(p->palette[3]));
|
|
|
|
item = mxmlFindNewElement(section, "wind");
|
|
|
|
mxmlElementSetAttr(item, "c0", toHex(p->palette[4]));
|
|
|
|
mxmlElementSetAttr(item, "c1", toHex(p->palette[5]));
|
|
|
|
mxmlElementSetAttr(item, "c2", toHex(p->palette[6]));
|
|
|
|
mxmlElementSetAttr(item, "c3", toHex(p->palette[7]));
|
|
|
|
item = mxmlFindNewElement(section, "obj0");
|
|
|
|
mxmlElementSetAttr(item, "c0", toHex(p->palette[8]));
|
|
|
|
mxmlElementSetAttr(item, "c1", toHex(p->palette[9]));
|
|
|
|
mxmlElementSetAttr(item, "c2", toHex(p->palette[10]));
|
|
|
|
item = mxmlFindNewElement(section, "obj1");
|
|
|
|
mxmlElementSetAttr(item, "c0", toHex(p->palette[11]));
|
|
|
|
mxmlElementSetAttr(item, "c1", toHex(p->palette[12]));
|
|
|
|
mxmlElementSetAttr(item, "c2", toHex(p->palette[13]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-10-02 00:42:02 +02:00
|
|
|
preparePalData (gamePalette pals[], int palCount)
|
2009-05-27 19:31:18 +02:00
|
|
|
{
|
|
|
|
xml = mxmlNewXML("1.0");
|
|
|
|
mxmlSetWrapMargin(0); // disable line wrapping
|
|
|
|
|
|
|
|
data = mxmlNewElement(xml, "palette");
|
|
|
|
mxmlElementSetAttr(data, "app", APPNAME);
|
|
|
|
mxmlElementSetAttr(data, "version", APPVERSION);
|
2009-10-02 00:42:02 +02:00
|
|
|
for (int i=0; i<palCount; i++)
|
2009-05-29 22:04:11 +02:00
|
|
|
createXMLPalette(&pals[i], false);
|
2009-05-27 19:31:18 +02:00
|
|
|
|
|
|
|
int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSavePalCallback);
|
|
|
|
|
|
|
|
mxmlDelete(xml);
|
|
|
|
|
|
|
|
return datasize;
|
|
|
|
}
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-29 22:04:11 +02:00
|
|
|
static void loadXMLPaletteFromSection(gamePalette &pal)
|
|
|
|
{
|
2009-10-02 00:42:02 +02:00
|
|
|
if (section)
|
|
|
|
{
|
2009-05-29 22:04:11 +02:00
|
|
|
strncpy(pal.gameName, mxmlElementGetAttr(section, "name"), 17);
|
|
|
|
item = mxmlFindElement(section, xml, "bkgr", NULL, NULL, MXML_DESCEND);
|
2009-10-02 00:42:02 +02:00
|
|
|
if (item)
|
|
|
|
{
|
2009-05-29 22:04:11 +02:00
|
|
|
const char * tmp = mxmlElementGetAttr(item, "c0");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[0] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c1");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[1] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c2");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[2] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c3");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[3] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
}
|
|
|
|
item = mxmlFindElement(section, xml, "wind", NULL, NULL, MXML_DESCEND);
|
2009-10-02 00:42:02 +02:00
|
|
|
if (item)
|
|
|
|
{
|
2009-05-29 22:04:11 +02:00
|
|
|
const char * tmp = mxmlElementGetAttr(item, "c0");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[4] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c1");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[5] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c2");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[6] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c3");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[7] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
}
|
|
|
|
item = mxmlFindElement(section, xml, "obj0", NULL, NULL, MXML_DESCEND);
|
2009-10-02 00:42:02 +02:00
|
|
|
if (item)
|
|
|
|
{
|
2009-05-29 22:04:11 +02:00
|
|
|
const char * tmp = mxmlElementGetAttr(item, "c0");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[8] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c1");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[9] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c2");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[10] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
}
|
|
|
|
item = mxmlFindElement(section, xml, "obj1", NULL, NULL, MXML_DESCEND);
|
2009-10-02 00:42:02 +02:00
|
|
|
if (item)
|
|
|
|
{
|
2009-05-29 22:04:11 +02:00
|
|
|
const char * tmp = mxmlElementGetAttr(item, "c0");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[11] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c1");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[12] = strtoul(tmp, NULL, 16);
|
2009-05-29 22:04:11 +02:00
|
|
|
tmp = mxmlElementGetAttr(item, "c2");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (tmp)
|
|
|
|
pal.palette[13] = strtoul(tmp, NULL, 16);
|
2009-05-30 08:27:47 +02:00
|
|
|
}
|
2009-05-29 22:04:11 +02:00
|
|
|
const char *use = mxmlElementGetAttr(section, "use");
|
2009-10-02 00:42:02 +02:00
|
|
|
if (use)
|
|
|
|
{
|
|
|
|
if (atoi(use) == 0)
|
|
|
|
pal.use = 0;
|
|
|
|
else
|
|
|
|
pal.use = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-29 22:04:11 +02:00
|
|
|
pal.use = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2009-10-02 00:42:02 +02:00
|
|
|
decodePrefsData ()
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
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-04-27 09:16:13 +02:00
|
|
|
else if(verMajor < 2) // less than version 2.0.0
|
2009-03-04 08:01:04 +01:00
|
|
|
result = false; // reset settings (sorry, should update settings instead)
|
2009-01-06 06:33:13 +01:00
|
|
|
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));
|
2016-12-10 21:47:27 +01:00
|
|
|
loadXMLSetting(GCSettings.ScreenshotsFolder, "ScreenshotsFolder", sizeof(GCSettings.ScreenshotsFolder));
|
|
|
|
loadXMLSetting(GCSettings.CoverFolder, "CoverFolder", sizeof(GCSettings.CoverFolder));
|
|
|
|
loadXMLSetting(GCSettings.ArtworkFolder, "ArtworkFolder", sizeof(GCSettings.ArtworkFolder));
|
|
|
|
loadXMLSetting(GCSettings.ImageFolder, "ImageFolder", sizeof(GCSettings.ImageFolder));
|
|
|
|
|
2009-01-06 06:33:13 +01:00
|
|
|
// 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
|
|
|
|
2009-04-27 09:49:46 +02:00
|
|
|
loadXMLSetting(&GCSettings.videomode, "videomode");
|
2009-11-16 10:02:17 +01:00
|
|
|
loadXMLSetting(&GCSettings.gbaZoomHor, "gbaZoomHor");
|
|
|
|
loadXMLSetting(&GCSettings.gbaZoomVert, "gbaZoomVert");
|
2010-01-06 19:22:12 +01:00
|
|
|
loadXMLSetting(&GCSettings.gbZoomHor, "gbZoomHor");
|
|
|
|
loadXMLSetting(&GCSettings.gbZoomVert, "gbZoomVert");
|
2009-01-06 06:33:13 +01:00
|
|
|
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-05-30 08:27:47 +02:00
|
|
|
loadXMLSetting(&GCSettings.Rumble, "Rumble");
|
2010-01-25 22:06:27 +01:00
|
|
|
loadXMLSetting(&GCSettings.language, "language");
|
2016-12-10 21:47:27 +01:00
|
|
|
loadXMLSetting(&GCSettings.PreviewImage, "PreviewImage");
|
2009-04-08 09:08:12 +02:00
|
|
|
|
2016-12-10 21:47:27 +01:00
|
|
|
// Emulation Settings
|
|
|
|
|
|
|
|
loadXMLSetting(&GCSettings.BasicPalette, "BasicPalette");
|
|
|
|
|
|
|
|
|
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");
|
2009-01-06 06:33:13 +01:00
|
|
|
}
|
|
|
|
mxmlDelete(xml);
|
|
|
|
}
|
|
|
|
return result;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-29 22:04:11 +02:00
|
|
|
static bool
|
2009-10-02 00:42:02 +02:00
|
|
|
decodePalsData ()
|
2009-05-29 22:04:11 +02:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
xml = mxmlLoadString(NULL, (char *) savebuffer, MXML_TEXT_CALLBACK);
|
2009-05-29 22:04:11 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
if (xml)
|
2009-05-29 22:04:11 +02:00
|
|
|
{
|
2009-06-01 09:20:23 +02:00
|
|
|
// count number of palettes in file
|
|
|
|
loadedPalettes = 0;
|
|
|
|
item = mxmlFindElement(xml, xml, "palette", NULL, NULL, MXML_DESCEND);
|
|
|
|
for (section = mxmlFindElement(item, xml, "game", NULL, NULL,
|
|
|
|
MXML_DESCEND); section; section = mxmlFindElement(section, xml,
|
|
|
|
"game", NULL, NULL, MXML_NO_DESCEND))
|
2009-05-29 22:04:11 +02:00
|
|
|
{
|
2009-06-01 09:20:23 +02:00
|
|
|
loadedPalettes++;
|
2009-05-29 22:04:11 +02:00
|
|
|
}
|
2009-06-01 09:20:23 +02:00
|
|
|
// Allocate enough memory for all palettes in file, plus all hardcoded palettes,
|
|
|
|
// plus one new palette
|
|
|
|
if (palettes)
|
|
|
|
free(palettes);
|
|
|
|
|
|
|
|
palettes = (gamePalette *)malloc(sizeof(gamePalette)*loadedPalettes);
|
|
|
|
// Load all palettes in file, hardcoded palettes are added later
|
|
|
|
int i = 0;
|
|
|
|
for (section = mxmlFindElement(item, xml, "game", NULL, NULL,
|
|
|
|
MXML_DESCEND); section; section = mxmlFindElement(section, xml,
|
|
|
|
"game", NULL, NULL, MXML_NO_DESCEND))
|
2009-05-29 22:04:11 +02:00
|
|
|
{
|
2009-06-01 09:20:23 +02:00
|
|
|
loadXMLPaletteFromSection(palettes[i]);
|
|
|
|
i++;
|
2009-05-27 19:31:18 +02:00
|
|
|
}
|
|
|
|
mxmlDelete(xml);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-25 22:06:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* FixInvalidSettings
|
|
|
|
*
|
|
|
|
* Attempts to correct at least some invalid settings - the ones that
|
|
|
|
* might cause crashes
|
|
|
|
***************************************************************************/
|
|
|
|
void FixInvalidSettings()
|
|
|
|
{
|
2010-06-04 23:50:44 +02:00
|
|
|
if(GCSettings.LoadMethod > 6)
|
2010-01-25 22:06:27 +01:00
|
|
|
GCSettings.LoadMethod = DEVICE_AUTO;
|
2010-06-04 23:50:44 +02:00
|
|
|
if(GCSettings.SaveMethod > 6)
|
2010-01-25 22:06:27 +01:00
|
|
|
GCSettings.SaveMethod = DEVICE_AUTO;
|
|
|
|
if(!(GCSettings.gbaZoomHor > 0.5 && GCSettings.gbaZoomHor < 1.5))
|
|
|
|
GCSettings.gbaZoomHor = 1.0;
|
|
|
|
if(!(GCSettings.gbaZoomVert > 0.5 && GCSettings.gbaZoomVert < 1.5))
|
|
|
|
GCSettings.gbaZoomVert = 1.0;
|
|
|
|
if(!(GCSettings.gbZoomHor > 0.5 && GCSettings.gbZoomHor < 1.5))
|
|
|
|
GCSettings.gbZoomHor = 1.0;
|
|
|
|
if(!(GCSettings.gbZoomVert > 0.5 && GCSettings.gbZoomVert < 1.5))
|
|
|
|
GCSettings.gbZoomVert = 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))
|
|
|
|
GCSettings.MusicVolume = 40;
|
|
|
|
if(!(GCSettings.SFXVolume >= 0 && GCSettings.SFXVolume <= 100))
|
|
|
|
GCSettings.SFXVolume = 40;
|
2010-08-29 23:43:05 +02:00
|
|
|
if(GCSettings.language < 0 || GCSettings.language >= LANG_LENGTH)
|
2010-01-25 22:06:27 +01:00
|
|
|
GCSettings.language = LANG_ENGLISH;
|
|
|
|
if(!(GCSettings.render >= 0 && GCSettings.render < 3))
|
|
|
|
GCSettings.render = 1;
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2016-12-10 21:47:27 +01:00
|
|
|
sprintf (GCSettings.ScreenshotsFolder, "%s/screenshots", APPFOLDER); // Path to screenshot files
|
|
|
|
sprintf (GCSettings.CoverFolder, "%s/covers", APPFOLDER); // Path to cover files
|
|
|
|
sprintf (GCSettings.ArtworkFolder, "%s/artworks", APPFOLDER); // Path to artwork files
|
|
|
|
sprintf (GCSettings.ImageFolder, "%s/screenshots", APPFOLDER);
|
|
|
|
|
2010-01-25 22:06:27 +01:00
|
|
|
GCSettings.AutoLoad = 1;
|
|
|
|
GCSettings.AutoSave = 1;
|
|
|
|
|
|
|
|
GCSettings.WiimoteOrientation = 0;
|
|
|
|
|
|
|
|
GCSettings.gbaZoomHor = 1.0; // GBA horizontal zoom level
|
|
|
|
GCSettings.gbaZoomVert = 1.0; // GBA vertical zoom level
|
|
|
|
GCSettings.gbZoomHor = 1.0; // GBA horizontal zoom level
|
|
|
|
GCSettings.gbZoomVert = 1.0; // GBA vertical zoom level
|
|
|
|
GCSettings.videomode = 0; // automatic video mode detection
|
|
|
|
GCSettings.render = 1; // Filtered
|
|
|
|
GCSettings.scaling = 1; // partial stretch
|
|
|
|
GCSettings.WiiControls = false; // Match Wii Game
|
|
|
|
|
|
|
|
GCSettings.xshift = 0; // horizontal video shift
|
|
|
|
GCSettings.yshift = 0; // vertical video shift
|
|
|
|
GCSettings.colorize = 0; // Colorize mono gameboy games
|
|
|
|
|
|
|
|
GCSettings.WiimoteOrientation = 0;
|
|
|
|
GCSettings.ExitAction = 0;
|
|
|
|
GCSettings.MusicVolume = 40;
|
|
|
|
GCSettings.SFXVolume = 40;
|
|
|
|
GCSettings.Rumble = 1;
|
2016-12-10 21:47:27 +01:00
|
|
|
GCSettings.PreviewImage = 0;
|
|
|
|
|
|
|
|
GCSettings.BasicPalette = 0;
|
|
|
|
|
2010-01-25 22:33:33 +01:00
|
|
|
#ifdef HW_RVL
|
2010-01-25 22:06:27 +01:00
|
|
|
GCSettings.language = CONF_GetLanguage();
|
2010-03-16 00:30:21 +01:00
|
|
|
|
|
|
|
if(GCSettings.language == LANG_JAPANESE ||
|
|
|
|
GCSettings.language == LANG_SIMP_CHINESE ||
|
|
|
|
GCSettings.language == LANG_TRAD_CHINESE ||
|
|
|
|
GCSettings.language == LANG_KOREAN)
|
|
|
|
GCSettings.language = LANG_ENGLISH;
|
2010-01-25 22:33:33 +01:00
|
|
|
#else
|
|
|
|
GCSettings.language = LANG_ENGLISH;
|
|
|
|
#endif
|
2010-01-25 22:06:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Save Preferences
|
|
|
|
***************************************************************************/
|
2009-10-02 00:42:02 +02:00
|
|
|
static char prefpath[MAXPATHLEN] = { 0 };
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
bool
|
2008-12-19 00:21:51 +01:00
|
|
|
SavePrefs (bool silent)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2009-10-02 00:42:02 +02:00
|
|
|
char filepath[MAXPATHLEN];
|
2008-09-16 07:42:21 +02:00
|
|
|
int datasize;
|
|
|
|
int offset = 0;
|
2009-10-02 00:42:02 +02:00
|
|
|
int device = 0;
|
|
|
|
|
|
|
|
if(prefpath[0] != 0)
|
|
|
|
{
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath, "%s/%s", prefpath, PREF_FILE_NAME);
|
2009-10-02 00:42:02 +02:00
|
|
|
FindDevice(filepath, &device);
|
|
|
|
}
|
|
|
|
else if(appPath[0] != 0)
|
|
|
|
{
|
2009-10-05 03:30:19 +02:00
|
|
|
sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME);
|
2009-12-23 01:39:48 +01:00
|
|
|
strcpy(prefpath, appPath);
|
2009-10-02 00:42:02 +02:00
|
|
|
FindDevice(filepath, &device);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-06 09:17:52 +02:00
|
|
|
device = autoSaveMethod(silent);
|
2009-10-02 00:42:02 +02:00
|
|
|
|
|
|
|
if(device == 0)
|
|
|
|
return false;
|
|
|
|
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER);
|
|
|
|
|
2011-01-20 03:53:27 +01:00
|
|
|
DIR *dir = opendir(filepath);
|
2010-08-14 07:57:22 +02:00
|
|
|
if (!dir)
|
2009-12-23 01:39:48 +01:00
|
|
|
{
|
2010-08-14 07:57:22 +02:00
|
|
|
if(mkdir(filepath, 0777) != 0)
|
|
|
|
return false;
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath, "%s%s/roms", pathPrefix[device], APPFOLDER);
|
2010-08-14 07:57:22 +02:00
|
|
|
if(mkdir(filepath, 0777) != 0)
|
|
|
|
return false;
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath, "%s%s/saves", pathPrefix[device], APPFOLDER);
|
2010-08-14 07:57:22 +02:00
|
|
|
if(mkdir(filepath, 0777) != 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-20 03:53:27 +01:00
|
|
|
closedir(dir);
|
2009-12-23 01:39:48 +01:00
|
|
|
}
|
2009-11-29 09:20:40 +01:00
|
|
|
sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME);
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER);
|
2009-10-02 00:42:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(device == 0)
|
2008-11-12 08:53:25 +01:00
|
|
|
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 ();
|
2009-10-02 00:42:02 +02:00
|
|
|
datasize = preparePrefsData ();
|
2008-11-12 08:53:25 +01:00
|
|
|
|
2009-10-02 00:42:02 +02:00
|
|
|
offset = SaveFile(filepath, datasize, 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;
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
/****************************************************************************
|
2009-10-02 00:42:02 +02:00
|
|
|
* Load Preferences from specified filepath
|
2009-06-01 09:20:23 +02:00
|
|
|
***************************************************************************/
|
|
|
|
bool
|
2009-12-23 01:39:48 +01:00
|
|
|
LoadPrefsFromMethod (char * path)
|
2009-05-27 19:31:18 +02:00
|
|
|
{
|
2009-06-01 09:20:23 +02:00
|
|
|
bool retval = false;
|
2009-05-27 19:31:18 +02:00
|
|
|
int offset = 0;
|
2009-12-23 01:39:48 +01:00
|
|
|
char filepath[MAXPATHLEN];
|
|
|
|
sprintf(filepath, "%s/%s", path, PREF_FILE_NAME);
|
2009-05-27 19:31:18 +02:00
|
|
|
|
|
|
|
AllocSaveBuffer ();
|
|
|
|
|
2009-10-02 00:42:02 +02:00
|
|
|
offset = LoadFile(filepath, SILENT);
|
2009-05-27 19:31:18 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
if (offset > 0)
|
2009-10-02 00:42:02 +02:00
|
|
|
retval = decodePrefsData ();
|
2009-05-27 19:31:18 +02:00
|
|
|
|
|
|
|
FreeSaveBuffer ();
|
2009-12-23 08:22:19 +01:00
|
|
|
|
2009-10-02 00:42:02 +02:00
|
|
|
if(retval)
|
2009-12-23 08:22:19 +01:00
|
|
|
{
|
|
|
|
strcpy(prefpath, path);
|
|
|
|
|
|
|
|
if(appPath[0] == 0)
|
|
|
|
strcpy(appPath, prefpath);
|
|
|
|
}
|
2009-05-27 19:31:18 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
return retval;
|
|
|
|
}
|
2009-05-27 19:31:18 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Load Preferences
|
|
|
|
* Checks sources consecutively until we find a preference file
|
|
|
|
***************************************************************************/
|
|
|
|
static bool prefLoaded = false;
|
|
|
|
|
|
|
|
bool LoadPrefs()
|
|
|
|
{
|
|
|
|
if(prefLoaded) // already attempted loading
|
2009-05-27 19:31:18 +02:00
|
|
|
return true;
|
2009-06-01 09:20:23 +02:00
|
|
|
|
|
|
|
bool prefFound = false;
|
2009-10-02 00:42:02 +02:00
|
|
|
char filepath[4][MAXPATHLEN];
|
|
|
|
int numDevices;
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
2009-12-23 08:22:19 +01:00
|
|
|
numDevices = 5;
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath[0], "%s", appPath);
|
2009-12-23 08:22:19 +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:42:02 +02:00
|
|
|
#else
|
2009-11-29 09:20:40 +01:00
|
|
|
numDevices = 2;
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath[0], "carda:/%s", APPFOLDER);
|
|
|
|
sprintf(filepath[1], "cardb:/%s", APPFOLDER);
|
2009-10-02 00:42:02 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for(int i=0; i<numDevices; i++)
|
2009-06-16 07:01:12 +02:00
|
|
|
{
|
2009-10-02 00:42:02 +02:00
|
|
|
prefFound = LoadPrefsFromMethod(filepath[i]);
|
|
|
|
|
|
|
|
if(prefFound)
|
|
|
|
break;
|
2009-06-16 07:01:12 +02:00
|
|
|
}
|
2009-06-01 09:20:23 +02:00
|
|
|
|
|
|
|
prefLoaded = true; // attempted to load preferences
|
|
|
|
|
|
|
|
if(prefFound)
|
|
|
|
FixInvalidSettings();
|
|
|
|
|
2010-01-29 01:58:31 +01:00
|
|
|
ResetText();
|
2009-06-01 09:20:23 +02:00
|
|
|
return prefFound;
|
2009-05-27 19:31:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
bool SavePalettes(bool silent)
|
|
|
|
{
|
2009-05-27 19:31:18 +02:00
|
|
|
char filepath[1024];
|
2009-05-29 22:04:11 +02:00
|
|
|
int datasize;
|
2009-05-27 19:31:18 +02:00
|
|
|
int offset = 0;
|
|
|
|
|
2009-12-23 01:39:48 +01:00
|
|
|
if(prefpath[0] == 0)
|
2009-05-27 19:31:18 +02:00
|
|
|
return false;
|
|
|
|
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath, "%s/%s", prefpath, PAL_FILE_NAME);
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
// Now create the XML palette file
|
|
|
|
|
2009-05-29 22:04:11 +02:00
|
|
|
if (!silent)
|
|
|
|
ShowAction("Saving palette...");
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
AllocSaveBuffer();
|
2009-10-02 00:42:02 +02:00
|
|
|
datasize = preparePalData(palettes, loadedPalettes);
|
2009-05-29 22:04:11 +02:00
|
|
|
|
2009-10-02 00:42:02 +02:00
|
|
|
offset = SaveFile(filepath, datasize, silent);
|
2009-05-27 19:31:18 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
FreeSaveBuffer();
|
2009-05-27 19:31:18 +02:00
|
|
|
|
|
|
|
CancelAction();
|
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
|
|
|
if (!silent)
|
|
|
|
InfoPrompt("Palette saved");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-01 14:36:56 +02:00
|
|
|
static void AddPalette(gamePalette pal, const char *gameName, bool overwrite)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2009-06-01 09:20:23 +02:00
|
|
|
for (int i=0; i < loadedPalettes; i++)
|
2009-10-02 00:42:02 +02:00
|
|
|
if (strcmp(palettes[i].gameName, gameName)==0)
|
|
|
|
{
|
|
|
|
if (overwrite)
|
|
|
|
{
|
2009-06-01 14:36:56 +02:00
|
|
|
palettes[i] = pal;
|
|
|
|
strncpy(palettes[i].gameName, gameName, 17);
|
|
|
|
return;
|
2009-10-02 00:42:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-01 14:36:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-09-29 09:35:26 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
palettes = (gamePalette *)realloc(palettes, sizeof(gamePalette)*(loadedPalettes+1));
|
|
|
|
palettes[loadedPalettes] = pal;
|
|
|
|
strncpy(palettes[loadedPalettes].gameName, gameName, 17);
|
|
|
|
loadedPalettes++;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 14:36:56 +02:00
|
|
|
bool SavePaletteAs(bool silent, const char *name)
|
|
|
|
{
|
|
|
|
AddPalette(CurrentPalette, name, true);
|
|
|
|
return SavePalettes(silent);
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Load Palettes
|
|
|
|
***************************************************************************/
|
|
|
|
bool LoadPalettes()
|
2009-05-27 19:31:18 +02:00
|
|
|
{
|
|
|
|
bool retval = false;
|
|
|
|
int offset = 0;
|
2009-12-23 01:39:48 +01:00
|
|
|
char filepath[MAXPATHLEN];
|
|
|
|
|
2009-05-29 22:04:11 +02:00
|
|
|
AllocSaveBuffer ();
|
2009-10-02 00:42:02 +02:00
|
|
|
|
2009-12-23 01:39:48 +01:00
|
|
|
sprintf(filepath, "%s/%s", prefpath, PAL_FILE_NAME);
|
|
|
|
offset = LoadFile(filepath, SILENT);
|
2009-05-29 22:04:11 +02:00
|
|
|
|
|
|
|
if (offset > 0)
|
2009-10-02 00:42:02 +02:00
|
|
|
retval = decodePalsData ();
|
2009-05-29 22:04:11 +02:00
|
|
|
|
|
|
|
FreeSaveBuffer ();
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
// add hard-coded palettes
|
|
|
|
for (int i=0; i<gamePalettesCount; i++)
|
2009-06-01 14:36:56 +02:00
|
|
|
AddPalette(gamePalettes[i], gamePalettes[i].gameName, false);
|
2009-05-27 19:31:18 +02:00
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
if (!retval)
|
|
|
|
retval = SavePalettes(SILENT);
|
2009-05-27 19:31:18 +02:00
|
|
|
|
2009-10-02 00:42:02 +02:00
|
|
|
return retval;
|
2009-05-27 19:31:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 09:20:23 +02:00
|
|
|
void SetPalette(const char *gameName)
|
2009-05-27 19:31:18 +02:00
|
|
|
{
|
2009-06-01 09:20:23 +02:00
|
|
|
// Load existing palette
|
|
|
|
int snum = -1;
|
|
|
|
for (int i = 0; i < loadedPalettes; i++)
|
|
|
|
{
|
|
|
|
if(strcmp(gameName, palettes[i].gameName)==0)
|
|
|
|
{
|
|
|
|
snum = i;
|
|
|
|
break;
|
2009-05-29 22:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
2009-06-01 09:20:23 +02:00
|
|
|
// match found!
|
|
|
|
if(snum >= 0)
|
|
|
|
{
|
2009-06-01 14:36:56 +02:00
|
|
|
CurrentPalette = palettes[snum];
|
2009-05-29 22:04:11 +02:00
|
|
|
}
|
2009-06-01 09:20:23 +02:00
|
|
|
else
|
2009-06-01 14:36:56 +02:00
|
|
|
// no match, use the default palette
|
2009-06-01 09:20:23 +02:00
|
|
|
{
|
2009-06-01 14:36:56 +02:00
|
|
|
for (int i = 0; i < loadedPalettes; i++)
|
|
|
|
{
|
|
|
|
if(strcmp(gameName, "default")==0)
|
|
|
|
{
|
|
|
|
snum = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(snum >= 0)
|
|
|
|
{
|
|
|
|
CurrentPalette = palettes[snum];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentPalette = palettes[0];
|
|
|
|
}
|
|
|
|
// DON'T add this game to the palette list
|
2009-05-27 19:31:18 +02:00
|
|
|
}
|
|
|
|
}
|