Beispiel #1
0
        public static ShellAPI.CSIDL?ShellFolderToCSIDL(Environment.SpecialFolder spFolder)
        {
            foreach (var val in Enum.GetValues(typeof(KnownFolderIds)))
            {
                var csidlAttributes = EnumAttributeUtils <CsidlAttribute, KnownFolderIds> .FindAllAttributes(val).ToArray();

                var spFolderAttributes = EnumAttributeUtils <SpecialFolderAttribute, KnownFolderIds> .FindAllAttributes(val).ToArray();

                for (int i = 0; i < spFolderAttributes.Length; i++)
                {
                    if (spFolderAttributes[i].SpecialFolder == spFolder)
                    {
                        if (csidlAttributes.Length >= spFolderAttributes.Length)
                        {
                            return(csidlAttributes[i].CSIDL);
                        }
                        else if (spFolderAttributes.Length >= 0)
                        {
                            return(csidlAttributes[0].CSIDL);
                        }
                    }
                }
            }
            return(null);

            //var enumerator = _shellFolderLookupDic.Value.GetEnumerator();

            //while (enumerator.MoveNext())
            //    if (enumerator.Current.Key.Equals(shellFolder))
            //        return enumerator.Current.Value;

            //throw new ArgumentException("This SpecialFolder path not supported");
        }
Beispiel #2
0
        //private static readonly Lazy<Dictionary<Environment.SpecialFolder, ShellAPI.CSIDL>> _shellFolderLookupDic =
        //    new Lazy<Dictionary<Environment.SpecialFolder, ShellAPI.CSIDL>>(() => constructShellFolderLookupDic());
        //private static readonly Lazy<Dictionary<Environment.SpecialFolder, string>> _directoryFullNameLookupDic =
        //    new Lazy<Dictionary<Environment.SpecialFolder, string>>(() => constructDirectoryFullNameLookupDic());
        //private static readonly Lazy<Dictionary<string, KnownFolder>> _pathToKnownFolderLookupDic =
        //    new Lazy<Dictionary<string, KnownFolder>>(() => constructpathToKnownFolderLookupDic());

        private static Dictionary <string, KnownFolder> constructpathToKnownFolderLookupDic()
        {
            Dictionary <string, KnownFolder> dic = new Dictionary <string, KnownFolder>();

            foreach (var kfId in Enum.GetValues(typeof(KnownFolderIds)))
            {
                var category = EnumAttributeUtils <FolderCategoryAttribute, KnownFolderIds> .FindAttribute(kfId);

                if (category == null)
                {
                    Debug.WriteLine(String.Format("Attribute {0} does not have FolderCategoryAttribute", kfId));
                }
                else
                {
                    if (category.Category != KnownFolderCategory.Virtual)
                    {
                        KnownFolder kf   = KnownFolder.FromKnownFolderId((KnownFolderIds)kfId);
                        string      path = kf.Path;
                        if (!dic.ContainsKey(path))
                        {
                            dic.Add(path, kf);
                        }
                    }
                }
            }

            //foreach (var kf in KnownFolder.GetKnownFolders())
            //    if (kf.Category != KnownFolderCategory.Virtual)
            //    {
            //        string path = kf.Path;
            //        if (path != null)
            //        {
            //            if (!dic.ContainsKey(path))
            //                dic.Add(path, kf);
            //        }
            //    }

            return(dic);
        }
        public static KnownFolder FromKnownFolderId(KnownFolderIds kfId)
        {
            var guidAtb = EnumAttributeUtils <KnownFolderGuidAttribute, KnownFolderIds> .FindAttribute(kfId);

            return(FromKnownFolderId(guidAtb.Guid));
        }
Beispiel #4
0
 public DirectoryInfoEx(KnownFolderIds knownFolderId)
     : this(KnownFolder.FromKnownFolderId(
                EnumAttributeUtils <KnownFolderGuidAttribute, KnownFolderIds> .FindAttribute(knownFolderId).Guid))
 {
 }