Updated SongPictureInfo use to async copy of picture data stream. Update other classes accordingly.
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Harmonia.Core.Library;
|
||||
|
||||
public interface IAudioLibrary
|
||||
{
|
||||
void AddLocation(string path);
|
||||
ValueTask AddLocationAsync(string path, CancellationToken cancellationToken);
|
||||
void RemoveLocation(string path);
|
||||
void RemoveLocations(string[] paths);
|
||||
void Scan(string path);
|
||||
@@ -25,12 +25,12 @@ public abstract class AudioLibrary : IAudioLibrary
|
||||
public event EventHandler<EventArgs>? ScanStarted;
|
||||
public event EventHandler<EventArgs>? ScanFinished;
|
||||
|
||||
protected abstract bool IncludeLocation(string path);
|
||||
protected abstract void ScanLocation(string path);
|
||||
protected abstract ValueTask<bool> IncludeLocationAsync(string path, CancellationToken cancellationToken);
|
||||
protected abstract ValueTask ScanLocationAsync(string path, CancellationToken cancellationToken);
|
||||
|
||||
public void AddLocation(string path)
|
||||
public async ValueTask AddLocationAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
if (IncludeLocation(path) == false)
|
||||
if (await IncludeLocationAsync(path, cancellationToken) == false)
|
||||
return;
|
||||
|
||||
LocationAdded?.Invoke(this, new EventArgs());
|
||||
@@ -69,13 +69,13 @@ public abstract class AudioLibrary : IAudioLibrary
|
||||
|
||||
public class AudioDatabaseLibrary(IAudioFileScanner audioFileScanner, AudioLibraryContext context) : AudioLibrary
|
||||
{
|
||||
protected override bool IncludeLocation(string path)
|
||||
protected override async ValueTask<bool> IncludeLocationAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
if (CanAddLocation(path) == false)
|
||||
return false;
|
||||
|
||||
Location location = GetLocation(path) ?? CreateLocation(path);
|
||||
ScanLocation(location);
|
||||
await ScanLocationAsync(location, cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -104,19 +104,19 @@ public class AudioDatabaseLibrary(IAudioFileScanner audioFileScanner, AudioLibra
|
||||
return context.Locations.FirstOrDefault(location => location.Name == path);
|
||||
}
|
||||
|
||||
protected override void ScanLocation(string path)
|
||||
protected override async ValueTask ScanLocationAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
Location? location = GetLocation(path);
|
||||
|
||||
if (location == null)
|
||||
return;
|
||||
|
||||
ScanLocation(location);
|
||||
await ScanLocationAsync(location, cancellationToken);
|
||||
}
|
||||
|
||||
private void ScanLocation(Location location)
|
||||
private async ValueTask ScanLocationAsync(Location location, CancellationToken cancellationToken)
|
||||
{
|
||||
SongModel[] songModels = audioFileScanner.GetSongsFromPath(location.Name);
|
||||
SongModel[] songModels = await audioFileScanner.GetSongsFromPathAsync(location.Name, cancellationToken);
|
||||
|
||||
AddFolders(location, songModels);
|
||||
AddSongs(songModels);
|
||||
|
||||
Reference in New Issue
Block a user