From 2e195e52421a3fe798a0dc9ad8b31bf6a2e1836a Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 25 Jul 2010 22:51:01 +0200 Subject: [PATCH] Convert string settings' prefix to user path. --- apps/paths.c | 11 ++--------- apps/paths.h | 11 ++++++----- apps/settings.c | 17 +++++++++++------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/paths.c b/apps/paths.c index f6deda112..3ea969f67 100644 --- a/apps/paths.c +++ b/apps/paths.c @@ -44,16 +44,9 @@ const char* get_user_file_path(const char *path, const size_t bufsize) { const char *ret = path; - char end[MAX_PATH]; - memset(end, 0, sizeof(end)); - printf("%s(): looking for %s\n", __func__, path); - /* replace ROCKBOX_DIR in path with $HOME/.config/rockbox.org */ + const char *pos = path + ROCKBOX_DIR_LEN; - /* hopefully rockbox directories never get spaces in their name, - * this could break then */ - if (sscanf(path, ROCKBOX_DIR "/%s", end) == 0) - return NULL; - if (snprintf(buf, bufsize, "%s/.config/rockbox.org/%s", getenv("HOME"), end) + if (snprintf(buf, bufsize, "%s/.config/rockbox.org/%s", getenv("HOME"), pos) >= (int)bufsize) return NULL; diff --git a/apps/paths.h b/apps/paths.h index 36a0b4c1d..12a0bb624 100644 --- a/apps/paths.h +++ b/apps/paths.h @@ -36,7 +36,6 @@ * the passed path directly otherwise, e.g. always on target builds) */ #define FORCE_BUFFER_COPY (1<<2) -#ifndef APPLICATION /* name of directory where configuration, fonts and other data @@ -49,10 +48,6 @@ #define ROCKBOX_DIR_LEN 1 #else -/* make sure both are the same for native builds */ -#undef ROCKBOX_LIBRARY_PATH -#define ROCKBOX_LIBRARY_PATH ROCKBOX_DIR - /* ROCKBOX_DIR is now defined in autoconf.h for flexible build types */ #ifndef ROCKBOX_DIR #error ROCKBOX_DIR not defined (should be in autoconf.h) @@ -60,6 +55,12 @@ #define ROCKBOX_DIR_LEN sizeof(ROCKBOX_DIR) #endif /* def __PCTOOL__ */ +#ifndef APPLICATION + +/* make sure both are the same for native builds */ +#undef ROCKBOX_LIBRARY_PATH +#define ROCKBOX_LIBRARY_PATH ROCKBOX_DIR + #define PLUGIN_DIR ROCKBOX_DIR "/rocks" #define CODECS_DIR ROCKBOX_DIR "/codecs" #define LANG_DIR ROCKBOX_DIR "/langs" diff --git a/apps/settings.c b/apps/settings.c index 7bf9f4caa..a447d3f32 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -342,10 +342,12 @@ bool settings_load_config(const char* file, bool apply) char storage[MAX_PATH]; if (settings[i].filename_setting->prefix) { - int len = strlen(settings[i].filename_setting->prefix); - if (!strncasecmp(value, - settings[i].filename_setting->prefix, - len)) + char prefix_dir[MAX_PATH]; + const char *dir = get_user_file_path( + settings[i].filename_setting->prefix, + 0, prefix_dir, sizeof(prefix_dir)); + int len = strlen(dir); + if (!strncasecmp(value, dir, len)) { strlcpy(storage, &value[len], MAX_PATH); } @@ -478,6 +480,10 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) if (((char*)settings[i].setting)[0] && settings[i].filename_setting->prefix) { + char path[MAX_PATH]; + const char *prefix = get_user_file_path( + settings[i].filename_setting->prefix, 0, + path, sizeof(path)); if (((char*)settings[i].setting)[0] == '-') { buf[0] = '-'; @@ -485,8 +491,7 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) } else { - snprintf(buf,buf_len,"%s%s%s", - settings[i].filename_setting->prefix, + snprintf(buf,buf_len,"%s%s%s", prefix, (char*)settings[i].setting, settings[i].filename_setting->suffix); } -- 2.11.4.GIT