diff --git a/src/registry.rs b/src/registry.rs index 8561592..02b6e6a 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -62,20 +62,31 @@ impl Registry { pub fn save_albums_file(&self) -> Result<(), Error> { let mut file = File::create(format!("{}.list.new", self.device))?; - let mut cur_parent = PathBuf::new(); + let mut cur_artist = PathBuf::new(); let mut albums: Vec<&PathBuf> = self.albums_fs.iter().collect(); albums.sort(); for album in albums { - let parent = album.parent().unwrap(); - if parent != cur_parent { - writeln!(file, "{}/", parent.to_str().unwrap()); - cur_parent = parent.to_path_buf(); + let artist = album.parent().unwrap(); + if artist != cur_artist { + let artist_str = format!("{}/", artist.to_str().unwrap()); + // FIXME: Make this way more efficient! + if self + .selected_albums + .iter() + .any(|ref path| path.starts_with(&artist_str)) + { + writeln!(file, "{}", artist_str)?; + } else { + writeln!(file, "#{}", artist_str)?; + } + cur_artist = artist.to_path_buf(); } + let album_str = album.to_str().unwrap(); if self.selected_albums.contains(album) { - writeln!(file, "{}/***", album.to_str().unwrap()); + writeln!(file, "{}/***", album_str)?; } else { - writeln!(file, "#{}/***", album.to_str().unwrap()); + writeln!(file, "#{}/***", album_str)?; } } Ok(())