Пример #1
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);
            }
        }
Пример #2
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);
        }