Beispiel #1
0
        public static bool TryGet(string extension, out FileIcon icon)
        {
            if (extension.StartsWith("."))
            {
                extension = extension.Remove(0, 1);
            }
            extension = extension.ToLower();
            XmlDocument doc = hapConfig.Current.MyFiles.KnownIcons;

            icon = null;
            if (doc.SelectSingleNode("/Icons/Icon[@extension='" + extension + "']") == null)
            {
                return(false);
            }
            else
            {
                icon           = new FileIcon();
                icon.Extension = extension;
                XmlNode n = doc.SelectSingleNode("/Icons/Icon[@extension='" + extension + "']");
                icon.ContentType = n.Attributes["contenttype"].Value;
                icon.Icon        = n.Attributes["icon"].Value;
                icon.Type        = n.Attributes["type"].Value;
                return(true);
            }
        }
Beispiel #2
0
        public CBFile(FileInfo file, UNCPath unc, User user)
        {
            Extension = file.Extension;
            Type      = "File";
            Name      = file.Name + (file.Name.Contains(file.Extension) ? "" : file.Extension);

            FileIcon fi;

            if (FileIcon.TryGet(Extension, out fi))
            {
                Type = fi.Type;
                Name = Name.Remove(Name.LastIndexOf(file.Extension));
            }
            if (Type == "File")
            {
                try
                {
                    RegistryKey rkRoot = Registry.ClassesRoot;
                    string      keyref = rkRoot.OpenSubKey(file.Extension).GetValue("").ToString();
                    Type = rkRoot.OpenSubKey(keyref).GetValue("").ToString();
                    Name = Name.Remove(Name.LastIndexOf(file.Extension));
                }
                catch { Type = "File"; }
            }
            if (Type != "File")
            {
                Icon = "images/icons/" + ParseForImage(file);
                if (Icon.EndsWith(".ico"))
                {
                    Icon = "api/mycomputer/" + ParseForImage(file);
                }
            }
            else
            {
                Icon = "images/icons/file.png";
            }
            if (file.Extension.ToLower().Equals(".png") || file.Extension.ToLower().Equals(".jpg") || file.Extension.ToLower().Equals(".jpeg") || file.Extension.ToLower().Equals(".gif") || file.Extension.ToLower().Equals(".bmp") || file.Extension.ToLower().Equals(".wmf"))
            {
                Icon = "api/mycomputer/thumb/" + Converter.UNCtoDrive2(file.FullName, unc, user).Replace('&', '^');
            }
            BType        = ComputerBrowser.BType.File;
            CreatedTime  = file.CreationTime;
            ModifiedTime = file.LastWriteTime;
            Size         = parseLength(file.Length);
            Path         = Converter.UNCtoDrive(file.FullName, unc, user);
        }