Index: apps/playlist.c =================================================================== --- apps/playlist.c (revision 17284) +++ apps/playlist.c (working copy) @@ -3612,3 +3612,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_catalog.c =================================================================== --- apps/playlist_catalog.c (revision 17284) +++ apps/playlist_catalog.c (working copy) @@ -54,56 +54,18 @@ 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) - strncpy(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) { - gui_syncsplash(HZ*2, str(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 */ @@ -410,21 +372,15 @@ 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(char* sel, int sel_attr, bool new_playlist) { char playlist[MAX_PATH]; - if (initialize_catalog() == -1) - return false; + initialize_catalog(); if (new_playlist) { @@ -448,7 +404,7 @@ if (add_to_playlist(playlist, sel, sel_attr) == 0) { - strncpy(most_recent_playlist, playlist+playlist_dir_length+1, + strncpy(most_recent_playlist, playlist+strlen(playlist_dir)+1, sizeof(most_recent_playlist)); return true; } Index: apps/playlist.h =================================================================== --- apps/playlist.h (revision 17284) +++ apps/playlist.h (working copy) @@ -30,7 +30,7 @@ #define PLAYLIST_ATTR_SKIPPED 0x04 #define PLAYLIST_MAX_CACHE 16 -#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8" +#define DEFAULT_DYNAMIC_PLAYLIST_NAME "dynamic.m3u8" enum playlist_command { PLAYLIST_COMMAND_PLAYLIST, @@ -127,6 +127,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 17284) +++ apps/menus/playlist_menu.c (working copy) @@ -22,6 +22,7 @@ #include #include #include +#include #include "config.h" #include "lang.h" #include "action.h" @@ -50,7 +51,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))) {