📄 bookmark.c
字号:
/* This keeps it from getting too large */ if ((strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE)==0)) { if(bookmark_count >= MAX_BOOKMARKS) break; } if (unique) { cp=strchr(global_read_buffer,'/'); if (check_bookmark(global_read_buffer) && strncmp(playlist,cp,len)) { bookmark_count++; write(temp_bookmark_file, global_read_buffer, strlen(global_read_buffer)); write(temp_bookmark_file, "\n", 1); } } else { if (check_bookmark(global_read_buffer)) { bookmark_count++; write(temp_bookmark_file, global_read_buffer, strlen(global_read_buffer)); write(temp_bookmark_file, "\n", 1); } } } close(bookmark_file); } close(temp_bookmark_file); remove(bookmark_file_name); rename(global_temp_buffer, bookmark_file_name); return true;}/* ----------------------------------------------------------------------- *//* This function takes the system resume data and formats it into a valid *//* bookmark. *//* ----------------------------------------------------------------------- */static char* create_bookmark(){ int resume_index = 0; char *file; /* grab the currently playing track */ struct mp3entry *id3 = mpeg_current_track(); if(!id3) return NULL; /* Get some basic resume information */ /* queue_resume and queue_resume_index are not used and can be ignored.*/ playlist_get_resume_info(&resume_index); /* Get the currently playing file minus the path */ /* This is used when displaying the available bookmarks */ file = strrchr(id3->path,'/'); if(NULL == file) return NULL; /* create the bookmark */ snprintf(global_bookmark, sizeof(global_bookmark), "%d;%d;%d;%d;%d;%d;%d;%s;%s", resume_index, id3->offset, playlist_get_seed(NULL), 0, id3->elapsed, global_settings.repeat_mode, global_settings.playlist_shuffle, playlist_get_name(NULL, global_temp_buffer, sizeof(global_temp_buffer)), file+1); /* checking to see if the bookmark is valid */ if (check_bookmark(global_bookmark)) return global_bookmark; else return NULL;}static bool check_bookmark(char* bookmark){ return parse_bookmark(bookmark, NULL,NULL,NULL, NULL, NULL,0,NULL,NULL, NULL, NULL, 0);}/* ----------------------------------------------------------------------- *//* This function will determine if an autoload is necessary. This is an *//* interface function. *//* ------------------------------------------------------------------------*/bool bookmark_autoload(char* file){ int key; int fd; bool done = false; if(global_settings.autoloadbookmark == BOOKMARK_NO) return false; /*Checking to see if a bookmark file exists.*/ if(!generate_bookmark_file_name(file, global_bookmark_file_name, sizeof(global_bookmark_file_name))) { return false; } fd = open(global_bookmark_file_name, O_RDONLY); if(fd<0) return false; if(-1 == lseek(fd, 0, SEEK_END)) { close(fd); return false; } close(fd); if(global_settings.autoloadbookmark == BOOKMARK_YES) { return bookmark_load(global_bookmark_file_name, true); } else { while (button_get(false)); /* clear button queue */ /* Prompting user to confirm bookmark load */ lcd_clear_display();#ifdef HAVE_LCD_BITMAP lcd_puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY)); lcd_puts(0,1, str(LANG_CONFIRM_WITH_PLAY_RECORDER)); lcd_puts(0,2, str(LANG_BOOKMARK_SELECT_LIST_BOOKMARKS)); lcd_puts(0,3, str(LANG_CANCEL_WITH_ANY_RECORDER));#else status_draw(false); lcd_puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY)); lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER));#endif lcd_update(); sleep(100); while(!done) { /* Wait for a key to be pushed */ while (button_get(false)); /* clear button queue */ key = button_get(true); switch(key) { default: return false;#ifdef HAVE_LCD_BITMAP case BUTTON_DOWN: return bookmark_load(global_bookmark_file_name, false);#endif case BUTTON_PLAY: return bookmark_load(global_bookmark_file_name, true); case SYS_USB_CONNECTED: status_set_playmode(STATUS_STOP); usb_screen();#ifdef HAVE_LCD_CHARCELLS status_set_param(true);#endif return true; } } return true; }}/* ----------------------------------------------------------------------- *//* This function loads the bookmark information into the resume memory. *//* This is an interface function. *//* ------------------------------------------------------------------------*/bool bookmark_load(char* file, bool autoload){ int fd; bool success = true; int offset; int seed; int index; char* bookmark = NULL;; if(autoload) { fd = open(file, O_RDONLY); if(fd >= 0) { if(read_line(fd, global_read_buffer, sizeof(global_read_buffer))) bookmark=global_read_buffer; close(fd); } } else { /* This is not an auto-load, so list the bookmarks */ bookmark=select_bookmark(file); if(!bookmark) return true; /* User exited without selecting a bookmark */ } if(bookmark) { success = parse_bookmark(bookmark, &index, &offset, &seed, NULL, global_temp_buffer, sizeof(global_temp_buffer), NULL, &global_settings.repeat_mode, &global_settings.playlist_shuffle, NULL, 0); } if(success) bookmark_play(global_temp_buffer,index,offset,seed); return success;}static int get_bookmark_count(char* bookmark_file_name){ int read_count = 0; int file = open(bookmark_file_name, O_RDONLY); if(file < 0) return -1; /* Get the requested bookmark */ while(read_line(file, global_read_buffer, sizeof(global_read_buffer))) { if(check_bookmark(global_read_buffer)) read_count++; } close(file); return read_count; }/* ----------------------------------------------------------------------- *//* This displays a the bookmarks in a file and allows the user to *//* select one to play. *//* ------------------------------------------------------------------------*/static char* select_bookmark(char* bookmark_file_name){ int bookmark_id = 0; bool delete_this_bookmark = true; int key = 0; char* bookmark; int bookmark_count = 0; while(true) { /* Handles the case where the user wants to go below the 0th bookmark */ if(bookmark_id < 0) bookmark_id = 0; if(delete_this_bookmark) { bookmark_count = get_bookmark_count(bookmark_file_name); delete_this_bookmark = false; } bookmark = get_bookmark(bookmark_file_name, bookmark_id); if (!bookmark) { /* if there were no bookmarks in the file, delete the file and exit. */ if(bookmark_id == 0) { splash(HZ, true, str(LANG_BOOKMARK_LOAD_EMPTY)); remove(bookmark_file_name); while (button_get(false)); /* clear button queue */ return NULL; } else { bookmark_id--; } } else { display_bookmark(bookmark, bookmark_id, bookmark_count); } /* waiting for the user to click a button */ while (button_get(false)); /* clear button queue */ key = button_get(true); switch(key) { case BUTTON_PLAY: /* User wants to use this bookmark */ return bookmark; case BUTTON_ON | BUTTON_PLAY: /* User wants to delete this bookmark */ delete_this_bookmark = true; break; case SYS_USB_CONNECTED: usb_screen();#ifdef HAVE_LCD_CHARCELLS status_set_param(true);#endif return NULL;#ifdef HAVE_RECORDER_KEYPAD case BUTTON_UP: bookmark_id--; break; case BUTTON_DOWN: bookmark_id++; break; case BUTTON_LEFT: case BUTTON_OFF: return NULL;#else case BUTTON_LEFT: bookmark_id--; break; case BUTTON_RIGHT: bookmark_id++; break; case BUTTON_STOP: return NULL;#endif } if (delete_this_bookmark) { delete_bookmark(bookmark_file_name, bookmark_id); bookmark_id--; } } return NULL;}/* ----------------------------------------------------------------------- *//* This function takes a location in a bookmark file and deletes that *//* bookmark. *//* ------------------------------------------------------------------------*/static bool delete_bookmark(char* bookmark_file_name, int bookmark_id){ int temp_bookmark_file = 0; int bookmark_file = 0; int bookmark_count = 0; /* Opening up a temp bookmark file */ snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s.tmp", bookmark_file_name); temp_bookmark_file = open(global_temp_buffer, O_WRONLY | O_CREAT | O_TRUNC); bookmark_file = open(bookmark_file_name, O_RDONLY); if (temp_bookmark_file < 0 || bookmark_file < 0) return false; /* can't open one of the files */ /* Reading in the previous bookmarks and writing them to the temp file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -