forked from len0rd/rockbox
Correct the spelling of persistent so its correct (Yes, I failed english at school).
Loading a persistent setting again (from any config file, including config.cfg unless it has a ~) will remove it from the list of persistent settings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12107 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
7760743b49
commit
b77f1217fb
1 changed files with 49 additions and 16 deletions
|
|
@ -259,19 +259,19 @@ static int hex_to_rgb(const char* hex)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#define MAX_PERSISTANT_VARS 8
|
#define MAX_PERSISTENT_VARS 8
|
||||||
struct persistant_vars {
|
struct persistent_vars {
|
||||||
char setting[MAX_FILENAME];
|
char setting[MAX_FILENAME];
|
||||||
char value[MAX_FILENAME];
|
char value[MAX_FILENAME];
|
||||||
};
|
};
|
||||||
static struct persistant_vars persistant_vars[MAX_PERSISTANT_VARS];
|
static struct persistent_vars persistent_vars[MAX_PERSISTENT_VARS];
|
||||||
static int persistant_vars_count = 0;
|
static int persistent_vars_count = 0;
|
||||||
bool settings_write_config(char* filename)
|
bool settings_write_config(char* filename)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int fd;
|
int fd;
|
||||||
bool check_persistant = !strcmp(filename, CONFIGFILE) &&
|
bool check_persistent = !strcmp(filename, CONFIGFILE) &&
|
||||||
persistant_vars_count;
|
persistent_vars_count;
|
||||||
char value[MAX_PATH];
|
char value[MAX_PATH];
|
||||||
fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY);
|
fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
|
@ -282,16 +282,16 @@ bool settings_write_config(char* filename)
|
||||||
{
|
{
|
||||||
if (settings[i].cfg_name == NULL)
|
if (settings[i].cfg_name == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (check_persistant)
|
if (check_persistent)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for(j=0; j<persistant_vars_count; j++)
|
for(j=0; j<persistent_vars_count; j++)
|
||||||
{
|
{
|
||||||
if (!strcmp(persistant_vars[j].setting, settings[i].cfg_name))
|
if (!strcmp(persistent_vars[j].setting, settings[i].cfg_name))
|
||||||
{
|
{
|
||||||
fdprintf(fd,"~%s: %s\r\n", settings[i].cfg_name,
|
fdprintf(fd,"~%s: %s\r\n", settings[i].cfg_name,
|
||||||
persistant_vars[j].value);
|
persistent_vars[j].value);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -747,7 +747,8 @@ bool settings_load_config(const char* file, bool apply)
|
||||||
char* name;
|
char* name;
|
||||||
char* value;
|
char* value;
|
||||||
int i;
|
int i;
|
||||||
bool check_persistant = !strcmp(file, CONFIGFILE);
|
bool check_persistent = !strcmp(file, CONFIGFILE);
|
||||||
|
bool is_persistent = false;
|
||||||
fd = open(file, O_RDONLY);
|
fd = open(file, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -756,20 +757,52 @@ bool settings_load_config(const char* file, bool apply)
|
||||||
{
|
{
|
||||||
if (!settings_parseline(line, &name, &value))
|
if (!settings_parseline(line, &name, &value))
|
||||||
continue;
|
continue;
|
||||||
if (check_persistant && (name[0] == '~')
|
if (name[0] == '~')
|
||||||
&& (persistant_vars_count<MAX_PERSISTANT_VARS))
|
|
||||||
{
|
{
|
||||||
name++;
|
name++;
|
||||||
strcpy(persistant_vars[persistant_vars_count].setting, name);
|
if (check_persistent &&
|
||||||
strcpy(persistant_vars[persistant_vars_count].value, value);
|
(persistent_vars_count<MAX_PERSISTENT_VARS))
|
||||||
persistant_vars_count++;
|
{
|
||||||
|
strcpy(persistent_vars[persistent_vars_count].setting, name);
|
||||||
|
strcpy(persistent_vars[persistent_vars_count].value, value);
|
||||||
|
persistent_vars_count++;
|
||||||
|
is_persistent = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else is_persistent = false;
|
||||||
for(i=0; i<nb_settings; i++)
|
for(i=0; i<nb_settings; i++)
|
||||||
{
|
{
|
||||||
if (settings[i].cfg_name == NULL)
|
if (settings[i].cfg_name == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (!strcasecmp(name,settings[i].cfg_name))
|
if (!strcasecmp(name,settings[i].cfg_name))
|
||||||
{
|
{
|
||||||
|
if (persistent_vars_count && !is_persistent)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
struct persistent_vars *p_var,
|
||||||
|
*p_var_last = &persistent_vars[persistent_vars_count-1];
|
||||||
|
for (j=0; j< persistent_vars_count; j++)
|
||||||
|
{
|
||||||
|
p_var = &persistent_vars[j];
|
||||||
|
if (!strcmp(name,p_var->setting))
|
||||||
|
{
|
||||||
|
if (j+1 == persistent_vars_count)
|
||||||
|
{
|
||||||
|
/* simple case, just decrement
|
||||||
|
persistent_vars_count */
|
||||||
|
persistent_vars_count--;
|
||||||
|
}
|
||||||
|
/*else move the last persistent var to here */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(p_var->setting, p_var_last->setting);
|
||||||
|
strcpy(p_var->value, p_var_last->value);
|
||||||
|
persistent_vars_count--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (settings[i].flags&F_T_MASK)
|
switch (settings[i].flags&F_T_MASK)
|
||||||
{
|
{
|
||||||
case F_T_INT:
|
case F_T_INT:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue