/// <summary> /// Cleans up live365 session data from a track url /// </summary> /// <param name="url"> /// A <see cref="SafeUri"/> -- the original url to be cleaned /// </param> /// <returns> /// A <see cref="SafeUri"/> -- the cleaned url /// </returns> public override SafeUri CleanUpUrl(SafeUri url) { if (url.ToString().Contains("session_id")) { int pos = url.ToString().IndexOf("session_id"); string new_url = url.ToString().Substring(0, pos - 1); return(new SafeUri(new_url)); } return(url); }
static bool IsValid(SafeUri uri, Pixbuf pixbuf) { if (pixbuf == null) { return(false); } if (pixbuf.GetOption(ThumbUriOpt) != uri.ToString()) { return(false); } var file = GLib.FileFactory.NewForUri(uri); if (!file.Exists) { return(false); } var info = file.QueryInfo("time::modified", GLib.FileQueryInfoFlags.None, null); if (pixbuf.GetOption(ThumbMTimeOpt) != info.GetAttributeULong("time::modified").ToString()) { return(false); } return(true); }
public Photo [] Query(SafeUri uri) { string filename = uri.GetFilename(); /* query by file */ if (!String.IsNullOrEmpty(filename)) { return(Query(new HyenaSqliteCommand( "SELECT id, " + "time, " + "base_uri, " + "filename, " + "description, " + "roll_id, " + "default_version_id, " + "rating " + "FROM photos " + "WHERE base_uri LIKE ?" + "AND filename LIKE ?", uri.GetBaseUri().ToString(), filename))); } /* query by directory */ return(Query(new HyenaSqliteCommand( "SELECT id, " + "time, " + "base_uri, " + "filename, " + "description, " + "roll_id, " + "default_version_id, " + "rating " + "FROM photos " + "WHERE base_uri LIKE ?" + "AND base_uri NOT LIKE ?", uri.ToString() + "%", uri.ToString() + "/%/%"))); }
private void AttemptToAddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri) { if (!Banshee.IO.File.Exists(fromUri)) { throw new FileNotFoundException(Catalog.GetString("File not found"), fromUri.ToString()); } // Ensure there's enough space if (BytesAvailable - Banshee.IO.File.GetSize(fromUri) >= 0) { // Ensure it's not already on the device if (ServiceManager.DbConnection.Query <int> (track_on_dap_query, DbId, track.MetadataHash) == 0) { AddTrackToDevice(track, fromUri); } } }
public override void UpdateMetadata(DatabaseTrackInfo track) { SafeUri new_uri = new SafeUri(GetTrackPath(track, System.IO.Path.GetExtension(track.Uri))); if (new_uri.ToString() != track.Uri.ToString()) { Directory.Create(System.IO.Path.GetDirectoryName(new_uri.LocalPath)); Banshee.IO.File.Move(track.Uri, new_uri); //to remove the folder if it's not needed anymore: DeleteTrackFile(track); track.Uri = new_uri; track.Save(true, BansheeQuery.UriField); } base.UpdateMetadata(track); }
public RssLoader(UriCollection collection, SafeUri uri) { XmlDocument doc = new XmlDocument(); doc.Load(uri.ToString()); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("media", "http://search.yahoo.com/mrss/"); ns.AddNamespace("pheed", "http://www.pheed.com/pheed/"); ns.AddNamespace("apple", "http://www.apple.com/ilife/wallpapers"); List <FilePhoto> items = new List <FilePhoto> (); XmlNodeList list = doc.SelectNodes("/rss/channel/item/media:content", ns); foreach (XmlNode item in list) { SafeUri image_uri = new SafeUri(item.Attributes ["url"].Value); Hyena.Log.DebugFormat("flickr uri = {0}", image_uri.ToString()); items.Add(new FilePhoto(image_uri)); } if (list.Count < 1) { list = doc.SelectNodes("/rss/channel/item/pheed:imgsrc", ns); foreach (XmlNode item in list) { SafeUri image_uri = new SafeUri(item.InnerText.Trim()); Hyena.Log.DebugFormat("pheed uri = {0}", uri); items.Add(new FilePhoto(image_uri)); } } if (list.Count < 1) { list = doc.SelectNodes("/rss/channel/item/apple:image", ns); foreach (XmlNode item in list) { SafeUri image_uri = new SafeUri(item.InnerText.Trim()); Hyena.Log.DebugFormat("apple uri = {0}", uri); items.Add(new FilePhoto(image_uri)); } } collection.Add(items.ToArray()); }
// internal for unit testing with Moq internal bool IsValid(SafeUri uri, Pixbuf pixbuf) { if (pixbuf == null) { return(false); } if (pixbuf.GetOption(ThumbUriOpt) != uri.ToString()) { return(false); } if (!fileSystem.File.Exists(uri)) { return(false); } var mTime = fileSystem.File.GetMTime(uri); return(pixbuf.GetOption(ThumbMTimeOpt) == mTime.ToString()); }
public bool CopyToLibraryIfAppropriate(bool force_copy) { bool copy_success = true; LibrarySource library_source = PrimarySource as LibrarySource; if (library_source == null) { // Get out, not a local Library return(false); } SafeUri old_uri = this.Uri; if (old_uri == null) { // Get out quick, no URI set yet. return(copy_success); } bool in_library = old_uri.IsLocalPath ? old_uri.AbsolutePath.StartsWith(PrimarySource.BaseDirectoryWithSeparator) : false; if (!in_library && ((library_source.HasCopyOnImport && library_source.CopyOnImport) || force_copy)) { string new_filename = PathPattern != null?PathPattern.BuildFull(PrimarySource.BaseDirectory, this, Path.GetExtension(old_uri.ToString())) : Path.Combine(PrimarySource.BaseDirectory, Path.GetFileName(SafeUri.UriToFilename(old_uri))); 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); }
private bool RenameFile(DatabaseTrackInfo track) { SafeUri old_uri = track.Uri; bool in_library = old_uri.AbsolutePath.StartsWith(musicLibrarySource.BaseDirectoryWithSeparator); if (!in_library) { return(false); } string new_filename = track.PathPattern.BuildFull(musicLibrarySource.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); }
/* * UpdateFolderTree queries for directories in database and updates * a possibly existing folder-tree to the queried structure */ private void UpdateFolderTree() { Clear(); count_all = 0; /* points at start of each iteration to the leaf of the last inserted uri */ TreeIter iter = TreeIter.Zero; /* stores the segments of the last inserted uri */ string[] last_segments = new string[] {}; int last_count = 0; Hyena.Data.Sqlite.IDataReader reader = database.Database.Query(query_string); while (reader.Read()) { var base_uri = new SafeUri(reader["base_uri"].ToString(), true); int count = Convert.ToInt32(reader["count"]); // FIXME: this is a workaround hack to stop things from crashing - https://bugzilla.gnome.org/show_bug.cgi?id=622318 int index = base_uri.ToString().IndexOf("://"); var hack = base_uri.ToString().Substring(index + 3); hack = hack.IndexOf('/') == 0 ? hack : "/" + hack; string[] segments = hack.TrimEnd('/').Split('/'); /* First segment contains nothing (since we split by /), so we * can overwrite the first segment for our needs and put the * scheme here. */ segments[0] = base_uri.Scheme; int i = 0; /* find first difference of last inserted an current uri */ while (i < last_segments.Length && i < segments.Length) { if (segments[i] != last_segments[i]) { break; } i++; } /* points to the parent node of the current iter */ TreeIter parent_iter = iter; /* step back to the level, where the difference occur */ for (int j = 0; j + i < last_segments.Length; j++) { iter = parent_iter; if (IterParent(out parent_iter, iter)) { last_count += (int)GetValue(parent_iter, 1); SetValue(parent_iter, 1, last_count); } else { count_all += (int)last_count; } } while (i < segments.Length) { if (IterIsValid(parent_iter)) { iter = AppendValues(parent_iter, Uri.UnescapeDataString(segments[i]), (segments.Length - 1 == i)? count : 0, (GetValue(parent_iter, 2) as SafeUri).Append(String.Format("{0}/", segments[i])) ); } else { iter = AppendValues(Uri.UnescapeDataString(segments[i]), (segments.Length - 1 == i)? count : 0, new SafeUri(String.Format("{0}:///", base_uri.Scheme), true)); } parent_iter = iter; i++; } last_count = count; last_segments = segments; } if (IterIsValid(iter)) { /* and at least, step back and update photo count */ while (IterParent(out iter, iter)) { last_count += (int)GetValue(iter, 1); SetValue(iter, 1, last_count); } count_all += last_count; } }
private static void OnDownloadCompletedHandler(object sender, DownloadCompletedEventArgs args) { DownloadInfo dif = args.DownloadInfo; SafeUri local_uri = new SafeUri(args.LocalUri); if (dif == null || local_uri == null) { return; } PodcastInfo pi = null; lock (downloads.SyncRoot) { if (downloads.Contains(dif)) { pi = downloads [args.DownloadInfo] as PodcastInfo; } } if (pi != null) { TrackInfo ti = null; try { try { ti = new LibraryTrackInfo(local_uri.LocalPath); } catch (ApplicationException) { ti = Globals.Library.TracksFnKeyed [PathUtil.MakeFileNameKey(local_uri)] as TrackInfo; } } catch (Exception e) { PodcastErrorsSource.Instance.AddError( local_uri.ToString(), Catalog.GetString("Unable to add file to library"), e ); } pi.IsDownloaded = true; if (ti != null) { pi.Track = ti; } else { pi.DownloadFailed = true; PodcastDBManager.Commit(pi); return; } pi.LocalPath = local_uri.ToString(); PodcastDBManager.Commit(pi); pi.Feed.UpdateCounts(); ThreadAssist.ProxyToMain(delegate { Library.AddTrack(ti, pi, true); }); } source.Update(); }
private static void OnDownloadCompletedHandler(object sender, DownloadCompletedEventArgs args) { DownloadInfo dif = args.DownloadInfo; SafeUri local_uri = new SafeUri (args.LocalUri); if (dif == null || local_uri == null) { return; } PodcastInfo pi = null; lock (downloads.SyncRoot) { if (downloads.Contains (dif)) { pi = downloads [args.DownloadInfo] as PodcastInfo; } } if (pi != null) { TrackInfo ti = null; try { try { ti = new LibraryTrackInfo(local_uri.LocalPath); } catch (ApplicationException) { ti = Globals.Library.TracksFnKeyed [PathUtil.MakeFileNameKey(local_uri)] as TrackInfo; } } catch (Exception e) { PodcastErrorsSource.Instance.AddError ( local_uri.ToString (), Catalog.GetString ("Unable to add file to library"), e ); } pi.IsDownloaded = true; if (ti != null) { pi.Track = ti; } else { pi.DownloadFailed = true; PodcastDBManager.Commit (pi); return; } pi.LocalPath = local_uri.ToString (); PodcastDBManager.Commit (pi); pi.Feed.UpdateCounts (); ThreadAssist.ProxyToMain (delegate { Library.AddTrack (ti, pi, true); }); } source.Update (); }