Пример #1
0
        public GLib.FileInfo Dup()
        {
            IntPtr raw_ret = g_file_info_dup(Handle);

            GLib.FileInfo ret = GLib.Object.GetObject(raw_ret) as GLib.FileInfo;
            return(ret);
        }
Пример #2
0
        private static Gdk.Pixbuf PlatformGetFileIcon(string path)
        {
            Gdk.Pixbuf icon = null;

            var info  = new GLib.FileInfo(Gtk3Wrapper.g_file_query_info(Gtk3Wrapper.g_file_new_for_path(path), "standard::*", 0, new IntPtr(), new IntPtr()));
            var sicon = info.Icon.ToString().Split(' ');

            for (int i = sicon.Length - 1; i >= 1; i--)
            {
                try
                {
                    icon = _theme.LoadIcon(sicon[i], 16, 0);
                    if (icon != null)
                    {
                        break;
                    }
                }
                catch { }
            }

            if (icon == null)
            {
                throw new Exception();
            }

            return(icon);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public GLib.IFile GetChild(GLib.FileInfo info)
        {
            IntPtr raw_ret = g_file_enumerator_get_child(Handle, info == null ? IntPtr.Zero : info.Handle);

            GLib.IFile ret = GLib.FileAdapter.GetObject(raw_ret, false);
            return(ret);
        }
Пример #5
0
        public static Pixbuf GetIcon(string fileName)
        {
            #if GTK3
            GLib.FileInfo info = new GLib.FileInfo(Gtk3Wrapper.g_file_query_info(Gtk3Wrapper.g_file_new_for_path(fileName), "standard::*", 0, new IntPtr(), new IntPtr()));

            try
            {
                string[] sicon = info.Icon.ToString().Split(' ');

                for(int i = sicon.Length - 1;i >= 1;i--)
                {
                    try
                    {
                        var icon = theme.LoadIcon(sicon[i], 16, (IconLookupFlags)0);

                        if(icon != null)
                            return icon;
                    }
                    catch { }
                }
            }
            catch { }
            return theme.LoadIcon("text-x-generic", 16, (IconLookupFlags)0);
            #endif

            return new Pixbuf(null, "MonoGame.Tools.Pipeline.Icons.blueprint.png");
        }
Пример #6
0
        public static Pixbuf GetIcon(string fileName)
        {
            #if GTK3
            GLib.FileInfo info = new GLib.FileInfo(Gtk3Wrapper.g_file_query_info(Gtk3Wrapper.g_file_new_for_path(fileName), "standard::*", 0, new IntPtr(), new IntPtr()));

            try
            {
                string[] sicon = info.Icon.ToString().Split(' ');

                for (int i = sicon.Length - 1; i >= 1; i--)
                {
                    try
                    {
                        var icon = theme.LoadIcon(sicon[i], 16, (IconLookupFlags)0);

                        if (icon != null)
                        {
                            return(icon);
                        }
                    }
                    catch { }
                }
            }
            catch { }
            return(theme.LoadIcon("text-x-generic", 16, (IconLookupFlags)0));
            #endif

            return(new Pixbuf(null, "MonoGame.Tools.Pipeline.Icons.blueprint.png"));
        }
Пример #7
0
        public unsafe GLib.FileInfo NextFile(GLib.Cancellable cancellable)
        {
            IntPtr error   = IntPtr.Zero;
            IntPtr raw_ret = g_file_enumerator_next_file(Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);

            GLib.FileInfo ret = GLib.Object.GetObject(raw_ret) as GLib.FileInfo;
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
Пример #8
0
        public unsafe bool Iterate(GLib.FileInfo out_info, GLib.IFile out_child, GLib.Cancellable cancellable)
        {
            IntPtr error   = IntPtr.Zero;
            bool   raw_ret = g_file_enumerator_iterate(Handle, out_info == null ? IntPtr.Zero : out_info.Handle, out_child == null ? IntPtr.Zero : ((out_child is GLib.Object) ? (out_child as GLib.Object).Handle : (out_child as GLib.FileAdapter).Handle), cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);
            bool   ret     = raw_ret;

            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
Пример #9
0
        public unsafe GLib.FileInfo QueryInfoFinish(GLib.IAsyncResult result)
        {
            IntPtr error   = IntPtr.Zero;
            IntPtr raw_ret = g_file_output_stream_query_info_finish(Handle, result == null ? IntPtr.Zero : ((result is GLib.Object) ? (result as GLib.Object).Handle : (result as GLib.AsyncResultAdapter).Handle), out error);

            GLib.FileInfo ret = GLib.Object.GetObject(raw_ret) as GLib.FileInfo;
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
Пример #10
0
        public unsafe GLib.FileInfo QueryInfo(string attributes, GLib.Cancellable cancellable)
        {
            IntPtr native_attributes = GLib.Marshaller.StringToPtrGStrdup(attributes);
            IntPtr error             = IntPtr.Zero;
            IntPtr raw_ret           = g_file_output_stream_query_info(Handle, native_attributes, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);

            GLib.FileInfo ret = GLib.Object.GetObject(raw_ret) as GLib.FileInfo;
            GLib.Marshaller.Free(native_attributes);
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
Пример #11
0
        private bool InternalLocalFileSetAttributes(string filename, GLib.FileInfo info, GLib.FileQueryInfoFlags flags, GLib.Cancellable cancellable)
        {
            LocalFileSetAttributesNativeDelegate unmanaged = class_abi.BaseOverride <LocalFileSetAttributesNativeDelegate>(this.LookupGType(), "local_file_set_attributes");

            if (unmanaged == null)
            {
                throw new InvalidOperationException("No base method to invoke");
            }

            IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename);
            IntPtr error           = IntPtr.Zero;
            bool   __result        = unmanaged(this.Handle, native_filename, info == null ? IntPtr.Zero : info.Handle, (int)flags, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);

            GLib.Marshaller.Free(native_filename);
            return(__result);
        }
Пример #12
0
        public bool Step()
        {
            if (done)
            {
                return(false);
            }

            GLib.FileInfo info = GLib.FileFactory.NewForUri(item.DefaultVersion.Uri).QueryInfo("access::can-write", GLib.FileQueryInfoFlags.None, null);
            if (!info.GetAttributeBoolean("access::can-write"))
            {
                throw new RotateException(Catalog.GetString("Unable to rotate readonly file"), item.DefaultVersion.Uri, true);
            }

            Rotate(item.DefaultVersion.Uri, direction);

            done = true;
            return(!done);
        }
Пример #13
0
        private bool InternalLocalFileSetAttributes(string filename, GLib.FileInfo info, GLib.FileQueryInfoFlags flags, GLib.Cancellable cancellable)
        {
            LocalFileSetAttributesNativeDelegate unmanaged = null;

            unsafe {
                IntPtr *raw_ptr = (IntPtr *)(((long)this.LookupGType().GetThresholdType().GetClassPtr()) + (long)class_abi.GetFieldOffset("local_file_set_attributes"));
                unmanaged = (LocalFileSetAttributesNativeDelegate)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(LocalFileSetAttributesNativeDelegate));
            }
            if (unmanaged == null)
            {
                throw new InvalidOperationException("No base method to invoke");
            }

            IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename);
            IntPtr error           = IntPtr.Zero;
            bool   __result        = unmanaged(this.Handle, native_filename, info == null ? IntPtr.Zero : info.Handle, (int)flags, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);

            GLib.Marshaller.Free(native_filename);
            return(__result);
        }
Пример #14
0
        public static IImageLoader Create(SafeUri uri)
        {
            string path      = uri.AbsolutePath;
            string extension = System.IO.Path.GetExtension(path).ToLower();

            System.Type  t;
            IImageLoader loader;

            if (!name_table.TryGetValue(extension, out t))
            {
                GLib.FileInfo info = GLib.FileFactory.NewForUri(uri).QueryInfo("standard::type,standard::content-type", GLib.FileQueryInfoFlags.None, null);
                if (!name_table.TryGetValue(info.ContentType, out t))
                {
                    throw new Exception("Loader requested for unknown file type: " + extension);
                }
            }

            loader = (IImageLoader)System.Activator.CreateInstance(t);

            return(loader);
        }
Пример #15
0
        private static Eto.Drawing.Image PlatformGetFileIcon(string path, bool exists)
        {
            Gdk.Pixbuf icon = null;

            try
            {
                var info  = new GLib.FileInfo(Gtk3Wrapper.g_file_query_info(Gtk3Wrapper.g_file_new_for_path(path), "standard::*", 0, new IntPtr(), new IntPtr()));
                var sicon = info.Icon.ToString().Split(' ');

                for (int i = sicon.Length - 1; i >= 1; i--)
                {
                    try
                    {
                        icon = _theme.LoadIcon(sicon[i], 16, 0);
                        if (icon != null)
                        {
                            break;
                        }
                    }
                    catch { }
                }
            }
            catch { }

            if (icon == null)
            {
                icon = _theme.LoadIcon("text-x-generic", 16, 0);
            }


            if (!exists)
            {
                icon = icon.Copy();
                _iconMissing.Composite(icon, 8, 8, 8, 8, 8, 8, 0.5, 0.5, Gdk.InterpType.Tiles, 255);
            }

            return(new Bitmap(new BitmapHandler(icon)));
        }
Пример #16
0
        private void InternalLocalFileAddInfo(string filename, ulong device, GLib.FileAttributeMatcher attribute_matcher, GLib.FileInfo info, GLib.Cancellable cancellable, IntPtr extra_data, out GLib.DestroyNotify free_extra_data)
        {
            LocalFileAddInfoNativeDelegate unmanaged = null;

            unsafe {
                IntPtr *raw_ptr = (IntPtr *)(((long)this.LookupGType().GetThresholdType().GetClassPtr()) + (long)class_abi.GetFieldOffset("local_file_add_info"));
                unmanaged = (LocalFileAddInfoNativeDelegate)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(LocalFileAddInfoNativeDelegate));
            }
            if (unmanaged == null)
            {
                throw new InvalidOperationException("No base method to invoke");
            }

            IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename);

            unmanaged(this.Handle, native_filename, device, attribute_matcher == null ? IntPtr.Zero : attribute_matcher.Handle, info == null ? IntPtr.Zero : info.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, extra_data, out free_extra_data);
            GLib.Marshaller.Free(native_filename);
        }
