Esempio n. 1
0
        public static string FileTypeInfo(string fileName)
        {
            FileTypeHelper.SHFILEINFO info = new FileTypeHelper.SHFILEINFO();
            uint dwFileAttributes          = FileTypeHelper.FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL;
            uint uFlags = (uint)(FileTypeHelper.SHGFI.SHGFI_TYPENAME | FileTypeHelper.SHGFI.SHGFI_USEFILEATTRIBUTES);

            FileTypeHelper.SHGetFileInfo(fileName, dwFileAttributes, ref info, (uint)Marshal.SizeOf(info), uFlags);

            return(info.szTypeName);
        }
Esempio n. 2
0
        private static IEnumerable <HintItem> getDirHint(HintContext context)
        {
            var list    = new List <HintItem>();
            var pattern = context.LastSegment;

            string dirPath       = context.CurrentDir;
            string pathInPattern = "";

            if (pattern.Contains("/"))
            {
                return(list);
            }

            if (pattern.Contains("\\"))
            {
                var index = pattern.LastIndexOf('\\');
                pathInPattern = pattern.Substring(0, index + 1);
                pattern       = pattern.Substring(index + 1);

                dirPath = Path.Combine(context.CurrentDir, pathInPattern);
                if (!Directory.Exists(dirPath))
                {
                    return(Enumerable.Empty <HintItem>());
                }
            }

            var di = new DirectoryInfo(dirPath);

            foreach (var item in di.EnumerateDirectories(pattern + "*"))
            {
                list.Add(new HintItem
                {
                    Category = "Directory",
                    Word     = pathInPattern + item.Name,
                });
            }

            foreach (var item in di.EnumerateFiles(pattern + "*"))
            {
                list.Add(new HintItem
                {
                    Category    = "File",
                    Word        = pathInPattern + item.Name,
                    Description = FileTypeHelper.FileTypeInfo(item.FullName)
                });
            }

            return(list);
        }