public DatabaseTrackInfo ImportTrack (SafeUri uri)
{
if (!IsWhiteListedFile (uri.AbsoluteUri)) {
return null;
}
if (DatabaseTrackInfo.ContainsUri (uri, PrimarySourceIds)) {
// TODO add DatabaseTrackInfo.SyncedStamp property, and if the file has been
// updated since the last sync, fetch its metadata into the db.
return null;
}
DatabaseTrackInfo track = new DatabaseTrackInfo () { Uri = uri };
using (var file = StreamTagger.ProcessUri (uri)) {
StreamTagger.TrackInfoMerge (track, file, false, true);
}
track.Uri = uri;
if (FindOutdatedDupe (track)) {
return null;
}
track.PrimarySource = trackPrimarySourceChooser (track);
// TODO note, there is deadlock potential here b/c of locking of shared commands and blocking
// because of transactions. Needs to be fixed in HyenaDatabaseConnection.
ServiceManager.DbConnection.BeginTransaction ();
try {
bool save_track = true;
if (track.PrimarySource is Banshee.Library.LibrarySource) {
save_track = track.CopyToLibraryIfAppropriate (force_copy);
}
if (save_track) {
track.Save (false);
}
ServiceManager.DbConnection.CommitTransaction ();
} catch (Exception) {
ServiceManager.DbConnection.RollbackTransaction ();
throw;
}
counts[track.PrimarySourceId] = counts.ContainsKey (track.PrimarySourceId) ? counts[track.PrimarySourceId] + 1 : 1;
// Reload every 20% or every 250 tracks, whatever is more (eg at most reload 5 times during an import)
if (counts[track.PrimarySourceId] >= Math.Max (TotalCount/5, 250)) {
counts[track.PrimarySourceId] = 0;
track.PrimarySource.NotifyTracksAdded ();
}
return track;
}