Fix normal sorting not working

This commit is contained in:
Royce551 2020-05-10 18:52:24 -05:00
parent 2cdd0aabb2
commit e7153cf19d

View file

@ -416,22 +416,31 @@ namespace FRESHMusicPlayer
} }
} }
private void SortLibraryButton_Click(object sender, EventArgs e) private async void SortLibraryButton_Click(object sender, EventArgs e)
{ {
List<string> songs = DatabaseHandler.ReadSongs(); if (!TaskIsRunning) await Task.Run(() =>
List<(string song, string path)> sort = new List<(string song, string path)>(); {
TaskIsRunning = true;
List<string> songs = DatabaseHandler.ReadSongs();
List<(string song, string path)> sort = new List<(string song, string path)>();
foreach (string x in songs) foreach (string x in songs)
{ {
ATL.Track track = new ATL.Track(x); Track track = new Track(x);
sort.Add(($"{track.Artist} - {track.Title}", x)); sort.Add(($"{track.Artist} - {track.Title}", x));
} }
sort.Sort(); sort.Sort();
DatabaseHandler.ClearLibrary(); DatabaseHandler.ClearLibrary();
foreach ((string song, string path) x in sort) foreach ((string song, string path) x in sort)
{ {
DatabaseHandler.ImportSong(x.path); DatabaseHandler.ImportSong(x.path);
} }
});
TaskIsRunning = false;
LibraryNeedsUpdating = true;
Notification notification = new Notification("Success!", "Your database was sorted successfully.", 5000);
notification.Location = Location;
notification.Show();
} }
private async void ReverseLibraryButton_Click(object sender, EventArgs e) private async void ReverseLibraryButton_Click(object sender, EventArgs e)
@ -444,7 +453,7 @@ namespace FRESHMusicPlayer
foreach (string x in songs) foreach (string x in songs)
{ {
ATL.Track track = new ATL.Track(x); Track track = new Track(x);
sort.Add(($"{track.Artist} - {track.Title}", x)); sort.Add(($"{track.Artist} - {track.Title}", x));
} }
sort.Sort(); sort.Sort();