public bool CopyToLibraryIfAppropriate(bool force_copy) { bool copy_success = true; SafeUri old_uri = this.Uri; if (old_uri == null) { // Get out quick, no URI set yet. return(copy_success); } bool in_library = old_uri.AbsolutePath.StartsWith(PrimarySource.BaseDirectoryWithSeparator); if (!in_library && (LibrarySchema.CopyOnImport.Get() || force_copy)) { string new_filename = FileNamePattern.BuildFull(PrimarySource.BaseDirectory, this, Path.GetExtension(old_uri.ToString())); SafeUri new_uri = new SafeUri(new_filename); try { if (Banshee.IO.File.Exists(new_uri)) { if (Banshee.IO.File.GetSize(old_uri) == Banshee.IO.File.GetSize(new_uri)) { Hyena.Log.DebugFormat("Not copying {0} to library because there is already a file of same size at {1}", old_uri, new_uri); copy_success = false; return(copy_success); } else { string extension = Path.GetExtension(new_filename); string filename_no_ext = new_filename.Remove(new_filename.Length - extension.Length); int duplicate_index = 1; while (Banshee.IO.File.Exists(new_uri)) { new_filename = String.Format("{0} ({1}){2}", filename_no_ext, duplicate_index, extension); new_uri = new SafeUri(new_filename); duplicate_index++; } } } Banshee.IO.File.Copy(old_uri, new_uri, false); Uri = new_uri; } catch (Exception e) { Log.ErrorFormat("Exception copying into library: {0}", e); } } return(copy_success); }
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 it's PrimarySource if (source.IsLocal || source is LibrarySource) { track.PrimarySource = this; if (!(source is LibrarySource)) { track.CopyToLibraryIfAppropriate(false); } track.Save(false); source.NotifyTracksChanged(); } else { // Figure out where we should put it if were to copy it string path = FileNamePattern.BuildFull(BaseDirectory, track); SafeUri uri = new SafeUri(path); // Make sure it's not already in the library // TODO optimize - no need to recrate 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); } }
private void RipNextTrack() { if (queue.Count == 0) { OnFinished(); Dispose(); return; } AudioCdTrackInfo track = queue.Dequeue(); user_job.Title = String.Format(Catalog.GetString("Importing {0} of {1}"), ++track_index, source.DiscModel.EnabledCount); status = String.Format("{0} - {1}", track.ArtistName, track.TrackTitle); user_job.Status = status; SafeUri uri = new SafeUri(FileNamePattern.BuildFull(ServiceManager.SourceManager.MusicLibrary.BaseDirectory, track, null)); bool tagging_supported; ripper.RipTrack(track.IndexOnDisc, track, uri, out tagging_supported); }
private bool RenameFile(DatabaseTrackInfo track) { SafeUri old_uri = track.Uri; bool in_library = old_uri.AbsolutePath.StartsWith(source.BaseDirectoryWithSeparator); if (!in_library) { return(false); } string new_filename = FileNamePattern.BuildFull(source.BaseDirectory, track, System.IO.Path.GetExtension(old_uri.ToString())); SafeUri new_uri = new SafeUri(new_filename); if (!new_uri.Equals(old_uri) && !Banshee.IO.File.Exists(new_uri)) { Banshee.IO.File.Move(old_uri, new_uri); Banshee.IO.Utilities.TrimEmptyDirectories(old_uri); track.Uri = new_uri; return(true); } return(false); }
private void AcceptTransfer(IncomingFileTransfer transfer) { if (transfer == null) { return; } // passing extension on Uri to allow import after a download string ext = Key.Track.Uri.ToString().Substring(Key.Track.Uri.ToString().LastIndexOf('/') + 1); string filename = FileNamePattern.BuildFull(ContactSource.TempDownloadDirectory, Key.Track, ext); if (transfer.State == API.Dispatchables.TransferState.LocalPending) { if (!String.IsNullOrEmpty(filename)) { transfer.Filename = filename; transfer.Accept(); } else { transfer.Accept(ContactSource.TempDownloadDirectory); } } }