public CopyToLibraryIfAppropriate ( bool force_copy ) : bool | ||
force_copy | bool | |
return | bool |
public DatabaseTrackInfo ImportTrack(SafeUri uri) { if (!IsWhiteListedFile(uri.LocalPath)) { 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 = null; // 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 { track = new DatabaseTrackInfo(); track.Uri = uri; StreamTagger.TrackInfoMerge(track, StreamTagger.ProcessUri(uri)); track.PrimarySource = trackPrimarySourceChooser(track); 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); }
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; } if (Banshee.IO.File.GetSize (uri) == 0) { throw new InvalidFileException (String.Format ( Catalog.GetString ("File is empty so it could not be imported: {0}"), Path.GetFileName (uri.LocalPath))); } DatabaseTrackInfo track = new DatabaseTrackInfo () { Uri = uri }; using (var file = StreamTagger.ProcessUri (uri)) { StreamTagger.TrackInfoMerge (track, file, false, true, 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; }
/*public override void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, UserJob job) { Banshee.IO.File.Copy (track.Uri, uri, false); }*/ protected override void AddTrack (DatabaseTrackInfo track) { // Ignore if already have it if (track.PrimarySourceId == DbId) return; PrimarySource source = track.PrimarySource; // If it's from a local primary source, change its PrimarySource if (source.IsLocal || source is LibrarySource) { track.PrimarySource = this; if (!(source is LibrarySource)) { track.CopyToLibraryIfAppropriate (false); } track.Save (false); // TODO optimize, remove this? I think it makes moving items // between local libraries very slow. //source.NotifyTracksChanged (); } else { // Figure out where we should put it if were to copy it var pattern = this.PathPattern ?? MusicLibrarySource.MusicFileNamePattern; string path = pattern.BuildFull (BaseDirectory, track); SafeUri uri = new SafeUri (path); // Make sure it's not already in the library // TODO optimize - no need to recreate this int [] every time if (DatabaseTrackInfo.ContainsUri (uri, new int [] {DbId})) { return; } // Since it's not, copy it and create a new TrackInfo object track.PrimarySource.CopyTrackTo (track, uri, AddTrackJob); // Create a new entry in CoreTracks for the copied file DatabaseTrackInfo new_track = new DatabaseTrackInfo (track); new_track.Uri = uri; new_track.PrimarySource = this; new_track.Save (false); } }
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); } if (!Banshee.IO.File.GetPermissions(uri).IsReadable) { throw new InvalidFileException(String.Format( Catalog.GetString("File is not readable so it could not be imported: {0}"), Path.GetFileName(uri.LocalPath))); } if (Banshee.IO.File.GetSize(uri) == 0) { throw new InvalidFileException(String.Format( Catalog.GetString("File is empty so it could not be imported: {0}"), Path.GetFileName(uri.LocalPath))); } DatabaseTrackInfo track = new DatabaseTrackInfo() { Uri = uri }; using (var file = StreamTagger.ProcessUri(uri)) { StreamTagger.TrackInfoMerge(track, file, false, true, 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); }