bool DirList::InternalLoadPath(std::string &folderpath) { if(folderpath.size() < 3) return false; struct dirent *dirent = NULL; DIR *dir = NULL; dir = opendir(folderpath.c_str()); if (dir == NULL) return false; while ((dirent = readdir(dir)) != 0) { bool isDir = dirent->d_type & DT_DIR; const char *filename = dirent->d_name; if(isDir) { if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) continue; if(Flags & CheckSubfolders) { int length = folderpath.size(); if(length > 2 && folderpath[length-1] != '/') folderpath += '/'; folderpath += filename; InternalLoadPath(folderpath); folderpath.erase(length); } if(!(Flags & Dirs)) continue; } else if(!(Flags & Files)) { continue; } if(Filter) { char * fileext = strrchr(filename, '.'); if(!fileext) continue; if(strtokcmp(fileext, Filter, ",") == 0) AddEntrie(folderpath, filename, isDir); } else { AddEntrie(folderpath, filename, isDir); } } closedir(dir); return true; }
bool GuiBGM::ParsePath(const char * folderpath) { ClearList(); if(currentPath) delete [] currentPath; currentPath = new char[strlen(folderpath)+1]; sprintf(currentPath, "%s", folderpath); char * isdirpath = strrchr(folderpath, '.'); if(isdirpath) { char * pathptr = strrchr(currentPath, '/'); if(pathptr) { pathptr++; pathptr[0] = 0; } } char * LoadedFilename = strrchr(folderpath, '/')+1; char filename[1024]; struct stat st; DIR_ITER * dir = diropen(currentPath); if (dir == NULL) { LoadStandard(); return false; } u32 counter = 0; while (dirnext(dir,filename,&st) == 0) { char * fileext = strrchr(filename, '.'); if(fileext) { if(strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0 || strcasecmp(fileext, ".wav") == 0) { AddEntrie(filename); if(strcmp(LoadedFilename, filename) == 0) currentPlaying = counter; counter++; } } } dirclose(dir); snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s", folderpath); return true; }