static int ntfs_scandir(fa_protocol_t *fap, fa_dir_t *fd, const char *url, char *errbuf, size_t errlen, int flags) { DIR_ITER *di = ps3ntfs_diropen(url); char filename[1024]; char buf[URL_MAX]; struct stat st; int type; while(1) { if(ps3ntfs_dirnext(di, filename, &st)) break; switch(st.st_mode & S_IFMT) { case S_IFDIR: type = CONTENT_DIR; break; case S_IFREG: type = CONTENT_FILE; break; default: continue; } fs_urlsnprintf(buf, sizeof(buf), "", url, filename); fa_dir_add(fd, buf, filename, type); } ps3ntfs_dirclose(di); return 0; }
static int sidfile_scandir(fa_dir_t *fd, const char *url, char *errbuf, size_t errlen) { void *fh = NULL; char *p, *fpath = mystrdupa(url); char buf[128]; char name[32]; char turl[URL_MAX]; int tracks, i; fa_dir_entry_t *fde; rstr_t *album, *artist; if((p = strrchr(fpath, '/')) == NULL) { snprintf(errbuf, errlen, "Invalid filename"); return -1; } *p = 0; if((fh = fa_open(fpath, errbuf, errlen)) == NULL) return -1; if(fa_read(fh, buf, 128) != 128) { snprintf(errbuf, errlen, "Unable to read file"); fa_close(fh); return -1; } album = rstr_alloc(utf8_from_bytes((char *)buf + 0x16, 32, NULL)); artist = rstr_alloc(utf8_from_bytes((char *)buf + 0x36, 32, NULL)); tracks = buf[0xf]; for(i = 0; i < tracks; i++) { snprintf(name, sizeof(name), "Track %02d", i + 1); snprintf(turl, sizeof(turl), "sidplayer:%s/%d", fpath, i + 1); fde = fa_dir_add(fd, turl, name, CONTENT_AUDIO); fde->fde_probestatus = FDE_PROBE_DEEP; fde->fde_metadata = prop_create_root("metadata"); prop_set_string(prop_create(fde->fde_metadata, "title"), name); prop_set_rstring(prop_create(fde->fde_metadata, "album"), album); prop_set_rstring(prop_create(fde->fde_metadata, "artist"), artist); } rstr_release(album); rstr_release(artist); fa_close(fh); return 0; }
static int fs_scandir(fa_protocol_t *fap, fa_dir_t *fd, const char *url, char *errbuf, size_t errlen) { char buf[URL_MAX]; struct stat st; struct dirent *d; int type; DIR *dir; int split_num; if((dir = opendir(url)) == NULL) { snprintf(errbuf, errlen, "%s", strerror(errno)); return -1; } while((d = readdir(dir)) != NULL) { fs_urlsnprintf(buf, sizeof(buf), "", url, d->d_name); if(stat(buf, &st)) continue; switch(st.st_mode & S_IFMT) { case S_IFDIR: type = CONTENT_DIR; break; case S_IFREG: type = CONTENT_FILE; if((split_num = is_splitted_file_name(d->d_name)) > 0) { if(split_num != 1) continue; // Strip off last part (.00x) of filename buf[strlen(buf) - 4] = 0; d->d_name[strlen(d->d_name) - 4] = 0; } break; default: continue; } fs_urlsnprintf(buf, sizeof(buf), "file://", url, d->d_name); fa_dir_add(fd, buf, d->d_name, type); } closedir(dir); return 0; }
static int gmefile_scandir(fa_dir_t *fd, const char *url, char *errbuf, size_t errlen) { char *p, *fpath = mystrdupa(url); char name[32]; char turl[URL_MAX]; int tracks, i; fa_dir_entry_t *fde; const char *title; Music_Emu *emu; gme_info_t *info; gme_err_t err; if((p = strrchr(fpath, '/')) == NULL) { snprintf(errbuf, errlen, "Invalid filename"); return -1; } *p = 0; buf_t *b; if((b = fa_load(fpath, NULL, errbuf, errlen, NULL, 0, NULL, NULL)) == NULL) return -1; err = gme_open_data(b->b_ptr, b->b_size, &emu, gme_info_only); buf_release(b); if(err != NULL) return 0; tracks = gme_track_count(emu); for(i = 0; i < tracks; i++) { snprintf(turl, sizeof(turl), "gmeplayer:%s/%d", fpath, i + 1); err = gme_track_info(emu, &info, i); if(err == NULL && info->song[0]) { title = info->song; } else { snprintf(name, sizeof(name), "Track %02d", i + 1); title = name; } fde = fa_dir_add(fd, turl, title, CONTENT_AUDIO); fde->fde_probestatus = FDE_PROBE_DEEP; fde->fde_metadata = prop_create_root("metadata"); prop_set_string(prop_create(fde->fde_metadata, "title"), title); if(err == NULL) { if(info->game[0]) prop_set_string(prop_create(fde->fde_metadata, "album"), info->game); if(info->author[0]) prop_set_string(prop_create(fde->fde_metadata, "artist"), info->author); prop_set_float(prop_create(fde->fde_metadata, "duration"), info->play_length / 1000.0); gme_free_info(info); } } gme_delete(emu); return 0; }
static int b_scandir(fa_dir_t *fd, const char *url, char *errbuf, size_t errlen) { fa_dir_entry_t *fde; struct filebundle *fb; char buf[PATH_MAX]; char buf2[PATH_MAX]; const struct filebundle_entry *fbe; const char *u, *u2; char *s; int ok = 0; if(*url == 0) { if(fd != NULL) { for(fb = filebundles; fb != NULL; fb = fb->next) { snprintf(buf2, sizeof(buf2), "%s", fb->prefix); if((s = strchr(buf2, '/')) != NULL) *s = 0; TAILQ_FOREACH(fde, &fd->fd_entries, fde_link) if(!strcmp(rstr_get(fde->fde_filename), buf2)) break; if(fde != NULL) continue; snprintf(buf, sizeof(buf), "bundle://%s", buf2); fa_dir_add(fd, buf, buf2, CONTENT_DIR); } } return 0; } while(*url == '/') url++; for(fb = filebundles; fb != NULL; fb = fb->next) { if(!strncmp(url, fb->prefix, strlen(url))) { if(fb->prefix[strlen(url)] == '/') { if(fd != NULL) { int len = strlen(url)+1; snprintf(buf2, sizeof(buf2), "%s", fb->prefix + len); if((s = strchr(buf2, '/')) != NULL) *s = 0; TAILQ_FOREACH(fde, &fd->fd_entries, fde_link) if(!strcmp(rstr_get(fde->fde_filename), buf2)) break; if(fde != NULL) continue; snprintf(buf, sizeof(buf), "bundle://%.*s%s", len, fb->prefix, buf2); fa_dir_add(fd, buf, buf2, CONTENT_DIR); } ok = 1; continue; } else { ok = 1; if(fd == NULL) continue; for(fbe = fb->entries; fbe->filename != NULL; fbe++) { snprintf(buf2, sizeof(buf2), "%s", fbe->filename); if((s = strchr(buf2, '/')) != NULL) { *s = 0; fde = TAILQ_LAST(&fd->fd_entries, fa_dir_entry_queue); if(fde != NULL && !strcmp(rstr_get(fde->fde_filename), buf2)) continue; snprintf(buf, sizeof(buf), "bundle://%s/%s", fb->prefix, buf2); } else { snprintf(buf, sizeof(buf), "bundle://%s/%s", fb->prefix, fbe->filename); } fa_dir_add(fd, buf, buf2, s ? CONTENT_DIR : CONTENT_FILE); } } } else if(!strncmp(url, fb->prefix, strlen(fb->prefix))) {