📄 bookmark.c
字号:
while (read_line(bookmark_file, global_read_buffer, sizeof(global_read_buffer))) { /* The MRB has a max of MAX_BOOKMARKS in it */ /* This keeps it from getting too large */ if ((strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE)==0)) { if(bookmark_count >= MAX_BOOKMARKS) break; } if (check_bookmark(global_read_buffer)) { if (bookmark_id != bookmark_count) { write(temp_bookmark_file, global_read_buffer, strlen(global_read_buffer)); write(temp_bookmark_file, "\n", 1); } bookmark_count++; } } close(bookmark_file); close(temp_bookmark_file); remove(bookmark_file_name); rename(global_temp_buffer, bookmark_file_name); return true;}/* ----------------------------------------------------------------------- *//* This function parses a bookmark and displays it for the user. *//* ------------------------------------------------------------------------*/static void display_bookmark(char* bookmark, int bookmark_id, int bookmark_count){ int resume_index = 0; int ms = 0; int repeat_mode = 0; bool playlist_shuffle = false; char MP3_file_name[45]; int len; char *dot; /* getting the index and the time into the file */ parse_bookmark(bookmark, &resume_index, NULL, NULL, NULL, NULL, 0, &ms, &repeat_mode, &playlist_shuffle, MP3_file_name, sizeof(MP3_file_name)); lcd_clear_display(); lcd_stop_scroll();#ifdef HAVE_LCD_BITMAP /* bookmark shuffle and repeat states*/ switch (repeat_mode) { case REPEAT_ONE: statusbar_icon_play_mode(Icon_RepeatOne); break; case REPEAT_ALL: statusbar_icon_play_mode(Icon_Repeat); break; } if(playlist_shuffle) statusbar_icon_shuffle(); /* File Name */ len=strlen(MP3_file_name); if (len>3) dot=strrchr(MP3_file_name + len - 4, '.'); else dot=NULL; if (dot) *dot='\0'; lcd_puts_scroll(0, 0, MP3_file_name); if (dot) *dot='.'; /* bookmark number */ snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %2d/%2d", str(LANG_BOOKMARK_SELECT_BOOKMARK_TEXT), bookmark_id + 1, bookmark_count); lcd_puts_scroll(0, 1, global_temp_buffer); /* bookmark resume index */ snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %2d", str(LANG_BOOKMARK_SELECT_INDEX_TEXT), resume_index+1); lcd_puts_scroll(0, 2, global_temp_buffer); /* elapsed time*/ snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %d:%02d", str(LANG_BOOKMARK_SELECT_TIME_TEXT), ms / 60000, ms % 60000 / 1000); lcd_puts_scroll(0, 3, global_temp_buffer); /* commands */ lcd_puts_scroll(0, 4, str(LANG_BOOKMARK_SELECT_PLAY)); lcd_puts_scroll(0, 5, str(LANG_BOOKMARK_SELECT_EXIT)); lcd_puts_scroll(0, 6, str(LANG_BOOKMARK_SELECT_DELETE));#else (void)bookmark_id; len=strlen(MP3_file_name); if (len>3) dot=strrchr(MP3_file_name+len-4,'.'); else dot=NULL; if (dot) *dot='\0'; snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%2d, %d:%02d, %s,", (bookmark_count+1), ms / 60000, ms % 60000 / 1000, MP3_file_name); status_draw(false); lcd_puts_scroll(0,0,global_temp_buffer); lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER)); if (dot) *dot='.';#endif lcd_update();}/* ----------------------------------------------------------------------- *//* This function retrieves a given bookmark from a file. *//* If the bookmark requested is beyond the number of bookmarks available *//* in the file, it will return the last one. *//* It also returns the index number of the bookmark in the file *//* ------------------------------------------------------------------------*/static char* get_bookmark(char* bookmark_file, int bookmark_count){ int read_count = -1; int result = 0; int file = open(bookmark_file, O_RDONLY); if (file < 0) return NULL; /* Get the requested bookmark */ while (read_count < bookmark_count) { /*Reading in a single bookmark */ result = read_line(file, global_read_buffer, sizeof(global_read_buffer)); /* Reading past the last bookmark in the file causes the loop to stop */ if (result <= 0) break; read_count++; } close(file); if (read_count == bookmark_count) return global_read_buffer; else return NULL;}/* ----------------------------------------------------------------------- *//* This function takes a bookmark and parses it. This function also *//* validates the bookmark. Passing in NULL for an output variable *//* indicates that value is not requested. *//* ----------------------------------------------------------------------- */static bool parse_bookmark(char *bookmark, int *resume_index, int *resume_offset, int *resume_seed, int *resume_first_index, char* resume_file, unsigned int resume_file_size, int* ms, int * repeat_mode, bool *shuffle, char* file_name, unsigned int max_file_name_size){ /* First check to see if a valid line was passed in. */ int bookmark_len = strlen(bookmark); int local_resume_index = 0; int local_resume_offset = 0; int local_resume_seed = 0; int local_resume_first_index = 0; int local_mS = 0; int local_shuffle = 0; int local_repeat_mode = 0; char* local_resume_file = NULL; char* local_file_name = NULL; char* field; char* end; static char bookmarkcopy[MAX_BOOKMARK_SIZE]; /* Don't do anything if the bookmark length is 0 */ if (bookmark_len <= 0) return false; /* Making a dup of the bookmark to use with strtok_r */ strncpy(bookmarkcopy, bookmark, sizeof(bookmarkcopy)); bookmarkcopy[sizeof(bookmarkcopy) - 1] = 0; /* resume_index */ if ((field = strtok_r(bookmarkcopy, ";", &end))) local_resume_index = atoi(field); else return false; /* resume_offset */ if ((field = strtok_r(NULL, ";", &end))) local_resume_offset = atoi(field); else return false; /* resume_seed */ if ((field = strtok_r(NULL, ";", &end))) local_resume_seed = atoi(field); else return false; /* resume_first_index */ if ((field = strtok_r(NULL, ";", &end))) local_resume_first_index = atoi(field); else return false; /* Milliseconds into MP3. Used for the bookmark select menu */ if ((field = strtok_r(NULL, ";", &end))) local_mS = atoi(field); else return false; /* repeat_mode */ if ((field = strtok_r(NULL, ";", &end))) local_repeat_mode = atoi(field); else return false; /* shuffle mode */ if ((field = strtok_r(NULL, ";", &end))) local_shuffle = atoi(field); else return false; /* resume_file & file_name (for the bookmark select menu)*/ if (end) { local_resume_file = strtok_r(NULL, ";", &end); if (local_resume_file[strlen(local_resume_file) - 1] == '/') local_resume_file[strlen(local_resume_file) - 1] = '\0'; if (end) local_file_name = strtok_r(NULL, ";", &end); } else return false; /* Only return the values the calling function wants */ if (resume_index) *resume_index = local_resume_index; if (resume_offset) *resume_offset = local_resume_offset; if (resume_seed) *resume_seed = local_resume_seed; if (resume_first_index) *resume_first_index = local_resume_first_index; if (resume_file && local_resume_file) { strncpy(resume_file, local_resume_file, MIN(strlen(local_resume_file), resume_file_size-1)); resume_file[MIN(strlen(local_resume_file), resume_file_size-1)]=0; } if (ms) *ms = local_mS; if (shuffle) *shuffle = local_shuffle; if (repeat_mode) *repeat_mode = local_repeat_mode; if (file_name && local_file_name) { strncpy(file_name, local_file_name, MIN(strlen(local_file_name),max_file_name_size-1)); file_name[MIN(strlen(local_file_name),max_file_name_size-1)]=0; } return true;}/* ----------------------------------------------------------------------- *//* This function is used by multiple functions and is used to generate a *//* bookmark named based off of the input. *//* Changing this function could result in how the bookmarks are stored. *//* it would be here that the centralized/decentralized bookmark code *//* could be placed. *//* ----------------------------------------------------------------------- */static bool generate_bookmark_file_name(char *in, char *out, unsigned int max_length){ char* cp; if (!in || !out || max_length <= 0) return false; if (max_length < strlen(in)+6) return false; /* if this is a root dir MP3, rename the boomark file root_dir.bmark */ /* otherwise, name it based on the in variable */ cp = in; cp = in + strlen(in) - 1; if (*cp == '/') *cp = 0; cp = in; if (*cp == '/') cp++; if (strlen(in) > 0) snprintf(out, max_length, "/%s.%s", cp, "bmark"); else snprintf(out, max_length, "/root_dir.%s", "bmark"); return true;}/* ----------------------------------------------------------------------- *//* Checks the current state of the system and returns if it is in a *//* bookmarkable state. *//* ----------------------------------------------------------------------- *//* Inputs: *//* ----------------------------------------------------------------------- *//* Outputs: *//* return bool: Indicates if the system was in a bookmarkable state *//* ----------------------------------------------------------------------- */static bool system_check(void){ int resume_index = 0; struct mp3entry *id3 = mpeg_current_track(); if (!id3) { /* no track playing */ return false; } /* Checking to see if playing a queued track */ if (playlist_get_resume_info(&resume_index) == -1) { /* something bad happened while getting the queue information */ return false; } else if (playlist_modified(NULL)) { /* can't bookmark while in the queue */ return false; } return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -