public void SwitchToFolderSource (SafeUri uri) { IImportSource source; if (!history_sources.TryGetValue (uri, out source)) { var name = uri.GetFilename (); source = new FileImportSource (uri, name, "folder"); history_sources[uri] = source; } PopulateSourceCombo (source); Controller.ActiveSource = source; }
public void TestFileUris() { foreach (var test in tests) { var suri = new SafeUri (test.Uri); Assert.AreEqual (suri.AbsoluteUri, test.AbsoluteUri, String.Format("AbsoluteUri for {0}", test.Uri)); Assert.AreEqual (suri.GetExtension (), test.Extension, String.Format("Extension for {0}", test.Uri)); Assert.AreEqual (suri.GetBaseUri ().ToString (), test.BaseUri, String.Format("BaseUri for {0}", test.Uri)); Assert.AreEqual (suri.GetFilename (), test.Filename, String.Format("Filename for {0}", test.Uri)); Assert.AreEqual (suri.GetFilenameWithoutExtension (), test.FilenameWithoutExtension, String.Format("FilenameWithoutExtension for {0}", test.Uri)); } }
SafeUri FindImportDestination(SafeUri uri, DateTime time) { // Find a new unique location inside the photo folder string name = uri.GetFilename (); var dest_uri = FSpot.Core.Global.PhotoUri.Append (time.Year.ToString ()) .Append (String.Format ("{0:D2}", time.Month)) .Append (String.Format ("{0:D2}", time.Day)); EnsureDirectory (dest_uri); // If the destination we'd like to use is the file itself return that if (dest_uri.Append (name) == uri) return uri; // Find an unused name int i = 1; var dest = dest_uri.Append (name); var file = GLib.FileFactory.NewForUri (dest); while (file.Exists) { var filename = uri.GetFilenameWithoutExtension (); var extension = uri.GetExtension (); dest = dest_uri.Append (String.Format ("{0}-{1}{2}", filename, i++, extension)); file = GLib.FileFactory.NewForUri (dest); } return dest; }