void PresetLoader::rescan() { // std::cerr << "Rescanning..." << std::endl; // Clear the directory entry collection clear(); // If directory already opened, close it first if ( _dir ) { closedir ( _dir ); _dir = 0; } // Allocate a new a stream given the current directory name if ( ( _dir = opendir ( _dirname.c_str() ) ) == NULL ) { handleDirectoryError(); return; // no files loaded. _entries is empty } struct dirent * dir_entry; std::set<std::string> alphaSortedFileSet; std::set<std::string> alphaSortedPresetNameSet; while ( ( dir_entry = readdir ( _dir ) ) != NULL ) { if (dir_entry->d_name == 0) continue; std::ostringstream out; // Convert char * to friendly string std::string filename ( dir_entry->d_name ); // Verify extension is projectm or milkdrop if (!_presetFactoryManager.extensionHandled(parseExtension(filename))) continue; if ( filename.length() > 0 && filename[0] == '.' ) continue; // Create full path name out << _dirname << PATH_SEPARATOR << filename; // Add to our directory entry collection alphaSortedFileSet.insert ( out.str() ); alphaSortedPresetNameSet.insert ( filename ); // the directory entry struct is freed elsewhere } // Push all entries in order from the file set to the file entries member (which is an indexed vector) for ( std::set<std::string>::iterator pos = alphaSortedFileSet.begin(); pos != alphaSortedFileSet.end();++pos ) _entries.push_back ( *pos ); // Push all preset names in similar fashion for ( std::set<std::string>::iterator pos = alphaSortedPresetNameSet.begin(); pos != alphaSortedPresetNameSet.end();++pos ) _presetNames.push_back ( *pos ); // Give all presets equal rating of 3 - why 3? I don't know _ratings = std::vector<RatingList>(TOTAL_RATING_TYPES, RatingList( _presetNames.size(), 3 )); _ratingsSums = std::vector<int>(TOTAL_RATING_TYPES, 3 * _presetNames.size()); assert ( _entries.size() == _presetNames.size() ); }
/// Clears all presets from the collection inline void clear() { _entries.clear(); _presetNames.clear(); _ratings = std::vector<RatingList>(TOTAL_RATING_TYPES, RatingList()); clearRatingsSum(); }