⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookmark.c

📁 编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统引导 Boot、FLASH Driver等内容的
💻 C
📖 第 1 页 / 共 3 页
字号:
 /*************************************************************************** *             __________               __   ___. *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  / *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  < *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \ *                     \/            \/     \/    \/            \/ * * Copyright (C) 2003 by Benjamin Metzler * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdbool.h>#include "applimits.h"#include "lcd.h"#include "button.h"#include "usb.h"#include "mpeg.h"#include "wps.h"#include "settings.h"#include "bookmark.h"#include "dir.h"#include "status.h"#include "system.h"#include "errno.h"#include "icons.h"#include "atoi.h"#include "string.h"#include "menu.h"#include "lang.h"#include "screens.h"#include "status.h"#include "debug.h"#include "kernel.h"#include "sprintf.h"#define MAX_BOOKMARKS 10#define MAX_BOOKMARK_SIZE  350#define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"static bool  add_bookmark(char* bookmark_file_name, char* bookmark);static bool  bookmark_load_menu(void);static bool  check_bookmark(char* bookmark);static char* create_bookmark(void);static bool  delete_bookmark(char* bookmark_file_name, int bookmark_id);static void  display_bookmark(char* bookmark,                              int bookmark_id,                               int bookmark_count);static bool  generate_bookmark_file_name(char *in,                                         char *out,                                         unsigned int max_length);static char* get_bookmark(char* bookmark_file, int bookmark_count);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);static char* select_bookmark(char* bookmark_file_name);static bool  system_check(void);static bool  write_bookmark(bool create_bookmark_file);static int   get_bookmark_count(char* bookmark_file_name);static char global_temp_buffer[MAX_PATH+1];static char global_bookmark_file_name[MAX_PATH];static char global_read_buffer[MAX_BOOKMARK_SIZE];static char global_bookmark[MAX_BOOKMARK_SIZE];/* ----------------------------------------------------------------------- *//* Displays the bookmark menu options for the user to decide.  This is an  *//* interface function.                                                     *//* ----------------------------------------------------------------------- */bool bookmark_menu(void){    int m;    bool result;    struct menu_items items[] = {        { str(LANG_BOOKMARK_MENU_CREATE), bookmark_create_menu},        { str(LANG_BOOKMARK_MENU_LIST), bookmark_load_menu},        { str(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS), bookmark_mrb_load},    };    m=menu_init( items, sizeof items / sizeof(struct menu_items) );#ifdef HAVE_LCD_CHARCELLS    status_set_param(true);#endif    result = menu_run(m);#ifdef HAVE_LCD_CHARCELLS    status_set_param(false);#endif    menu_exit(m);    settings_save();    return result;}/* ----------------------------------------------------------------------- *//* This is the interface function from the main menu.                      *//* ----------------------------------------------------------------------- */bool bookmark_create_menu(void){    write_bookmark(true);    return false;}/* ----------------------------------------------------------------------- *//* This function acts as the load interface from the main menu             *//* This function determines the bookmark file name and then loads that file*//* for the user.  The user can then select a bookmark to load.             *//* If no file/directory is currently playing, the menu item does not work. *//* ----------------------------------------------------------------------- */static bool bookmark_load_menu(void){    bool success = true;    int  offset;    int  seed;    int  index;    char* bookmark;    if(!system_check())        return false;    else    {        char* name = playlist_get_name(NULL, global_temp_buffer,                                       sizeof(global_temp_buffer));        if (generate_bookmark_file_name(name,                                        global_bookmark_file_name,                                        sizeof(global_bookmark_file_name)))        {            bookmark = select_bookmark(global_bookmark_file_name);            if (!bookmark)                return false;  /* User exited without selecting a 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);        }        else        {            /* something bad happened while creating bookmark name*/            success = false;        }        if (success)            bookmark_play(global_temp_buffer, index, offset, seed);    }    return success;}/* ----------------------------------------------------------------------- *//* Gives the user a list of the Most Recent Bookmarks.  This is an         *//* interface function                                                      *//* ----------------------------------------------------------------------- */bool bookmark_mrb_load(){    bool success = true;    int  offset;    int  seed;    int  index;    char* bookmark;    bookmark = select_bookmark(RECENT_BOOKMARK_FILE);    if (!bookmark)        return false;  /* User exited without selecting a 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;}/* ----------------------------------------------------------------------- *//* This function handles an autobookmark creation.  This is an interface   *//* function.                                                               *//* ----------------------------------------------------------------------- */bool bookmark_autobookmark(void){    /* prompts the user as to create a bookmark */    bool done = false;    int  key = 0;    if (!system_check())        return false;    mpeg_pause();    /* first pause playback */    switch (global_settings.autocreatebookmark)    {        case BOOKMARK_YES:            return write_bookmark(true);        case BOOKMARK_NO:            return false;        case BOOKMARK_RECENT_ONLY_YES:            return write_bookmark(false);    }    /* Prompting user to confirm bookmark creation */    lcd_clear_display();#ifdef HAVE_LCD_BITMAP    lcd_puts(0,0, str(LANG_AUTO_BOOKMARK_QUERY));    lcd_puts(0,1, str(LANG_CONFIRM_WITH_PLAY_RECORDER));    lcd_puts(0,2, str(LANG_CANCEL_WITH_ANY_RECORDER));#else    status_draw(false);    lcd_puts(0,0, str(LANG_AUTO_BOOKMARK_QUERY));    lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER));#endif    lcd_update();    while (!done)    {        /* Wait for a key to be pushed */        key = button_get(true);        switch (key)        {            case BUTTON_DOWN | BUTTON_REL:            case BUTTON_ON | BUTTON_REL:#ifdef HAVE_RECORDER_KEYPAD            case BUTTON_OFF | BUTTON_REL:            case BUTTON_RIGHT | BUTTON_REL:            case BUTTON_UP | BUTTON_REL:#endif            case BUTTON_LEFT | BUTTON_REL:                done = true;                break;            case BUTTON_PLAY | BUTTON_REL:                if (global_settings.autocreatebookmark ==                    BOOKMARK_RECENT_ONLY_ASK)                    write_bookmark(false);                else                    write_bookmark(true);                done = true;                break;            case SYS_USB_CONNECTED:                usb_screen();#ifdef HAVE_LCD_CHARCELLS                status_set_param(true);#endif                return false;        }    }    return true;}/* ----------------------------------------------------------------------- *//* This function takes the current current resume information and writes   *//* that to the beginning of the bookmark file.                             *//* This file will contain N number of bookmarks in the following format:   *//* resume_index*resume_offset*resume_seed*resume_first_index*              *//* resume_file*milliseconds*MP3 Title*                                     *//* ------------------------------------------------------------------------*/static bool write_bookmark(bool create_bookmark_file){    bool   success=false;    char*  bookmark;    if (!system_check())       return false; /* something didn't happen correctly, do nothing */    bookmark = create_bookmark();    if (!bookmark)       return false; /* something didn't happen correctly, do nothing */    if (global_settings.usemrb)        success = add_bookmark(RECENT_BOOKMARK_FILE, bookmark);    /* writing the bookmark */    if (create_bookmark_file)    {        char* name = playlist_get_name(NULL, global_temp_buffer,                                       sizeof(global_temp_buffer));        if (generate_bookmark_file_name(name,                                        global_bookmark_file_name,                                        sizeof(global_bookmark_file_name)))        {            success = add_bookmark(global_bookmark_file_name, bookmark);        }    }    if (success)        splash(HZ, true, str(LANG_BOOKMARK_CREATE_SUCCESS));    else        splash(HZ, true, str(LANG_BOOKMARK_CREATE_FAILURE));    return true;}/* ----------------------------------------------------------------------- *//* This function adds a bookmark to a file.                                *//* ------------------------------------------------------------------------*/static bool add_bookmark(char* bookmark_file_name, char* bookmark){    int    temp_bookmark_file = 0;    int    bookmark_file = 0;    int    bookmark_count = 0;    char*  playlist = NULL;    char*  cp;    int    len = 0;    bool   unique = false;    /* 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);    if (temp_bookmark_file < 0)        return false; /* can't open the temp file */    if (!strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE) &&        (global_settings.usemrb == BOOKMARK_UNIQUE_ONLY))    {        playlist = strchr(bookmark,'/');        cp = strrchr(bookmark,';');        len = cp - playlist;        unique = true;    }    /* Writing the new bookmark to the begining of the temp file */    write(temp_bookmark_file, bookmark, strlen(bookmark));    write(temp_bookmark_file, "\n", 1);    bookmark_count++;    /* Reading in the previous bookmarks and writing them to the temp file */    bookmark_file = open(bookmark_file_name, O_RDONLY);    if (bookmark_file >= 0)    {        while (read_line(bookmark_file, global_read_buffer,                         sizeof(global_read_buffer)))        {            /* The MRB has a max of MAX_BOOKMARKS in it */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -