7#if defined(SDL_LIBRETRO_IMPLEMENTATION) && !defined(SDL_LIBRETRO_CONFIG_IMPL_ONCE)
8#define SDL_LIBRETRO_CONFIG_IMPL_ONCE
10static void SDL_Libretro_SanitizeSectionName(
char* dst,
size_t dstSize,
const char* name) {
11 SDL_strlcpy(dst, name, dstSize);
12 for (
char* p = dst; *p; ++p) {
13 if (*p ==
'[' || *p ==
']' || *p ==
'\n' || *p ==
'\r') {
27 if (!lr || !file)
return false;
30 SDL_free(lr->iniFile);
36 SDL_ini* ini = INI_Load(file);
39 if (!ini)
return false;
43 lr->iniFile = SDL_strdup(file);
51 if (INI_HasValue(ini, NULL,
"volume"))
53 if (INI_HasValue(ini, NULL,
"username"))
54 SDL_Libretro_SetUsername(lr, INI_GetString(ini, NULL,
"username", SDL_Libretro_GetUsername(lr)));
55 if (INI_HasValue(ini, NULL,
"audiolatency"))
57 if (INI_HasValue(ini, NULL,
"fitmode"))
59 if (INI_HasValue(ini, NULL,
"savedirectory"))
60 SDL_Libretro_SetSaveDirectory(lr, INI_GetString(ini, NULL,
"savedirectory", SDL_Libretro_GetSaveDirectory(lr)));
61 if (INI_HasValue(ini, NULL,
"systemdirectory"))
62 SDL_Libretro_SetSystemDirectory(lr, INI_GetString(ini, NULL,
"systemdirectory", SDL_Libretro_GetSystemDirectory(lr)));
63 if (INI_HasValue(ini, NULL,
"coredirectory"))
65 if (INI_HasValue(ini, NULL,
"coreassetsdirectory"))
66 SDL_Libretro_SetCoreAssetsDirectory(lr, INI_GetString(ini, NULL,
"coreassetsdirectory", SDL_Libretro_GetCoreAssetsDirectory(lr)));
81 if (!lr)
return false;
82 if (!org || org[0] ==
'\0') org =
"SDL_libretro";
83 if (!app || app[0] ==
'\0') app =
"SDL_libretro";
84 char* prefPath = SDL_GetPrefPath(org, app);
85 if (!prefPath)
return false;
86 char path[SDL_LIBRETRO_MAX_PATH];
87 SDL_snprintf(path,
sizeof(path),
"%s%s.cfg", prefPath, app);
95static void SDL_Libretro_SetCoreConfigOption(
void *userdata,
const SDL_ini *ini,
const char* section,
const char *key,
const char *value) {
104static bool SDL_Libretro_LoadCoreConfig(SDL_Libretro* lr) {
105 if (!lr || !lr->ini || !SDL_Libretro_IsCoreReady(lr))
return false;
109 SDL_Libretro_SanitizeSectionName(section,
sizeof(section), lr->core.libraryName);
112 if (section[0] ==
'\0') {
115 INI_EnumerateKeys(lr->ini, section, &SDL_Libretro_SetCoreConfigOption, (
void*)lr);
122static bool SDL_Libretro_SaveCoreConfig(SDL_Libretro* lr) {
123 if (!lr || !lr->ini || !SDL_Libretro_IsCoreReady(lr))
return false;
125 SDL_Libretro_SanitizeSectionName(section,
sizeof(section), lr->core.libraryName);
126 if (section[0] ==
'\0') {
130 for (
int i = 0; i < count; i++) {
132 if (!option)
continue;
136 INI_RemoveKey(lr->ini, section, option->key);
139 INI_SetString(lr->ini, section, option->key, val);
147static bool SDL_Libretro_SaveConfig(SDL_Libretro* lr) {
148 if (!lr || !lr->ini || !lr->iniFile)
return false;
151 if (lr->core.loaded) {
152 SDL_Libretro_SaveCoreConfig(lr);
155 INI_SetFloat(lr->ini, NULL,
"volume", SDL_Libretro_GetVolume(lr));
156 INI_SetString(lr->ini, NULL,
"username", SDL_Libretro_GetUsername(lr));
157 INI_SetInt(lr->ini, NULL,
"audiolatency", (Sint64)SDL_Libretro_GetAudioLatency(lr));
158 INI_SetInt(lr->ini, NULL,
"fitmode", (Sint64)SDL_Libretro_GetFitMode(lr));
159 INI_SetString(lr->ini, NULL,
"savedirectory", SDL_Libretro_GetSaveDirectory(lr));
160 INI_SetString(lr->ini, NULL,
"systemdirectory", SDL_Libretro_GetSystemDirectory(lr));
161 INI_SetString(lr->ini, NULL,
"coredirectory", SDL_Libretro_GetCoreDirectory(lr));
162 INI_SetString(lr->ini, NULL,
"coreassetsdirectory", SDL_Libretro_GetCoreAssetsDirectory(lr));
164 return INI_Save(lr->ini, lr->iniFile);
170static bool SDL_Libretro_CloseConfig(SDL_Libretro* lr) {
171 if (!lr)
return false;
172 bool ok = SDL_Libretro_SaveConfig(lr);
173 SDL_free(lr->iniFile);
175 INI_Destroy(lr->ini);
bool SDL_Libretro_SetCoreDirectory(SDL_Libretro *lr, const char *path)
Sets the associated libretro core directory, where the default set of cores will be loaded from.
bool SDL_Libretro_InitConfig(SDL_Libretro *lr, const char *org, const char *app)
Sets up the config file to be the default path, accoring to the organization and app name.
bool SDL_Libretro_InitConfigFile(SDL_Libretro *lr, const char *file)
Initializes the config system based on the given file.
const SDL_LibretroOption * SDL_Libretro_GetOptionByIndex(const SDL_Libretro *lr, unsigned index)
Retrieve a core option by its registration index, or NULL if out of range.
void SDL_Libretro_SetVolume(SDL_Libretro *lr, float volume)
Set the audio volume when playing sounds.
void SDL_Libretro_SetAudioLatency(SDL_Libretro *lr, unsigned latencyMs)
Set the desired minimum audio latency for the audio stream.
bool SDL_Libretro_SetOptionValue(SDL_Libretro *lr, const char *key, const char *value)
Set a core option's value; fails if the value isn't one the core declared.
unsigned SDL_Libretro_GetOptionCount(const SDL_Libretro *lr)
Get the number of core options that have been set.
void SDL_Libretro_SetFitMode(SDL_Libretro *lr, SDL_LibretroFitMode mode)
Sets the desired scale mode for the libretro context when it's displayed.
A core option and its current state.
const char * value
Description / help text; may be empty.
const char * defaultValue
The current value.