Пример #17
0
        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);
        }
Пример #18
0
 protected virtual void OnLocalFileAddInfo(string filename, ulong device, GLib.FileAttributeMatcher attribute_matcher, GLib.FileInfo info, GLib.Cancellable cancellable, IntPtr extra_data, out GLib.DestroyNotify free_extra_data)
 {
     InternalLocalFileAddInfo(filename, device, attribute_matcher, info, cancellable, extra_data, out free_extra_data);
 }
Пример #19
0
 public void CopyInto(GLib.FileInfo dest_info)
 {
     g_file_info_copy_into(Handle, dest_info == null ? IntPtr.Zero : dest_info.Handle);
 }
Пример #20
0
        private void InternalLocalFileAddInfo(string filename, ulong device, GLib.FileAttributeMatcher attribute_matcher, GLib.FileInfo info, GLib.Cancellable cancellable, IntPtr extra_data, out GLib.DestroyNotify free_extra_data)
        {
            LocalFileAddInfoNativeDelegate unmanaged = class_abi.BaseOverride <LocalFileAddInfoNativeDelegate>(this.LookupGType(), "local_file_add_info");

            if (unmanaged == null)
            {
                throw new InvalidOperationException("No base method to invoke");
            }

            IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename);

            unmanaged(this.Handle, native_filename, device, attribute_matcher == null ? IntPtr.Zero : attribute_matcher.Handle, info == null ? IntPtr.Zero : info.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, extra_data, out free_extra_data);
            GLib.Marshaller.Free(native_filename);
        }
Пример #21
0
 protected virtual bool OnLocalFileSetAttributes(string filename, GLib.FileInfo info, GLib.FileQueryInfoFlags flags, GLib.Cancellable cancellable)
 {
     return(InternalLocalFileSetAttributes(filename, info, flags, cancellable));
 }