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

📄 directory.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * directory.c: expands a directory (directory: access plug-in) ***************************************************************************** * Copyright (C) 2002-2007 the VideoLAN team * $Id$ * * Authors: Derk-Jan Hartman <hartman at videolan dot org> *          Rémi Denis-Courmont * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <assert.h>#include <vlc_common.h>#include <vlc_plugin.h>#warning playlist code must not be used here.#include <vlc_playlist.h>#include <vlc_input.h>#include <vlc_access.h>#include <vlc_demux.h>#ifdef HAVE_SYS_TYPES_H#   include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H#   include <sys/stat.h>#endif#ifdef HAVE_ERRNO_H#   include <errno.h>#endif#ifdef HAVE_FCNTL_H#   include <fcntl.h>#endif#ifdef HAVE_UNISTD_H#   include <unistd.h>#elif defined( WIN32 ) && !defined( UNDER_CE )#   include <io.h>#elif defined( UNDER_CE )#   define strcoll strcmp#endif#ifdef HAVE_DIRENT_H#   include <dirent.h>#endif#include <vlc_charset.h>/***************************************************************************** * Module descriptor *****************************************************************************/static int  Open ( vlc_object_t * );static void Close( vlc_object_t * );static int  DemuxOpen ( vlc_object_t * );#define RECURSIVE_TEXT N_("Subdirectory behavior")#define RECURSIVE_LONGTEXT N_( \        "Select whether subdirectories must be expanded.\n" \        "none: subdirectories do not appear in the playlist.\n" \        "collapse: subdirectories appear but are expanded on first play.\n" \        "expand: all subdirectories are expanded.\n" )static const char *const psz_recursive_list[] = { "none", "collapse", "expand" };static const char *const psz_recursive_list_text[] = {    N_("none"), N_("collapse"), N_("expand") };#define IGNORE_TEXT N_("Ignored extensions")#define IGNORE_LONGTEXT N_( \        "Files with these extensions will not be added to playlist when " \        "opening a directory.\n" \        "This is useful if you add directories that contain playlist files " \        "for instance. Use a comma-separated list of extensions." )vlc_module_begin();    set_category( CAT_INPUT );    set_shortname( N_("Directory" ) );    set_subcategory( SUBCAT_INPUT_ACCESS );    set_description( N_("Standard filesystem directory input") );    set_capability( "access", 55 );    add_shortcut( "directory" );    add_shortcut( "dir" );    add_shortcut( "file" );    add_string( "recursive", "expand" , NULL, RECURSIVE_TEXT,                RECURSIVE_LONGTEXT, false );      change_string_list( psz_recursive_list, psz_recursive_list_text, 0 );    add_string( "ignore-filetypes", "m3u,db,nfo,jpg,gif,sfv,txt,sub,idx,srt,cue",                NULL, IGNORE_TEXT, IGNORE_LONGTEXT, false );    set_callbacks( Open, Close );    add_submodule();        set_description( "Directory EOF");        set_capability( "demux", 0 );        set_callbacks( DemuxOpen, NULL );vlc_module_end();/***************************************************************************** * Local prototypes, constants, structures *****************************************************************************/enum{    MODE_EXPAND,    MODE_COLLAPSE,    MODE_NONE};typedef struct stat_list_t stat_list_t;static ssize_t Read( access_t *, uint8_t *, size_t );static ssize_t ReadNull( access_t *, uint8_t *, size_t );static int Control( access_t *, int, va_list );static int Demux( demux_t *p_demux );static int DemuxControl( demux_t *p_demux, int i_query, va_list args );static int ReadDir( access_t *, playlist_t *, const char *psz_name,                    int i_mode, playlist_item_t *, input_item_t *,                    DIR *handle, stat_list_t *stats );static DIR *OpenDir (vlc_object_t *obj, const char *psz_name);/***************************************************************************** * Open: open the directory *****************************************************************************/static int Open( vlc_object_t *p_this ){    access_t *p_access = (access_t*)p_this;    if( !p_access->psz_path )        return VLC_EGENERIC;    struct stat st;    if( !stat( p_access->psz_path, &st ) && !S_ISDIR( st.st_mode ) )        return VLC_EGENERIC;    DIR *handle = OpenDir (p_this, p_access->psz_path);    if (handle == NULL)        return VLC_EGENERIC;    p_access->p_sys = (access_sys_t *)handle;    p_access->pf_read  = Read;    p_access->pf_block = NULL;    p_access->pf_seek  = NULL;    p_access->pf_control= Control;    /* Force a demux */    free( p_access->psz_demux );    p_access->psz_demux = strdup( "directory" );    return VLC_SUCCESS;}/***************************************************************************** * Close: close the target *****************************************************************************/static void Close( vlc_object_t * p_this ){    access_t *p_access = (access_t*)p_this;    DIR *handle = (DIR *)p_access->p_sys;    closedir (handle);}/***************************************************************************** * ReadNull: read the directory *****************************************************************************/static ssize_t ReadNull( access_t *p_access, uint8_t *p_buffer, size_t i_len){    (void)p_access;    /* Return fake data */    memset( p_buffer, 0, i_len );    return i_len;}/***************************************************************************** * Read: read the directory *****************************************************************************/static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len){    (void)p_buffer;    (void)i_len;    char               *psz;    int                 i_mode;    char               *psz_name = strdup( p_access->psz_path );    if( psz_name == NULL )        return VLC_ENOMEM;    playlist_t         *p_playlist = pl_Yield( p_access );    input_thread_t     *p_input = (input_thread_t*)vlc_object_find( p_access, VLC_OBJECT_INPUT, FIND_PARENT );    playlist_item_t    *p_item_in_category;    input_item_t       *p_current_input;    playlist_item_t    *p_current;    if( !p_input )    {        msg_Err( p_access, "unable to find input (internal error)" );        free( psz_name );        pl_Release( p_access );        return VLC_ENOOBJ;    }    p_current_input = input_GetItem( p_input );    p_current = playlist_ItemGetByInput( p_playlist, p_current_input, pl_Unlocked );    if( !p_current )    {        msg_Err( p_access, "unable to find item in playlist" );        vlc_object_release( p_input );        free( psz_name );        pl_Release( p_access );        return VLC_ENOOBJ;    }    /* Remove the ending '/' char */    if( psz_name[0] )    {        char *ptr = psz_name + strlen (psz_name);        switch (*--ptr)        {            case '/':            case '\\':                *ptr = '\0';        }    }    /* Handle mode */    psz = var_CreateGetString( p_access, "recursive" );    if( *psz == '\0' || !strncmp( psz, "none" , 4 )  )        i_mode = MODE_NONE;    else if( !strncmp( psz, "collapse", 8 )  )        i_mode = MODE_COLLAPSE;    else        i_mode = MODE_EXPAND;    free( psz );    p_current->p_input->i_type = ITEM_TYPE_DIRECTORY;    p_item_in_category = playlist_ItemToNode( p_playlist, p_current,                                              pl_Unlocked );    assert( p_item_in_category );    ReadDir( p_access, p_playlist, psz_name, i_mode,             p_item_in_category,             p_current_input, (DIR *)p_access->p_sys, NULL );    playlist_Signal( p_playlist );    free( psz_name );    vlc_object_release( p_input );    pl_Release( p_access );    /* Return fake data forever */    p_access->pf_read = ReadNull;    return -1;}/***************************************************************************** * Control: *****************************************************************************/static int Control( access_t *p_access, int i_query, va_list args ){    bool   *pb_bool;    int          *pi_int;    int64_t      *pi_64;    switch( i_query )    {        /* */        case ACCESS_CAN_SEEK:        case ACCESS_CAN_FASTSEEK:        case ACCESS_CAN_PAUSE:        case ACCESS_CAN_CONTROL_PACE:

⌨️ 快捷键说明

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