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; }
/// <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; }
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<long> (track_on_dap_query, DbId, track.MetadataHash) == 0) { AddTrackToDevice (track, fromUri); } } }
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 ()); }
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); }
/* * 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; 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; } }
// 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 (); }
private static string CreateUriId(SafeUri uri) { string digestible = uri.ToString (); return CreateId ("unknown", digestible); }