/*! * Load file list in some folder */ static RET_CODE _ui_video_m_get_file_list(u16 *p_path) { u16 *p_name_filter = NULL; flist_dir_t flist_dir = NULL; /*! * Free last time dir and list first */ p_name_filter = mtos_malloc(sizeof(u16) *(strlen(p_g_name_filter) + 1)); str_asc2uni(p_g_name_filter, p_name_filter); flist_dir = file_list_enter_dir(p_name_filter, MAX_FILE_COUNT, p_path); mtos_free(p_name_filter); if(NULL == flist_dir) { UI_VIDEO_PRINF("[%s]: ##ERR## file list null\n", __FUNCTION__); return ERR_FAILURE; } _ui_video_m_free_dir_and_list(); g_video_m.flist_dir = flist_dir; file_list_get(g_video_m.flist_dir, FLIST_UNIT_FIRST, &g_video_m.file_list); /*! * Set default sort as a-z mode */ file_list_sort(&g_video_m.file_list, g_video_m.file_list.file_count, A_Z_MODE); return SUCCESS; }
/*! * Load video subtitle file */ RET_CODE ui_video_m_load_subt(u16 *p_name) { u16 *p_cur_path = NULL; u16 *p_filter = NULL; if(NULL == p_name || (strlen((void *)p_name) == 0)) { UI_VIDEO_PRINF("[%s]: ##ERR## cur name null\n", __FUNCTION__); return ERR_FAILURE; } /*! * Subtitle files in current playing video path will be loaded */ p_cur_path = ui_video_m_get_cur_path(); if(NULL == p_cur_path) { UI_VIDEO_PRINF("[%s]: ##ERR## cur path null\n", __FUNCTION__); return ERR_FAILURE; } UI_VIDEO_PRINF("[%s]: p_cur_path = %s\n", __FUNCTION__, p_cur_path); /*! * Free dir and list first */ _ui_video_m_free_subt_dir_and_list(); p_filter = mtos_malloc(sizeof(u16) * (strlen(p_g_subt_filter) + 1)); str_asc2uni(p_g_subt_filter, p_filter); g_video_m.subt_dir = file_list_enter_dir(p_filter, MAX_FILE_COUNT, p_cur_path); mtos_free(p_filter); if(NULL == g_video_m.subt_dir) { return ERR_FAILURE; } file_list_get(g_video_m.subt_dir, FLIST_UNIT_FIRST, &g_video_m.subt_list); file_list_sort(&g_video_m.subt_list, g_video_m.subt_list.file_count, A_Z_MODE); /*! * Save subtitle by playing file name */ _ui_video_m_save_subt_lang(p_name); return SUCCESS; }
static struct file_list *file_list_read_nolfn(const char *path, const char *pattern) { char *cwd = ioutil_current_dir(); struct file_list *fl = NULL; struct find_t f; if (cwd == NULL) { return NULL; } if (ioutil_chdir(path) < 0) { goto end; } if (_dos_findfirst("*.*", (_A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR | _A_ARCH), &f)) { goto end; } fl = file_list_create(); /* (We skip `.' here.) */ while (!_dos_findnext(&f)) { strlwr(f.name); if (pattern == NULL || (f.attrib & _A_SUBDIR)) { file_list_add_item(fl, f.name, (f.attrib & _A_SUBDIR) ? FT_DIR : FT_NORMAL); continue; } { char *p = lib_stralloc(pattern); char *element; element = strtok(p, ";"); do { if (fnmatch(element, f.name, FNM_NOCASE) == 0) { file_list_add_item(fl, f.name, (f.attrib & _A_SUBDIR) ? FT_DIR : FT_NORMAL); } element = strtok(NULL, ";"); } while (element != NULL); lib_free(p); } } file_list_sort(fl); end: ioutil_chdir(cwd); return fl; }
/* XXX: Assumes `path' ends with a slash. */ static struct file_list *file_list_read_lfn(const char *path, const char *pattern) { struct dirent *d; struct file_list *fl; DIR *ds; int pathlen = strlen(path); if (path == NULL || *path == '\0') { ds = opendir("."); } else { ds = opendir(path); } if (ds == NULL) { return NULL; } fl = file_list_create(); /* Skip ".". */ readdir(ds); { unsigned short old_djstat = _djstat_flags; /* This makes `stat()' faster. FIXME: but it's still too slow imo... */ _djstat_flags = (_STAT_INODE | _STAT_EXEC_EXT | _STAT_EXEC_MAGIC | _STAT_DIRSIZE | _STAT_ROOT_TIME | _STAT_WRITEBIT); while ((d = readdir(ds)) != NULL) { struct stat s; int type; /* Warning: Assumes `path' has a trailing '/'. */ char *name = alloca(d->d_namlen + pathlen + 1); memcpy(name, path, pathlen); strcpy(name + pathlen, d->d_name); if (stat(name, &s) != -1) { type = S_ISDIR(s.st_mode) ? FT_DIR : FT_NORMAL; if (pattern == NULL || type == FT_DIR) { file_list_add_item(fl, d->d_name, type); continue; } { char *p = lib_stralloc(pattern); char *element; element = strtok(p, ";"); do { if (fnmatch(element, d->d_name, FNM_NOCASE) == 0) { file_list_add_item(fl, d->d_name, type); } element = strtok(NULL, ";"); } while (element != NULL); lib_free(p); } } } _djstat_flags = old_djstat; } file_list_sort(fl); closedir(ds); return fl; }