Index: apps/playlist.c =================================================================== --- apps/playlist.c (Revision 19053) +++ apps/playlist.c (Arbeitskopie) @@ -3561,3 +3561,13 @@ return result; } + +/* + * Check if a folder exists, if not try to create it + * return folder or "/" if it's not possible to create the folder + */ +const char* playlist_check_mkdir(const char* dirname) +{ + return dir_exists(dirname) ? + dirname : mkdir(dirname)==0 ? dirname : "/"; +} Index: apps/playlist.h =================================================================== --- apps/playlist.h (Revision 19053) +++ apps/playlist.h (Arbeitskopie) @@ -34,7 +34,7 @@ #define PLAYLIST_DISPLAY_COUNT 10 -#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8" +#define DEFAULT_DYNAMIC_PLAYLIST_NAME "dynamic.m3u8" enum playlist_command { PLAYLIST_COMMAND_PLAYLIST, @@ -131,6 +131,7 @@ int playlist_update_resume_info(const struct mp3entry* id3); int playlist_get_display_index(void); int playlist_amount(void); +const char* playlist_check_mkdir(const char*); /* Exported functions for all playlists. Pass NULL for playlist_info structure to work with current playlist. */ Index: apps/menus/playlist_menu.c =================================================================== --- apps/menus/playlist_menu.c (Revision 19053) +++ apps/menus/playlist_menu.c (Arbeitskopie) @@ -24,6 +24,7 @@ #include #include #include +#include #include "config.h" #include "lang.h" #include "action.h" @@ -52,7 +53,11 @@ strcat(temp, "8"); if (len <= 5 || strcasecmp(&temp[len-5], ".m3u8")) - strcpy(temp, DEFAULT_DYNAMIC_PLAYLIST_NAME); + { + snprintf(temp, MAX_PATH, "%s/%s", + playlist_check_mkdir(global_settings.playlist_catalog_dir), + DEFAULT_DYNAMIC_PLAYLIST_NAME); + } if (!kbd_input(temp, sizeof(temp))) { Index: apps/playlist_catalog.c =================================================================== --- apps/playlist_catalog.c (revision 22019) +++ apps/playlist_catalog.c (working copy) @@ -56,55 +56,19 @@ static char most_recent_playlist[MAX_PATH]; /* directory where our playlists our stored */ -static char playlist_dir[MAX_PATH]; -static int playlist_dir_length; -static bool playlist_dir_exists = false; +static char* playlist_dir; /* Retrieve playlist directory from config file and verify it exists */ -static int initialize_catalog(void) +static void initialize_catalog(void) { static bool initialized = false; if (!initialized) { - bool default_dir = true; - - /* directory config is of the format: "dir: /path/to/dir" */ - if (global_settings.playlist_catalog_dir[0]) - { - strcpy(playlist_dir, global_settings.playlist_catalog_dir); - default_dir = false; - } - - /* fall back to default directory if no or invalid config */ - if (default_dir) - strlcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR, - sizeof(playlist_dir)); - - playlist_dir_length = strlen(playlist_dir); - - if (dir_exists(playlist_dir)) - { - playlist_dir_exists = true; - memset(most_recent_playlist, 0, sizeof(most_recent_playlist)); - initialized = true; - } + playlist_dir = playlist_check_mkdir(global_settings.playlist_catalog_dir); + memset(most_recent_playlist, 0, sizeof(most_recent_playlist)); + initialized = true; } - - if (!playlist_dir_exists) - { - if (mkdir(playlist_dir) < 0) { - splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir); - return -1; - } - else { - playlist_dir_exists = true; - memset(most_recent_playlist, 0, sizeof(most_recent_playlist)); - initialized = true; - } - } - - return 0; } /* Use the filetree functions to retrieve the list of playlists in the directory */ @@ -434,13 +398,8 @@ bool catalog_view_playlists(void) { - if (initialize_catalog() == -1) - return false; - - if (display_playlists(NULL, true) == -1) - return false; - - return true; + initialize_catalog(); + return display_playlists(NULL, true) != -1; } bool catalog_add_to_a_playlist(const char* sel, int sel_attr, @@ -448,8 +407,7 @@ { char playlist[MAX_PATH]; - if (initialize_catalog() == -1) - return false; + initialize_catalog(); if (new_playlist) { @@ -478,7 +436,7 @@ if (add_to_playlist(playlist, new_playlist, sel, sel_attr) == 0) { - strlcpy(most_recent_playlist, playlist+playlist_dir_length+1, + strncpy(most_recent_playlist, playlist+strlen(playlist_dir)+1, sizeof(most_recent_playlist)); return true; }