1
0
Fork 0
forked from len0rd/rockbox

[BugFix] pitch screen load config fd wasn't closed

check file_exist(PITCH_CFG_FILE)
close fd when finished

If you already have a setting saved and you reenter the pitch plugin
with differing pitch settings you will be asked to restore your
default settings

update manual entry to be a clearer

Change-Id: Iaaaf08983a355f9848412d1c6b0bba25d6ea8f39
This commit is contained in:
William Wilgus 2025-01-18 11:08:13 -05:00
parent a8f6ddc5ed
commit c4ceea40bf
4 changed files with 49 additions and 31 deletions

View file

@ -197,26 +197,29 @@ void INIT_ATTR audio_init(void)
char* name;
char* value;
int32_t num;
fd = open_utf8(PITCH_CFG_FILE, O_RDONLY);
if (fd >= 0)
if (file_exists(PITCH_CFG_FILE))
{
while (read_line(fd, line, sizeof line) > 0)
fd = open_utf8(PITCH_CFG_FILE, O_RDONLY);
if (fd >= 0)
{
if (!settings_parseline(line, &name, &value))
continue;
if (strcasecmp(name, "pitch") == 0)
while (read_line(fd, line, sizeof line) > 0)
{
num = atoi(value);
if (num != PITCH_SPEED_100)
sound_set_pitch(num);
}
if (strcasecmp(name, "stretch") == 0)
{
num = atoi(value);
if (num != PITCH_SPEED_100)
dsp_set_timestretch(num);
if (!settings_parseline(line, &name, &value))
continue;
if (strcasecmp(name, "pitch") == 0)
{
num = atoi(value);
if (num != PITCH_SPEED_100)
sound_set_pitch(num);
}
if (strcasecmp(name, "stretch") == 0)
{
num = atoi(value);
if (num != PITCH_SPEED_100)
dsp_set_timestretch(num);
}
}
close(fd);
}
}
#endif

View file

@ -23,6 +23,13 @@
static void get_cfg_filename(char* buf, int buf_len, const char* filename)
{
if (rb->strncmp(filename, ROCKBOX_DIR, sizeof(ROCKBOX_DIR) - 1) == 0)
{
/* allow the rockbox directory */
rb->snprintf(buf, buf_len, "/%s", filename);
return;
}
#ifdef APPLICATION
rb->snprintf(buf, buf_len, PLUGIN_DATA_DIR "/%s", filename);
#else
@ -49,14 +56,8 @@ int configfile_save(const char *filename, const struct configdata *cfg,
int i;
char buf[MAX_PATH];
if (rb->strncmp(filename, ROCKBOX_DIR, sizeof(ROCKBOX_DIR) - 1) != 0)
{
get_cfg_filename(buf, MAX_PATH, filename);
fd = rb->creat(buf, 0666);
}
else /* allow saving to the rockbox directory */
fd = rb->creat(filename, 0666);
get_cfg_filename(buf, MAX_PATH, filename);
fd = rb->creat(buf, 0666);
if(fd < 0)
return fd*10 - 1;

View file

@ -1241,6 +1241,21 @@ enum plugin_status plugin_start(const void* parameter)
rb->settings_save();
}
gui = true;
if (rb->file_exists(CFG_FILE))
{
if (configfile_load(CFG_FILE, pitchcfg, 2, CFG_VER) >= 0)
{
if (pitch_vars.pitch != cur.pitch || pitch_vars.stretch != cur.stretch)
{
if (rb->yesno_pop(ID2P(LANG_REVERT_TO_DEFAULT_SETTINGS)))
{
rb->sound_set_pitch(pitch_vars.pitch);
rb->dsp_set_timestretch(pitch_vars.stretch);
}
}
}
}
}
else
{
@ -1294,9 +1309,7 @@ enum plugin_status plugin_start(const void* parameter)
if (pitch_vars.pitch != cur.pitch || pitch_vars.stretch != cur.stretch)
{
if (configfile_save(CFG_FILE, pitchcfg, 2, CFG_VER) >= 0)
rb->splash(HZ, ID2P(LANG_SETTINGS_SAVED));
else
if (configfile_save(CFG_FILE, pitchcfg, 2, CFG_VER) < 0)
rb->splash(HZ, ID2P(LANG_ERROR_WRITING_CONFIG));
}
}