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

📄 tree.c

📁 编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统引导 Boot、FLASH Driver等内容的
💻 C
📖 第 1 页 / 共 4 页
字号:
                                update_all = true;                                put_cursorxy(CURSOR_X, CURSOR_Y +                                             tree_max_on_screen - 1, true);                            }                        }                    }                    need_update = true;                }                break;            case TREE_NEXT:            case TREE_NEXT | BUTTON_REPEAT:#ifdef BUTTON_RC_RIGHT            case BUTTON_RC_RIGHT:#endif                if(filesindir)                {                    if (dircursor + dirstart + 1 < numentries ) {                        if(dircursor+1 < tree_max_on_screen) {                            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, false);                            dircursor++;                            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);                        }                        else {                            dirstart++;                            numentries = showdir(currdir, dirstart, dirfilter);                            update_all = true;                            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);                        }                    }                    else {                        if(numentries < tree_max_on_screen) {                            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, false);                            dirstart = dircursor = 0;                            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);                        }                        else {                            dirstart = dircursor = 0;                            numentries = showdir(currdir, dirstart, dirfilter);                            update_all=true;                            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);                        }                    }                    need_update = true;                }                break;            case TREE_MENU:                if (*dirfilter < NUM_FILTER_MODES)                {                    lcd_stop_scroll();                    if (main_menu())                        reload_root = true;                    restore = true;                }                break;#ifdef BUTTON_ON /* I bet the folks without ON-button want this to                    work on a different button */            case BUTTON_ON:                if (handle_on(&dirstart, &dircursor, numentries,                              tree_max_on_screen, dirfilter))                {                    /* start scroll */                    restore = true;                }                else                {                    if (mpeg_status() & MPEG_STATUS_PLAY)                    {                        start_wps=true;                    }                    else                    {                        start_resume(false);                        restore = true;                    }                }                break;#endif#ifdef HAVE_RECORDER_KEYPAD            case BUTTON_F2:                if (*dirfilter < NUM_FILTER_MODES)                {                    if (f2_screen())                        reload_root = true;                    restore = true;                    break;                }            case BUTTON_F3:                if (*dirfilter < NUM_FILTER_MODES)                {                    if (f3_screen())                        reload_root = true;#ifdef HAVE_LCD_BITMAP                    tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;#endif                    restore = true;                }                break;#endif            case SYS_USB_CONNECTED:                status_set_playmode(STATUS_STOP);                usb_screen();                reload_root = true;                break;            case BUTTON_NONE:                status_draw(false);                break;        }        if ( button )            ata_spin();        if (start_wps)	{            lcd_stop_scroll();            if (wps_show() == SYS_USB_CONNECTED)                reload_root = true;#ifdef HAVE_LCD_BITMAP            tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;#endif            restore = true;            start_wps=false;        }        /* do we need to rescan dir? */        if (reload_dir || reload_root ||            lastfilter != *dirfilter ||            lastsortcase != global_settings.sort_case)        {            if ( reload_root ) {                strcpy(currdir, "/");                dirlevel = 0;                reload_root = false;            }            if (! reload_dir )            {                dircursor = 0;                dirstart = 0;                lastdir[0] = 0;            }            lastfilter = *dirfilter;            lastsortcase = global_settings.sort_case;            restore = true;            while (button_get(false)); /* clear button queue */        }        if (exit_func)            break;        if (restore || reload_dir) {            /* restore display */            /* We need to adjust if the number of lines on screen have               changed because of a status bar change */            if(CURSOR_Y+LINE_Y+dircursor>tree_max_on_screen) {                dirstart++;                dircursor--;            }#ifdef HAVE_LCD_BITMAP            /* the sub-screen might've ruined the margins */            lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and                                                  icon */            lcd_setfont(FONT_UI);#endif            numentries = showdir(currdir, dirstart, dirfilter);            update_all = true;            put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);            need_update = true;            reload_dir = false;        }        if ( numentries && need_update) {            i = dirstart+dircursor;            /* if MP3 filter is on, cut off the extension */            if(lasti!=i || restore) {                lcd_stop_scroll();                /* So if lastdircursor and dircursor differ, and then full                   screen was not refreshed, restore the previous line */                if ((lastdircursor != dircursor) && !update_all ) {                    showfileline(lastdircursor, lasti, false, dirfilter); /* no scroll */                }                lasti=i;                lastdircursor=dircursor;                showfileline(dircursor, i, true, dirfilter); /* scroll please */                need_update = true;            }        }        if(need_update) {            lcd_update();            need_update = false;            update_all = false;        }    }    return true;}static int plsize = 0;static bool add_dir(char* dirname, int fd){    bool abort = false;    char buf[MAX_PATH/2]; /* saving a little stack... */    DIR* dir;    /* check for user abort */#ifdef BUTTON_STOP    if (button_get(false) == BUTTON_STOP)#else    if (button_get(false) == BUTTON_OFF)#endif        return true;    dir = opendir(dirname);    if(!dir)        return true;    while (true) {        struct dirent *entry;        entry = readdir(dir);        if (!entry)            break;        if (entry->attribute & ATTR_DIRECTORY) {            if (!strcmp(entry->d_name, ".") ||                !strcmp(entry->d_name, ".."))                continue;            if (dirname[1])                snprintf(buf, sizeof buf, "%s/%s", dirname, entry->d_name);            else                snprintf(buf, sizeof buf, "/%s", entry->d_name);            if (add_dir(buf,fd)) {                abort = true;                break;            }        }        else {            int x = strlen(entry->d_name);            if ((!strcasecmp(&entry->d_name[x-4], ".mp3")) ||                (!strcasecmp(&entry->d_name[x-4], ".mp2")) ||                (!strcasecmp(&entry->d_name[x-4], ".mpa")))            {                write(fd, dirname, strlen(dirname));                write(fd, "/", 1);                write(fd, entry->d_name, x);                write(fd, "\n", 1);                plsize++;                snprintf(buf, sizeof buf, "%d", plsize);#ifdef HAVE_LCD_BITMAP                lcd_puts(0,4,buf);                lcd_update();#else                x = 10;                if (plsize > 999)                    x=7;                else {                    if (plsize > 99)                        x=8;                    else {                        if (plsize > 9)                            x=9;                    }                }                lcd_puts(x,0,buf);#endif            }        }    }    closedir(dir);    return abort;}bool create_playlist(void){    int fd;    char filename[MAX_PATH];    snprintf(filename, sizeof filename, "%s.m3u",             currdir[1] ? currdir : "/root");    lcd_clear_display();    lcd_puts(0,0,str(LANG_CREATING));    lcd_puts_scroll(0,1,filename);    lcd_update();    fd = creat(filename,0);    if (fd < 0)        return false;    plsize = 0;    add_dir(currdir[1] ? currdir : "/", fd);    close(fd);    sleep(HZ);    return true;}bool rockbox_browse(char *root, int dirfilter){    bool rc;    int dircursor_save = dircursor;    int dirstart_save = dirstart;    int dirlevel_save = dirlevel;    int dirpos_save = dirpos[0];    int cursorpos_save = cursorpos[0];    memcpy(currdir_save, currdir, sizeof(currdir));    reload_dir = true;    start_wps = false;    rc = dirbrowse(root, &dirfilter);    memcpy(currdir, currdir_save, sizeof(currdir));    reload_dir = true;    dirstart = dirstart_save;    cursorpos[0] = cursorpos_save;    dirlevel = dirlevel_save;    dircursor = dircursor_save;    dirpos[0] = dirpos_save;    return false;}void tree_init(void){    /* We copy the settings value in case it is changed by the user. We can't       use it until the next reboot. */    max_files_in_dir = global_settings.max_files_in_dir;    name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files_in_dir;    name_buffer = buffer_alloc(name_buffer_size);    dircache = buffer_alloc(max_files_in_dir * sizeof(struct entry));}void bookmark_play(char *resume_file, int index, int offset, int seed){    int len=strlen(resume_file);    if (!strcasecmp(&resume_file[len-4], ".m3u"))    {        char* slash;        // check that the file exists        int fd = open(resume_file, O_RDONLY);        if(fd<0)            return;        close(fd);        slash = strrchr(resume_file,'/');        if (slash)        {            char* cp;            *slash=0;            cp=resume_file;            if (!cp[0])                cp="/";            if (playlist_create(cp, slash+1) != -1)            {                if (global_settings.playlist_shuffle)                    playlist_shuffle(seed, -1);                playlist_start(index,offset);            }            *slash='/';        }    }    else    {        lastdir[0]='\0';        if (playlist_create(resume_file, NULL) != -1)        {            resume_directory(resume_file);            if (global_settings.playlist_shuffle)                playlist_shuffle(seed, -1);            playlist_start(index,offset);        }    }    status_set_playmode(STATUS_PLAY);    start_wps=true;}

⌨️ 快捷键说明

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