private void DeleteEmptyDirectory(GLib.File directory) { // if the directory we're dealing with is not in the // F-Spot photos directory, don't delete anything, // even if it is empty string photo_uri = SafeUri.UriToFilename(Global.PhotoUri.ToString()); bool path_matched = directory.Path.IndexOf(photo_uri) > -1; if (directory.Path.Equals(photo_uri) || !path_matched) { return; } if (DirectoryIsEmpty(directory)) { try { Log.DebugFormat("Removing empty directory: {0}", directory.Path); directory.Delete(); } catch (GLib.GException e) { // silently log the exception, but don't re-throw it // as to not annoy the user Log.Exception(e); } // check to see if the parent is empty DeleteEmptyDirectory(directory.Parent); } }
public static string TypeGuessForTree(GLib.File root) { IntPtr raw_ret = g_content_type_guess_for_tree(root == null ? IntPtr.Zero : root.Handle); string ret = GLib.Marshaller.PtrToStringGFree(raw_ret); return(ret); }
private uint CreateVersion(string name, string extension, uint base_version_id, bool create, bool is_protected) { extension = extension ?? VersionUri(base_version_id).GetExtension(); SafeUri new_base_uri = DefaultVersion.BaseUri; string filename = GetFilenameForVersionName(name, extension); SafeUri original_uri = VersionUri(base_version_id); SafeUri new_uri = new_base_uri.Append(filename); string import_md5 = DefaultVersion.ImportMD5; if (VersionNameExists(name)) { throw new Exception("This version name already exists"); } if (create) { GLib.File destination = GLib.FileFactory.NewForUri(new_uri); if (destination.Exists) { throw new Exception(string.Format("An object at this uri {0} already exists", new_uri)); } //FIXME. or better, fix the copy api ! GLib.File source = GLib.FileFactory.NewForUri(original_uri); source.Copy(destination, GLib.FileCopyFlags.None, null, null); } highest_version_id++; versions [highest_version_id] = new PhotoVersion(this, highest_version_id, new_base_uri, filename, import_md5, name, is_protected); changes.AddVersion(highest_version_id); return(highest_version_id); }
public static string GetMimeTypeForFile(string filename) { string mimeType = null; #if UNIX GLib.File file = GLib.FileFactory.NewForPath(filename); if (file.Exists) { // GLib backend // (null if the file does not exist) GLib.FileInfo info = file.QueryInfo("standard::content-type", GLib.FileQueryInfoFlags.None, null); mimeType = info.ContentType; } else { // use mono winforms backend as fallack for non-existing files // (also takes filename extension into account, // always returns a mimetype, even if the file does not exist) mimeType = Platform.Unix.Mime.Mime.GetMimeTypeForFile(filename); } #elif WIN32 // win32 registry backend // (uses filename extension only, always returns a mimetype) mimeType = Platform.Win32.Mime.RegistryMime.GetMimeTypeForExtension(filename); #endif if (mimeType == null) { return(MIME_TYPE_UNKNOWN); } else { return(mimeType); } }
public GLib.File GetFileForUri(string uri) { IntPtr native_uri = GLib.Marshaller.StringToPtrGStrdup(uri); IntPtr raw_ret = g_vfs_get_file_for_uri(Handle, native_uri); GLib.File ret = GLib.FileAdapter.GetObject(raw_ret, false); GLib.Marshaller.Free(native_uri); return(ret); }
public GLib.File GetFileForPath(string path) { IntPtr native_path = GLib.Marshaller.StringToPtrGStrdup(path); IntPtr raw_ret = g_vfs_get_file_for_path(Handle, native_path); GLib.File ret = GLib.FileAdapter.GetObject(raw_ret, false); GLib.Marshaller.Free(native_path); return(ret); }
public GLib.File ParseName(string parse_name) { IntPtr native_parse_name = GLib.Marshaller.StringToPtrGStrdup(parse_name); IntPtr raw_ret = g_vfs_parse_name(Handle, native_parse_name); GLib.File ret = GLib.FileAdapter.GetObject(raw_ret, false); GLib.Marshaller.Free(native_parse_name); return(ret); }
private bool DirectoryIsEmpty(GLib.File directory) { uint count = 0; using (GLib.FileEnumerator list = directory.EnumerateChildren("standard::name", GLib.FileQueryInfoFlags.None, null)) { foreach (var item in list) { count++; } } return(count == 0); }
public static unsafe GLib.FileMonitor Directory(GLib.File file, GLib.FileMonitorFlags flags, GLib.Cancellable cancellable) { IntPtr error = IntPtr.Zero; IntPtr raw_ret = g_file_monitor_directory(file == null ? IntPtr.Zero : file.Handle, (int)flags, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error); GLib.FileMonitor ret = GLib.Object.GetObject(raw_ret) as GLib.FileMonitor; if (error != IntPtr.Zero) { throw new GLib.GException(error); } return(ret); }
public void DeleteVersion(uint version_id, bool remove_original, bool keep_file) { if (version_id == OriginalVersionId && !remove_original) { throw new Exception("Cannot delete original version"); } SafeUri uri = VersionUri(version_id); if (!keep_file) { GLib.File file = GLib.FileFactory.NewForUri(uri); if (file.Exists) { try { file.Trash(null); } catch (GLib.GException) { Log.Debug("Unable to Trash, trying to Delete"); file.Delete(); } } try { thumbnailService.DeleteThumbnails(uri); } catch { // ignore an error here we don't really care. } // do we really need to check if the parent is a directory? // i.e. is file.Parent always a directory if the file instance is // an actual file? GLib.File directory = file.Parent; GLib.FileType file_type = directory.QueryFileType(GLib.FileQueryInfoFlags.None, null); if (directory.Exists && file_type == GLib.FileType.Directory) { DeleteEmptyDirectory(directory); } } versions.Remove(version_id); changes.RemoveVersion(version_id); for (version_id = highest_version_id; version_id >= OriginalVersionId; version_id--) { if (versions.ContainsKey(version_id)) { DefaultVersionId = version_id; break; } } }
public FileIcon(GLib.File file) : base(IntPtr.Zero) { if (GetType() != typeof(FileIcon)) { ArrayList vals = new ArrayList(); ArrayList names = new ArrayList(); if (file != null) { names.Add("file"); vals.Add(new GLib.Value(file)); } CreateNativeObject((string[])names.ToArray(typeof(string)), (GLib.Value[])vals.ToArray(typeof(GLib.Value))); return; } Raw = g_file_icon_new(file == null ? IntPtr.Zero : file.Handle); }
string ThemedSvg(string svgName) { if (DockTheme != DefaultTheme) { GLib.File themeFolder = ThemeContainerFolders .SelectMany(f => f.SubDirs(false)) .FirstOrDefault(th => th.Basename == DockTheme); if (themeFolder != null && themeFolder.GetChild(svgName).Exists) { return(themeFolder.GetChild(svgName).Path); } } return(svgName + "@" + System.Reflection.Assembly.GetExecutingAssembly().FullName); }
protected virtual void OnChanged(GLib.File file, GLib.File other_file, GLib.FileMonitorEvent event_type) { GLib.Value ret = GLib.Value.Empty; GLib.ValueArray inst_and_params = new GLib.ValueArray(4); GLib.Value[] vals = new GLib.Value [4]; vals [0] = new GLib.Value(this); inst_and_params.Append(vals [0]); vals [1] = new GLib.Value(file); inst_and_params.Append(vals [1]); vals [2] = new GLib.Value(other_file); inst_and_params.Append(vals [2]); vals [3] = new GLib.Value(event_type); inst_and_params.Append(vals [3]); g_signal_chain_from_overridden(inst_and_params.ArrayPtr, ref ret); foreach (GLib.Value v in vals) { v.Dispose(); } }
protected void RenameNewVersion() { try { System.Uri original_uri = GetUriForVersionFileName(this.currentphoto, this.currentphoto.DefaultVersion.Uri.LocalPath); System.Uri new_uri = GetUriForVersionFileName(this.currentphoto, new_filename); //Console.WriteLine ("ok pressed: old: " + this.currentphoto.DefaultVersionUri.LocalPath + "; " + original_uri.ToString() + " new: " + new_filename + "; " + new_uri.ToString() + "to open with: " ); // check if new version exist and remove foreach (uint id in currentphoto.VersionIds) { if (currentphoto.GetVersion(id).Name == new_version_entry.Text) { this.currentphoto.DeleteVersion(id); } } GLib.File destination = GLib.FileFactory.NewForUri(new_uri); if (destination.Exists) { throw new Exception(String.Format("An object at this uri {0} already exists", new_uri)); } //FIXME. or better, fix the copy api ! GLib.File source = GLib.FileFactory.NewForUri(original_uri); source.Copy(destination, GLib.FileCopyFlags.None, null, null); this.currentphoto.DefaultVersionId = this.currentphoto.AddVersion(new SafeUri(new_uri).GetBaseUri(), new SafeUri(new_uri).GetFilename(), new_version_entry.Text, true); uint currentid = this.currentphoto.DefaultVersionId; foreach (uint id in currentphoto.VersionIds) { if (currentphoto.GetVersion(id).Uri.ToString() == original_uri.ToString()) { this.currentphoto.DeleteVersion(id, false, false); } } this.currentphoto.DefaultVersionId = currentid; App.Instance.Database.Photos.Commit(this.currentphoto); this.currentphoto.Changes.DataChanged = true; } finally { Gtk.Application.Invoke(delegate { dialog.Destroy(); }); } }
public string InstallTheme(GLib.File file) { if (!file.Exists) { return(null); } if (!DockServices.Paths.UserDataFolder.Exists) { DockServices.Paths.UserDataFolder.MakeDirectory(null); } GLib.File themeDir = DockServices.Paths.UserDataFolder.GetChild("themes"); if (!themeDir.Exists) { themeDir.MakeDirectory(null); } Log <ThemeService> .Info("Trying to install theme: {0}", file.Path); try { List <string> oldThemes = DockThemes.ToList(); TarArchive ar = TarArchive.CreateInputTarArchive(new System.IO.FileStream(file.Path, System.IO.FileMode.Open)); ar.ExtractContents(themeDir.Path); List <string> newThemes = DockThemes.ToList(); newThemes.RemoveAll(f => oldThemes.Contains(f)); if (newThemes.Count == 1) { return(newThemes [0]); } return(null); } catch (Exception e) { Log <ThemeService> .Error("Error trying to unpack '{0}': {1}", file.Path, e.Message); Log <ThemeService> .Debug(e.StackTrace); return(null); } }
private void HandleResponse(object sender, Gtk.ResponseArgs args) { if (args.ResponseId != Gtk.ResponseType.Ok) { // FIXME this is to work around a bug in gtk+ where // the filesystem events are still listened to when // a FileChooserButton is destroyed but not finalized // and an event comes in that wants to update the child widgets. Dialog.Destroy(); uri_chooser.Dispose(); uri_chooser = null; return; } dest = GLib.FileFactory.NewForUri(uri_chooser.Uri); open = open_check.Active; scale = scale_check.Active; exportTags = export_tags_check.Active; exportTagIcons = export_tag_icons_check.Active; gallery_name = name_entry.Text; if (description_entry != null) { description = description_entry.Text; } if (scale) { size = size_spin.ValueAsInt; } command_thread = new System.Threading.Thread(new System.Threading.ThreadStart(Upload)); command_thread.Name = Catalog.GetString("Exporting Photos"); progress_dialog = new ThreadProgressDialog(command_thread, 1); progress_dialog.Start(); }
public uint CreateDefaultModifiedVersion(uint base_version_id, bool create_file) { int num = 1; while (true) { string name = Catalog.GetPluralString("Modified", "Modified ({0})", num); name = string.Format(name, num); //SafeUri uri = GetUriForVersionName (name, System.IO.Path.GetExtension (VersionUri(base_version_id).GetFilename())); string filename = GetFilenameForVersionName(name, System.IO.Path.GetExtension(versions [base_version_id].Filename)); SafeUri uri = DefaultVersion.BaseUri.Append(filename); GLib.File file = GLib.FileFactory.NewForUri(uri); if (!VersionNameExists(name) && !file.Exists) { return(CreateVersion(name, base_version_id, create_file)); } num++; } }
public uint CreateNamedVersion(string name, string extension, uint base_version_id, bool create_file) { int num = 1; string final_name; while (true) { final_name = string.Format( (num == 1) ? Catalog.GetString("Modified in {1}") : Catalog.GetString("Modified in {1} ({0})"), num, name); string filename = GetFilenameForVersionName(name, System.IO.Path.GetExtension(versions [base_version_id].Filename)); SafeUri uri = DefaultVersion.BaseUri.Append(filename); GLib.File file = GLib.FileFactory.NewForUri(uri); if (!VersionNameExists(final_name) && !file.Exists) { return(CreateVersion(final_name, extension, base_version_id, create_file)); } num++; } }
private void HandleResponse(object sender, Gtk.ResponseArgs args) { if (args.ResponseId != Gtk.ResponseType.Ok) { // FIXME this is to work around a bug in gtk+ where // the filesystem events are still listened to when // a FileChooserButton is destroyed but not finalized // and an event comes in that wants to update the child widgets. Dialog.Destroy (); uri_chooser.Dispose (); uri_chooser = null; return; } dest = GLib.FileFactory.NewForUri (uri_chooser.Uri); open = open_check.Active; scale = scale_check.Active; exportTags = export_tags_check.Active; exportTagIcons = export_tag_icons_check.Active; gallery_name = name_entry.Text; if (description_entry != null) description = description_entry.Text; if (scale) size = size_spin.ValueAsInt; command_thread = new System.Threading.Thread (new System.Threading.ThreadStart (Upload)); command_thread.Name = Catalog.GetString ("Exporting Photos"); progress_dialog = new ThreadProgressDialog (command_thread, 1); progress_dialog.Start (); }
public void Upload() { // FIXME: use mkstemp try { ThreadAssist.ProxyToMain(Dialog.Hide); GLib.File source = GLib.FileFactory.NewForPath(Path.Combine(gallery_path, gallery_name)); GLib.File target = GLib.FileFactory.NewForPath(Path.Combine(dest.Path, source.Basename)); if (dest.IsNative) { gallery_path = dest.Path; } progress_dialog.Message = Catalog.GetString("Building Gallery"); progress_dialog.Fraction = 0.0; FolderGallery gallery; if (static_radio.Active) { gallery = new HtmlGallery(selection, gallery_path, gallery_name); } else if (original_radio.Active) { gallery = new OriginalGallery(selection, gallery_path, gallery_name); } else { gallery = new FolderGallery(selection, gallery_path, gallery_name); } if (scale) { Log.DebugFormat("Resize Photos to {0}.", size); gallery.SetScale(size); } else { Log.Debug("Exporting full size."); } if (exportTags) { gallery.ExportTags = true; } if (exportTagIcons) { gallery.ExportTagIcons = true; } gallery.Description = description; gallery.GenerateLayout(); FilterSet filter_set = new FilterSet(); if (scale) { filter_set.Add(new ResizeFilter((uint)size)); } filter_set.Add(new ChmodFilter()); filter_set.Add(new UniqueNameFilter(new SafeUri(gallery_path))); for (int photo_index = 0; photo_index < selection.Count; photo_index++) { try { progress_dialog.Message = System.String.Format(Catalog.GetString("Exporting \"{0}\"..."), selection[photo_index].Name); progress_dialog.Fraction = photo_index / (double)selection.Count; gallery.ProcessImage(photo_index, filter_set); progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), (photo_index + 1), selection.Count); } catch (Exception e) { Log.Error(e.ToString()); progress_dialog.Message = String.Format(Catalog.GetString("Error Copying \"{0}\" to Gallery:{2}{1}"), selection[photo_index].Name, e.Message, Environment.NewLine); progress_dialog.ProgressText = Catalog.GetString("Error"); if (progress_dialog.PerformRetrySkip()) { photo_index--; } } } // create the zip tarballs for original if (gallery is OriginalGallery) { bool include_tarballs; try { include_tarballs = Preferences.Get <bool> (INCLUDE_TARBALLS_KEY); } catch (NullReferenceException) { include_tarballs = true; Preferences.Set(INCLUDE_TARBALLS_KEY, true); } if (include_tarballs) { (gallery as OriginalGallery).CreateZip(); } } // we've created the structure, now if the destination was local (native) we are done // otherwise we xfer if (!dest.IsNative) { Log.DebugFormat("Transferring \"{0}\" to \"{1}\"", source.Path, target.Path); progress_dialog.Message = String.Format(Catalog.GetString("Transferring to \"{0}\""), target.Path); progress_dialog.ProgressText = Catalog.GetString("Transferring..."); source.CopyRecursive(target, GLib.FileCopyFlags.Overwrite, new GLib.Cancellable(), Progress); } // No need to check result here as if result is not true, an Exception will be thrown before progress_dialog.Message = Catalog.GetString("Export Complete."); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Catalog.GetString("Exporting Photos Completed."); progress_dialog.ButtonLabel = Gtk.Stock.Ok; if (open) { Log.DebugFormat(String.Format("Open URI \"{0}\"", target.Uri.ToString())); ThreadAssist.ProxyToMain(() => { GtkBeans.Global.ShowUri(Dialog.Screen, target.Uri.ToString()); }); } // Save these settings for next time Preferences.Set(SCALE_KEY, scale); Preferences.Set(SIZE_KEY, size); Preferences.Set(OPEN_KEY, open); Preferences.Set(EXPORT_TAGS_KEY, exportTags); Preferences.Set(EXPORT_TAG_ICONS_KEY, exportTagIcons); Preferences.Set(METHOD_KEY, static_radio.Active ? "static" : original_radio.Active ? "original" : "folder"); Preferences.Set(URI_KEY, uri_chooser.Uri); } catch (System.Exception e) { Log.Error(e.ToString()); progress_dialog.Message = e.ToString(); progress_dialog.ProgressText = Catalog.GetString("Error Transferring"); } finally { // if the destination isn't local then we want to remove the temp directory we // created. if (!dest.IsNative) { System.IO.Directory.Delete(gallery_path, true); } ThreadAssist.ProxyToMain(() => { Dialog.Destroy(); }); } }
public static FileNode GetFileNode(int nodeType, String fileName, FileSlice owner) { int fileDisplayList; if (listGenerated[nodeType]) { fileDisplayList = displayLists[nodeType]; } else { fileDisplayList = displayLists[nodeType] = GenerateDisplayList(nodeType); } GLib.File fi = GLib.FileFactory.NewForPath(fileName); FileNode node = new FileNode(fi.Basename); node.File = fileName; //node.NumChildren = fi. GLib.FileInfo info = fi.QueryInfo("access::can-execute,thumbnail::path,filesystem::readonly,time::modified", GLib.FileQueryInfoFlags.None, null); node.SetDisplayList(fileDisplayList); node.SetParent(owner); if (nodeType == DIR_NODE) { node.IsDirectory = true; try { node.NumDirs = Directory.GetDirectories(fileName).Length; node.NumFiles = Directory.GetFiles(fileName).Length; node.NumChildren = node.NumDirs + node.NumFiles; node.DirHeight = GetHeightForFolder(node.NumChildren); } catch { node.NumChildren = 0; node.DirHeight = 1f; } } else { String description = Gnome.Vfs.Mime.GetDescription(fi.QueryInfo("standard::content-type", GLib.FileQueryInfoFlags.None, null).ContentType); if (description == null) { // use the extension String[] split = node.FileName.Split('.'); if (split.Length > 1) { description = split[split.Length - 1] + " file"; } else { // no extension either description = "unknown"; } } node.Description = description; if (info.GetAttributeBoolean("filesystem::readonly")) { node.IsReadOnly = true; } else if (info.GetAttributeBoolean("access::can-execute")) { node.IsExecutable = true; } else { node.TypeColour = NodeManager.GetColourForNode(node); } } node.ModifyTime = ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::modified"))); //Console.WriteLine(node.File + " : " + node.ModifyTime.ToString("MMMM dd, yyyy")); string previewPath = info.GetAttributeByteString("thumbnail::path"); if (previewPath != null) { node.ThumbFileName = previewPath; } return(node); }
public void EmitEvent(GLib.File child, GLib.File other_file, GLib.FileMonitorEvent event_type) { g_file_monitor_emit_event(Handle, child == null ? IntPtr.Zero : child.Handle, other_file == null ? IntPtr.Zero : other_file.Handle, (int)event_type); }