[Settings] Sync code
This commit is contained in:
parent
e8d5e8be9c
commit
d8e8523983
|
@ -1,54 +1,67 @@
|
|||
#include <Settings/Settings.h>
|
||||
#include <Common/Platform.h>
|
||||
#include <Common/stdtypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Common/stdtypes.h>
|
||||
#include <Common/Platform.h>
|
||||
#include "Settings.h"
|
||||
#if defined(_WIN32)
|
||||
#define EXPORT extern "C" __declspec(dllexport)
|
||||
#define CALL __cdecl
|
||||
#else
|
||||
#define EXPORT extern "C" __attribute__((visibility("default")))
|
||||
#define CALL
|
||||
#endif
|
||||
|
||||
enum SettingLocation {
|
||||
SettingType_ConstString = 0,
|
||||
SettingType_ConstValue = 1,
|
||||
SettingType_CfgFile = 2,
|
||||
SettingType_Registry = 3,
|
||||
SettingType_RelativePath = 4,
|
||||
TemporarySetting = 5,
|
||||
SettingType_RomDatabase = 6,
|
||||
SettingType_CheatSetting = 7,
|
||||
SettingType_GameSetting = 8,
|
||||
SettingType_BoolVariable = 9,
|
||||
SettingType_NumberVariable = 10,
|
||||
SettingType_StringVariable = 11,
|
||||
SettingType_SelectedDirectory = 12,
|
||||
SettingType_RdbSetting = 13,
|
||||
enum SettingLocation
|
||||
{
|
||||
SettingType_ConstString = 0,
|
||||
SettingType_ConstValue = 1,
|
||||
SettingType_CfgFile = 2,
|
||||
SettingType_Registry = 3,
|
||||
SettingType_RelativePath = 4,
|
||||
TemporarySetting = 5,
|
||||
SettingType_RomDatabase = 6,
|
||||
SettingType_CheatSetting = 7,
|
||||
SettingType_GameSetting = 8,
|
||||
SettingType_BoolVariable = 9,
|
||||
SettingType_NumberVariable = 10,
|
||||
SettingType_StringVariable = 11,
|
||||
SettingType_SelectedDirectory = 12,
|
||||
SettingType_RdbSetting = 13,
|
||||
};
|
||||
|
||||
enum SettingDataType {
|
||||
Data_DWORD = 0, Data_String = 1, Data_CPUTYPE = 2, Data_SelfMod = 3, Data_OnOff = 4, Data_YesNo = 5, Data_SaveChip = 6
|
||||
enum SettingDataType
|
||||
{
|
||||
Data_DWORD = 0, Data_String = 1, Data_CPUTYPE = 2, Data_SelfMod = 3, Data_OnOff = 4, Data_YesNo = 5, Data_SaveChip = 6
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint32_t dwSize;
|
||||
int DefaultStartRange;
|
||||
int SettingStartRange;
|
||||
int MaximumSettings;
|
||||
int NoDefault;
|
||||
int DefaultLocation;
|
||||
void * handle;
|
||||
unsigned int (*GetSetting) ( void * handle, int ID );
|
||||
const char * (*GetSettingSz) ( void * handle, int ID, char * Buffer, int BufferLen );
|
||||
void (*SetSetting) ( void * handle, int ID, unsigned int Value );
|
||||
void (*SetSettingSz) ( void * handle, int ID, const char * Value );
|
||||
void (*RegisterSetting) (void * handle, int ID, int DefaultID, SettingDataType Type,
|
||||
int DefaultStartRange;
|
||||
int SettingStartRange;
|
||||
int MaximumSettings;
|
||||
int NoDefault;
|
||||
int DefaultLocation;
|
||||
void * handle;
|
||||
|
||||
unsigned int(*GetSetting) (void * handle, int ID);
|
||||
const char * (*GetSettingSz) (void * handle, int ID, char * Buffer, int BufferLen);
|
||||
void(*SetSetting) (void * handle, int ID, unsigned int Value);
|
||||
void(*SetSettingSz) (void * handle, int ID, const char * Value);
|
||||
void(*RegisterSetting) (void * handle, int ID, int DefaultID, SettingDataType Type,
|
||||
SettingLocation Location, const char * Category, const char * DefaultStr, uint32_t Value);
|
||||
void (*UseUnregisteredSetting) (int ID);
|
||||
void(*UseUnregisteredSetting) (int ID);
|
||||
} PLUGIN_SETTINGS;
|
||||
|
||||
typedef struct {
|
||||
unsigned int (*FindSystemSettingId) ( void * handle, const char * Name );
|
||||
typedef struct
|
||||
{
|
||||
unsigned int(*FindSystemSettingId) (void * handle, const char * Name);
|
||||
} PLUGIN_SETTINGS2;
|
||||
|
||||
typedef struct {
|
||||
void (*FlushSettings) ( void * handle );
|
||||
typedef struct
|
||||
{
|
||||
void(*FlushSettings) (void * handle);
|
||||
} PLUGIN_SETTINGS3;
|
||||
|
||||
static PLUGIN_SETTINGS g_PluginSettings;
|
||||
|
@ -57,159 +70,157 @@ static PLUGIN_SETTINGS3 g_PluginSettings3;
|
|||
static bool g_PluginInitilized = false;
|
||||
static char g_PluginSettingName[300];
|
||||
|
||||
extern "C" {
|
||||
EXPORT void SetSettingInfo (PLUGIN_SETTINGS * info);
|
||||
EXPORT void SetSettingInfo2 (PLUGIN_SETTINGS2 * info);
|
||||
EXPORT void SetSettingInfo3 (PLUGIN_SETTINGS3 * info);
|
||||
}
|
||||
EXPORT void SetSettingInfo(PLUGIN_SETTINGS * info);
|
||||
EXPORT void SetSettingInfo2(PLUGIN_SETTINGS2 * info);
|
||||
EXPORT void SetSettingInfo3(PLUGIN_SETTINGS3 * info);
|
||||
|
||||
EXPORT void SetSettingInfo (PLUGIN_SETTINGS * info)
|
||||
EXPORT void SetSettingInfo(PLUGIN_SETTINGS * info)
|
||||
{
|
||||
g_PluginSettings = *info;
|
||||
g_PluginInitilized = true;
|
||||
info->UseUnregisteredSetting = UseUnregisteredSetting;
|
||||
g_PluginSettings = *info;
|
||||
g_PluginInitilized = true;
|
||||
info->UseUnregisteredSetting = UseUnregisteredSetting;
|
||||
}
|
||||
|
||||
EXPORT void SetSettingInfo2 (PLUGIN_SETTINGS2 * info)
|
||||
EXPORT void SetSettingInfo2(PLUGIN_SETTINGS2 * info)
|
||||
{
|
||||
g_PluginSettings2 = *info;
|
||||
g_PluginSettings2 = *info;
|
||||
}
|
||||
|
||||
EXPORT void SetSettingInfo3 (PLUGIN_SETTINGS3 * info)
|
||||
EXPORT void SetSettingInfo3(PLUGIN_SETTINGS3 * info)
|
||||
{
|
||||
g_PluginSettings3 = *info;
|
||||
g_PluginSettings3 = *info;
|
||||
}
|
||||
|
||||
bool SettingsInitilized(void)
|
||||
int32_t SettingsInitilized(void)
|
||||
{
|
||||
return g_PluginInitilized;
|
||||
return g_PluginInitilized;
|
||||
}
|
||||
|
||||
void SetModuleName ( const char * Name )
|
||||
void SetModuleName(const char * Name)
|
||||
{
|
||||
_snprintf(g_PluginSettingName,sizeof(g_PluginSettingName),"%s",Name);
|
||||
_snprintf(g_PluginSettingName, sizeof(g_PluginSettingName), "%s", Name);
|
||||
}
|
||||
|
||||
void RegisterSetting ( short SettingID, SETTING_DATA_TYPE Type, const char * Name, const char * Category,
|
||||
unsigned int DefaultDW, const char * DefaultStr )
|
||||
void RegisterSetting(short SettingID, SETTING_DATA_TYPE Type, const char * Name, const char * Category,
|
||||
unsigned int DefaultDW, const char * DefaultStr)
|
||||
{
|
||||
int DefaultID = g_PluginSettings.NoDefault;
|
||||
SettingLocation Location = (SettingLocation)g_PluginSettings.DefaultLocation;
|
||||
char FullCategory[400];
|
||||
if (Category && Category[0] != 0)
|
||||
{
|
||||
_snprintf(FullCategory,sizeof(FullCategory),"%s\\%s",g_PluginSettingName,Category);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snprintf(FullCategory,sizeof(FullCategory),"%s",g_PluginSettingName);
|
||||
}
|
||||
int DefaultID = g_PluginSettings.NoDefault;
|
||||
SettingLocation Location = (SettingLocation)g_PluginSettings.DefaultLocation;
|
||||
char FullCategory[400];
|
||||
if (Category && Category[0] != 0)
|
||||
{
|
||||
_snprintf(FullCategory, sizeof(FullCategory), "%s\\%s", g_PluginSettingName, Category);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snprintf(FullCategory, sizeof(FullCategory), "%s", g_PluginSettingName);
|
||||
}
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case Data_DWORD_Game:
|
||||
case Data_String_Game:
|
||||
Location = SettingType_GameSetting;
|
||||
break;
|
||||
case Data_DWORD_RDB:
|
||||
case Data_String_RDB:
|
||||
Location = SettingType_RomDatabase;
|
||||
break;
|
||||
case Data_DWORD_RDB_Setting:
|
||||
case Data_String_RDB_Setting:
|
||||
Location = SettingType_RdbSetting;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case Data_DWORD_Game:
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange,
|
||||
g_PluginSettings.NoDefault,Data_DWORD,Location,FullCategory,Name,DefaultDW);
|
||||
break;
|
||||
case Data_DWORD_General:
|
||||
case Data_DWORD_RDB:
|
||||
case Data_DWORD_RDB_Setting:
|
||||
if (DefaultDW != 0)
|
||||
{
|
||||
//create default
|
||||
DefaultID = SettingID + g_PluginSettings.DefaultStartRange;
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle,DefaultID,g_PluginSettings.NoDefault,
|
||||
Data_DWORD,SettingType_ConstValue,g_PluginSettingName,"",DefaultDW);
|
||||
}
|
||||
switch (Type)
|
||||
{
|
||||
case Data_DWORD_Game:
|
||||
case Data_String_Game:
|
||||
Location = SettingType_GameSetting;
|
||||
break;
|
||||
case Data_DWORD_RDB:
|
||||
case Data_String_RDB:
|
||||
Location = SettingType_RomDatabase;
|
||||
break;
|
||||
case Data_DWORD_RDB_Setting:
|
||||
case Data_String_RDB_Setting:
|
||||
Location = SettingType_RdbSetting;
|
||||
break;
|
||||
}
|
||||
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange,
|
||||
DefaultID,Data_DWORD,Location,FullCategory,Name,0);
|
||||
break;
|
||||
case Data_String_General:
|
||||
case Data_String_Game:
|
||||
case Data_String_RDB:
|
||||
case Data_String_RDB_Setting:
|
||||
if (DefaultStr != NULL && strlen(DefaultStr) > 0)
|
||||
{
|
||||
//create default
|
||||
DefaultID = SettingID + g_PluginSettings.DefaultStartRange;
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle,DefaultID,g_PluginSettings.NoDefault,
|
||||
Data_String,SettingType_ConstString,g_PluginSettingName,DefaultStr,0);
|
||||
}
|
||||
switch (Type)
|
||||
{
|
||||
case Data_DWORD_Game:
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange,
|
||||
g_PluginSettings.NoDefault, Data_DWORD, Location, FullCategory, Name, DefaultDW);
|
||||
break;
|
||||
case Data_DWORD_General:
|
||||
case Data_DWORD_RDB:
|
||||
case Data_DWORD_RDB_Setting:
|
||||
if (DefaultDW != 0)
|
||||
{
|
||||
//create default
|
||||
DefaultID = SettingID + g_PluginSettings.DefaultStartRange;
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle, DefaultID, g_PluginSettings.NoDefault,
|
||||
Data_DWORD, SettingType_ConstValue, g_PluginSettingName, "", DefaultDW);
|
||||
}
|
||||
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange,
|
||||
DefaultID,Data_String,Location,FullCategory,Name,0);
|
||||
break;
|
||||
}
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange,
|
||||
DefaultID, Data_DWORD, Location, FullCategory, Name, 0);
|
||||
break;
|
||||
case Data_String_General:
|
||||
case Data_String_Game:
|
||||
case Data_String_RDB:
|
||||
case Data_String_RDB_Setting:
|
||||
if (DefaultStr != NULL && strlen(DefaultStr) > 0)
|
||||
{
|
||||
//create default
|
||||
DefaultID = SettingID + g_PluginSettings.DefaultStartRange;
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle, DefaultID, g_PluginSettings.NoDefault,
|
||||
Data_String, SettingType_ConstString, g_PluginSettingName, DefaultStr, 0);
|
||||
}
|
||||
|
||||
g_PluginSettings.RegisterSetting(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange,
|
||||
DefaultID, Data_String, Location, FullCategory, Name, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
short FindSystemSettingId ( const char * Name )
|
||||
short FindSystemSettingId(const char * Name)
|
||||
{
|
||||
if (g_PluginSettings2.FindSystemSettingId && g_PluginSettings.handle)
|
||||
{
|
||||
return (short)g_PluginSettings2.FindSystemSettingId(g_PluginSettings.handle,Name);
|
||||
}
|
||||
return 0;
|
||||
if (g_PluginSettings2.FindSystemSettingId && g_PluginSettings.handle)
|
||||
{
|
||||
return (short)g_PluginSettings2.FindSystemSettingId(g_PluginSettings.handle, Name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FlushSettings ( void )
|
||||
void FlushSettings(void)
|
||||
{
|
||||
if (g_PluginSettings3.FlushSettings && g_PluginSettings.handle)
|
||||
{
|
||||
g_PluginSettings3.FlushSettings(g_PluginSettings.handle);
|
||||
}
|
||||
if (g_PluginSettings3.FlushSettings && g_PluginSettings.handle)
|
||||
{
|
||||
g_PluginSettings3.FlushSettings(g_PluginSettings.handle);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int GetSetting ( short SettingID )
|
||||
unsigned int GetSetting(short SettingID)
|
||||
{
|
||||
if (g_PluginSettings.GetSetting == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return g_PluginSettings.GetSetting(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange);
|
||||
if (g_PluginSettings.GetSetting == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return g_PluginSettings.GetSetting(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange);
|
||||
}
|
||||
|
||||
unsigned int GetSystemSetting ( short SettingID )
|
||||
unsigned int GetSystemSetting(short SettingID)
|
||||
{
|
||||
return g_PluginSettings.GetSetting(g_PluginSettings.handle,SettingID);
|
||||
return g_PluginSettings.GetSetting(g_PluginSettings.handle, SettingID);
|
||||
}
|
||||
|
||||
const char * GetSettingSz ( short SettingID, char * Buffer, int BufferLen )
|
||||
const char * GetSettingSz(short SettingID, char * Buffer, int BufferLen)
|
||||
{
|
||||
return g_PluginSettings.GetSettingSz(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange,Buffer,BufferLen);
|
||||
return g_PluginSettings.GetSettingSz(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange, Buffer, BufferLen);
|
||||
}
|
||||
|
||||
const char * GetSystemSettingSz ( short SettingID, char * Buffer, int BufferLen )
|
||||
const char * GetSystemSettingSz(short SettingID, char * Buffer, int BufferLen)
|
||||
{
|
||||
if (g_PluginSettings.GetSettingSz == NULL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return g_PluginSettings.GetSettingSz(g_PluginSettings.handle,SettingID,Buffer,BufferLen);
|
||||
if (g_PluginSettings.GetSettingSz == NULL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return g_PluginSettings.GetSettingSz(g_PluginSettings.handle, SettingID, Buffer, BufferLen);
|
||||
}
|
||||
|
||||
void SetSetting ( short SettingID, unsigned int Value )
|
||||
void SetSetting(short SettingID, unsigned int Value)
|
||||
{
|
||||
g_PluginSettings.SetSetting(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange, Value);
|
||||
g_PluginSettings.SetSetting(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange, Value);
|
||||
}
|
||||
|
||||
void SetSettingSz ( short SettingID, const char * Value )
|
||||
void SetSettingSz(short SettingID, const char * Value)
|
||||
{
|
||||
g_PluginSettings.SetSettingSz(g_PluginSettings.handle,SettingID + g_PluginSettings.SettingStartRange, Value);
|
||||
g_PluginSettings.SetSettingSz(g_PluginSettings.handle, SettingID + g_PluginSettings.SettingStartRange, Value);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
// Get Plugin Settings, take a setting id
|
||||
unsigned int GetSetting ( short SettingID );
|
||||
const char * GetSettingSz ( short SettingID, char * Buffer, int BufferLen );
|
||||
|
@ -23,7 +17,8 @@ void SetSetting ( short SettingID, unsigned int Value );
|
|||
void SetSettingSz ( short SettingID, const char * Value );
|
||||
|
||||
// enum's
|
||||
enum SETTING_DATA_TYPE {
|
||||
enum SETTING_DATA_TYPE
|
||||
{
|
||||
Data_DWORD_General = 0, // A unsigned int setting used anywhere
|
||||
Data_String_General = 1, // A string setting used anywhere
|
||||
Data_DWORD_Game = 2, // A unsigned int associated with the current game
|
||||
|
@ -35,7 +30,7 @@ enum SETTING_DATA_TYPE {
|
|||
};
|
||||
|
||||
// set other information about different settings
|
||||
bool SettingsInitilized ( void );
|
||||
int SettingsInitilized ( void );
|
||||
void SetModuleName ( const char * Name );
|
||||
void RegisterSetting ( short SettingID, SETTING_DATA_TYPE Type, const char * Name, const char * Category,
|
||||
unsigned int DefaultDW, const char * DefaultStr );
|
||||
|
|
Loading…
Reference in New Issue