public void Reset()
 {
     if (this.Reader != null)
     {
         this.Reader.Close();
     }
     this.Reader = null;
     if (this.Owner.FIniSection == null)
     {
         throw new ObjectDisposedException("IniResourceReader");
     }
 }
示例#2
0
        public static IVirtualItem FromUrlFile(Stream urlFileContent, IVirtualFolder parent)
        {
            FtpContext context = new FtpContext();
            Uri absoluteUri = null;
            string userName = null;
            byte[] source = null;
            using (IniReader reader = new IniReader(new StreamReader(urlFileContent, Encoding.ASCII)))
            {
                while (reader.Read())
                {
                    if (reader.ElementType != IniElementType.KeyValuePair)
                    {
                        continue;
                    }
                    if (reader.CheckCurrentKey("InternetShortcut", "URL"))
                    {
                        absoluteUri = new Uri(reader.CurrentValue);
                    }
                    switch (reader.CheckCurrentKey("FTP", new string[] { "UsePassive", "UseCache", "UsePrefetch", "StoreCredential", "UploadFileNameCasing", "Encoding" }))
                    {
                        case 0:
                            context.UsePassive = Convert.ToBoolean(reader.CurrentValue);
                            break;

                        case 1:
                            context.UseCache = Convert.ToBoolean(reader.CurrentValue);
                            break;

                        case 2:
                            context.UsePrefetch = Convert.ToBoolean(reader.CurrentValue);
                            break;

                        case 3:
                            context.StoreCredential = Convert.ToBoolean(reader.CurrentValue);
                            break;

                        case 4:
                            context.UploadFileNameCasing = (CharacterCasing) System.Enum.Parse(typeof(CharacterCasing), reader.CurrentValue);
                            break;

                        case 5:
                            context.ListEncoding = Encoding.GetEncoding(reader.CurrentValue);
                            break;
                    }
                    switch (reader.CheckCurrentKey("Credential", new string[] { "UserName", "Password" }))
                    {
                        case 0:
                            userName = reader.CurrentValue;
                            break;

                        case 1:
                            source = ByteArrayHelper.Parse(reader.CurrentValue);
                            break;
                    }
                }
            }
            if (userName != null)
            {
                context.Credentials = new NetworkCredential(userName, (source == null) ? string.Empty : SimpleEncrypt.DecryptString(source, DES.Create()));
            }
            if ((absoluteUri != null) && (absoluteUri.Scheme == Uri.UriSchemeFtp))
            {
                return FromUri(context, absoluteUri, VirtualItemType.Unknown, parent);
            }
            return null;
        }
 public bool MoveNext()
 {
     if (this.Owner.FIniSection == null)
     {
         if (this.Reader != null)
         {
             this.Reader.Close();
         }
         this.Reader = null;
         throw new ObjectDisposedException("IniResourceReader");
     }
     if (!(this.Finished || (this.Reader != null)))
     {
         this.Reader = new IniReader(new StreamReader(this.Owner.FIniPath));
         this.Finished = !this.Reader.MoveToSection(this.Owner.FIniSection);
     }
     if (!this.Finished)
     {
         this.Finished = !this.Reader.Read();
     }
     while (!this.Finished && (this.Reader.ElementType != IniElementType.KeyValuePair))
     {
         this.Finished = !this.Reader.Read() || (this.Reader.ElementType == IniElementType.Section);
     }
     if (this.Finished && (this.Reader != null))
     {
         this.Reader.Close();
         this.Reader = null;
     }
     return !this.Finished;
 }
        public override Image GetFolderIcon(string folderName, Size size)
        {
            StreamReader reader;
            char[] chArray;
            if (folderName == null)
            {
                throw new ArgumentNullException("folderName");
            }
            Image defaultIcon = null;
            FileInfo info = null;
            if (System.IO.Directory.Exists(folderName))
            {
                try
                {
                    if ((System.IO.File.GetAttributes(folderName) & FileAttributes.ReparsePoint) > 0)
                    {
                        ReparsePointInfo reparsePointInfo = ReparsePoint.GetReparsePointInfo(folderName);
                        if (reparsePointInfo.ReparseType == ReparseType.MountPoint)
                        {
                            try
                            {
                                VolumeInfo info3 = VolumeCache.Get(reparsePointInfo.Target);
                                defaultIcon = this.GetVolumeIcon(info3.VolumeType, '\0', ref size);
                            }
                            catch
                            {
                                defaultIcon = this.GetDefaultIcon(DefaultIcon.Drive, size);
                            }
                        }
                    }
                }
                catch
                {
                }
                if (defaultIcon == null)
                {
                    info = new FileInfo(Path.Combine(folderName, "desktop.ini"));
                }
            }
            if (((info == null) || !info.Exists) || ((info.Attributes & (FileAttributes.System | FileAttributes.Hidden)) <= 0))
            {
                goto Label_048D;
            }
            string currentValue = null;
            string a = null;
            string path = null;
            string str4 = null;
            int result = 0;
            ShellFolderType unknown = ShellFolderType.Unknown;
            try
            {
                reader = info.OpenText();
            }
            catch
            {
                reader = null;
            }
            if (reader != null)
            {
                using (IniReader reader2 = new IniReader(reader, true))
                {
                    bool flag = false;
                    while (reader2.Read())
                    {
                        bool flag2 = false;
                        switch (reader2.ElementType)
                        {
                            case IniElementType.Section:
                                if (!flag)
                                {
                                    break;
                                }
                                flag2 = true;
                                goto Label_02BF;

                            case IniElementType.KeyValuePair:
                                if (flag)
                                {
                                    switch (reader2.CurrentKey.ToLower())
                                    {
                                        case "clsid":
                                            goto Label_0239;

                                        case "clsid2":
                                            goto Label_0254;

                                        case "iconresource":
                                            goto Label_025F;

                                        case "iconfile":
                                            goto Label_026F;

                                        case "iconindex":
                                            goto Label_027F;

                                        case "foldertype":
                                            goto Label_0298;

                                        case "uiclsid":
                                            goto Label_02B2;
                                    }
                                }
                                goto Label_02BF;

                            default:
                                goto Label_02BF;
                        }
                        flag = reader2.CheckCurrentSection(".ShellClassInfo");
                        goto Label_02BF;
                    Label_0239:
                        if (string.IsNullOrEmpty(currentValue))
                        {
                            currentValue = reader2.CurrentValue;
                        }
                        goto Label_02BF;
                    Label_0254:
                        a = reader2.CurrentValue;
                        goto Label_02BF;
                    Label_025F:
                        path = Environment.ExpandEnvironmentVariables(reader2.CurrentValue);
                        goto Label_02BF;
                    Label_026F:
                        str4 = Environment.ExpandEnvironmentVariables(reader2.CurrentValue);
                        goto Label_02BF;
                    Label_027F:
                        if (!int.TryParse(reader2.CurrentValue, out result))
                        {
                            result = 0;
                        }
                        goto Label_02BF;
                    Label_0298:
                        if (!EnumHelper.TryParse<ShellFolderType>(reader2.CurrentValue, true, out unknown))
                        {
                            unknown = ShellFolderType.Unknown;
                        }
                        goto Label_02BF;
                    Label_02B2:
                        currentValue = reader2.CurrentValue;
                    Label_02BF:
                        if (flag2)
                        {
                            goto Label_02F5;
                        }
                    }
                }
            }
        Label_02F5:
            chArray = null;
            if ((path != null) && (path.IndexOfAny(chArray ?? (chArray = Path.GetInvalidPathChars())) < 0))
            {
                if (!Path.IsPathRooted(path))
                {
                    path = Path.Combine(folderName, path);
                }
                IconLocation iconLocation = IconLocation.TryParse(path);
                if (iconLocation != null)
                {
                    defaultIcon = LoadIconFromLocation2(iconLocation, ref size);
                }
            }
            if (((defaultIcon == null) && (str4 != null)) && (str4.IndexOfAny(chArray ?? (chArray = Path.GetInvalidPathChars())) < 0))
            {
                if (!Path.IsPathRooted(str4))
                {
                    str4 = Path.Combine(folderName, str4);
                }
                defaultIcon = LoadIconFromLocation2(new IconLocation(str4, result), ref size);
            }
            if ((defaultIcon == null) && (currentValue != null))
            {
                defaultIcon = this.GetClsidIcon(currentValue, ref size);
            }
            if ((defaultIcon == null) && string.Equals(a, "{0AFACED1-E828-11D1-9187-B532F1E9575D}", StringComparison.OrdinalIgnoreCase))
            {
                string str5 = Path.Combine(folderName, "target.lnk");
                if (System.IO.File.Exists(str5))
                {
                    defaultIcon = this.GetFileIcon(str5, size);
                }
            }
            if ((defaultIcon == null) && (unknown != ShellFolderType.Unknown))
            {
                switch (unknown)
                {
                    case ShellFolderType.Documents:
                    case ShellFolderType.MyDocuments:
                        defaultIcon = this.GetDefaultIcon(DefaultIcon.MyDocuments, size);
                        goto Label_048D;

                    case ShellFolderType.Pictures:
                    case ShellFolderType.MyPictures:
                    case ShellFolderType.PhotoAlbum:
                        defaultIcon = this.GetDefaultIcon(DefaultIcon.MyPictures, size);
                        goto Label_048D;

                    case ShellFolderType.Music:
                    case ShellFolderType.MyMusic:
                    case ShellFolderType.MusicArtist:
                    case ShellFolderType.MusicAlbum:
                        defaultIcon = this.GetDefaultIcon(DefaultIcon.MyMusic, size);
                        goto Label_048D;

                    case ShellFolderType.Videos:
                    case ShellFolderType.MyVideos:
                    case ShellFolderType.VideoAlbum:
                        defaultIcon = this.GetDefaultIcon(DefaultIcon.MyVideos, size);
                        goto Label_048D;
                }
            }
        Label_048D:
            if (defaultIcon == null)
            {
                defaultIcon = this.GetDefaultIcon(DefaultIcon.Folder, size);
            }
            return defaultIcon;
        }