public bool Load(MagnetLink magnetLink)
        {
            if (magnetLink == null)
            {
                return(false);
            }
            if (magnetLink.Hash == null)
            {
                return(false);
            }

            HashString = magnetLink.HashString;

            if (magnetLink.Trackers != null)
            {
                foreach (string tracker in magnetLink.Trackers)
                {
                    AnnounceList.Add(tracker);
                }
            }

            return(true);
        }
        /// <summary>  读取结构 </summary>
        private bool GetValueText(byte[] buffer, ref int starIndex, string key)
        {
            switch (key)
            {
            case "ANNOUNCE":
                Announce = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "ANNOUNCE-LIST":
                int       listCount = 0;
                ArrayList _tempList = GetKeyData(buffer, ref starIndex, ref listCount);
                for (int i = 0; i != _tempList.Count; i++)
                {
                    AnnounceList.Add(_tempList[i].ToString());
                }
                break;

            case "CREATION DATE":
                object date = GetKeyNumb(buffer, ref starIndex).ToString();
                if (date == null)
                {
                    if (OpenError.Length == 0)
                    {
                        OpenError = "CREATION DATE 返回不是数字类型";
                    }
                    return(false);
                }
                CreateTime = CreateTime.AddTicks(long.Parse(date.ToString()));
                break;

            case "CODEPAGE":
                object codePageNumb = GetKeyNumb(buffer, ref starIndex);
                if (codePageNumb == null)
                {
                    if (OpenError.Length == 0)
                    {
                        OpenError = "CODEPAGE 返回不是数字类型";
                    }
                    return(false);
                }
                CodePage = long.Parse(codePageNumb.ToString());
                break;

            case "ENCODING":
                Encoding = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "CREATED BY":
                CreatedBy = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "COMMENT":
                Comment = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "COMMENT.UTF-8":
                CommentUTF8 = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "INFO":
                int fileListCount = 0;
                GetFileInfo(buffer, ref starIndex, ref fileListCount);
                break;

            case "NAME":
                Name = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "NAME.UTF-8":
                NameUTF8 = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "PIECE LENGTH":
                object pieceLengthNumb = GetKeyNumb(buffer, ref starIndex);
                if (pieceLengthNumb == null)
                {
                    if (OpenError.Length == 0)
                    {
                        OpenError = "PIECE LENGTH 返回不是数字类型";
                    }
                    return(false);
                }
                PieceLength = long.Parse(pieceLengthNumb.ToString());
                break;

            case "PIECES":
                Pieces = GetKeyByte(buffer, ref starIndex);
                break;

            case "PUBLISHER":
                Publisher = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "PUBLISHER.UTF-8":
                PublisherUTF8 = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "PUBLISHER-URL":
                PublisherUrl = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "PUBLISHER-URL.UTF-8":
                PublisherUrlUTF8 = GetKeyText(buffer, ref starIndex).ToString();
                break;

            case "NODES":
                int       nodesCount = 0;
                ArrayList _nodesList = GetKeyData(buffer, ref starIndex, ref nodesCount);
                int       ipCount    = _nodesList.Count / 2;
                for (int i = 0; i != ipCount; i++)
                {
                    Notes.Add(_nodesList[i * 2] + ":" + _nodesList[(i * 2) + 1]);
                }
                break;

            default:
                return(false);
            }
            return(true);
        }
        public bool Load(Stream stream)
        {
            _root = BencodingUtils.Decode(stream);
            if (_root == null)
            {
                return(false);
            }

            BDict dictRoot = (_root as BDict);

            if (dictRoot == null)
            {
                return(false);
            }

            if (dictRoot.ContainsKey("announce"))
            {
                Announce = (BString)dictRoot["announce"];
            }

            if (dictRoot.ContainsKey("announce-list"))
            {
                BList announceList = (BList)dictRoot["announce-list"];
                foreach (IBencodingType type in announceList)
                {
                    if (type is BString)
                    {
                        AnnounceList.Add(type as BString);
                    }
                    else
                    {
                        BList list = type as BList;
                        if (list == null)
                        {
                            continue;
                        }

                        BList listType = list;
                        foreach (IBencodingType bencodingType in listType)
                        {
                            BString s = (BString)bencodingType;
                            AnnounceList.Add(s);
                        }
                    }
                }
            }

            if (dictRoot.ContainsKey("comment"))
            {
                Comment = (BString)dictRoot["comment"];
            }

            if (dictRoot.ContainsKey("created by"))
            {
                CreatedBy = (BString)dictRoot["created by"];
            }

            if (dictRoot.ContainsKey("creation date"))
            {
                long ts = (BInt)dictRoot["creation date"];
                CreationDate = new DateTime(1970, 1, 1).AddSeconds(ts);
            }

            if (dictRoot.ContainsKey("info"))
            {
                BDict infoDict = (BDict)dictRoot["info"];

                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    byte[] str = BencodingUtils.EncodeBytes(infoDict);
                    Hash = sha1.ComputeHash(str);
                }

                if (infoDict.ContainsKey("files"))
                {
                    //multi file mode
                    BList fileList = (BList)infoDict["files"];
                    foreach (IBencodingType bencodingType in fileList)
                    {
                        BDict fileDict = (BDict)bencodingType;

                        String filename = string.Empty;
                        Int64  filesize = default(Int64);

                        if (fileDict.ContainsKey("path"))
                        {
                            BList filenameList = (BList)fileDict["path"];
                            foreach (IBencodingType type in filenameList)
                            {
                                filename += (BString)type;
                                filename += "\\";
                            }
                            filename = filename.Trim('\\');
                        }

                        if (fileDict.ContainsKey("length"))
                        {
                            filesize = (BInt)fileDict["length"];
                        }

                        Files.Add(filename, filesize);
                    }
                }

                if (infoDict.ContainsKey("name"))
                {
                    Name = (BString)infoDict["name"];
                    if (Files.Count == 0 && infoDict.ContainsKey("length"))
                    {
                        Files.Add(Name, (BInt)infoDict["length"]);
                    }
                }

                if (infoDict.ContainsKey("private"))
                {
                    BInt isPrivate = (BInt)infoDict["private"];
                    Private = isPrivate != 0;
                }

                if (infoDict.ContainsKey("pieces"))
                {
                    BString pieces = (BString)infoDict["pieces"];
                    for (int x = 0; x < pieces.ByteValue.Length; x += 20)
                    {
                        byte[] hash = pieces.ByteValue.GetBytes(x, 20);
                        PieceHashes.Add(hash);
                    }
                }

                if (infoDict.ContainsKey("piece length"))
                {
                    PieceSize = (BInt)infoDict["piece length"];
                }
            }

            return(true);
        }
        public bool Load(Stream stream)
        {
            _root = BencodingUtils.Decode(stream);
            if (_root == null)
            {
                return(false);
            }

            var dictRoot = (_root as BDict);

            if (dictRoot == null)
            {
                return(false);
            }

            if (dictRoot.ContainsKey(ANNOUNCE_KEY))
            {
                Announce = (BString)dictRoot[ANNOUNCE_KEY];
            }

            if (dictRoot.ContainsKey(ANNOUNCE_LIST_KEY))
            {
                var announceList = (BList)dictRoot[ANNOUNCE_LIST_KEY];
                foreach (IBencodingType type in announceList)
                {
                    if (type is BString)
                    {
                        AnnounceList.Add(type as BString);
                    }
                    else
                    {
                        var list = type as BList;
                        if (list == null)
                        {
                            continue;
                        }

                        var listType = list;
                        foreach (IBencodingType bencodingType in listType)
                        {
                            var s = (BString)bencodingType;
                            AnnounceList.Add(s);
                        }
                    }
                }
            }

            if (dictRoot.ContainsKey(COMMENT_KEY))
            {
                Comment = (BString)dictRoot[COMMENT_KEY];
            }

            if (dictRoot.ContainsKey(CREATED_BY_KEY))
            {
                CreatedBy = (BString)dictRoot[CREATED_BY_KEY];
            }

            if (dictRoot.ContainsKey(CREATION_DATE_KEY))
            {
                long ts = (BInt)dictRoot[CREATION_DATE_KEY];
                CreationDate = new DateTime(1970, 1, 1).AddSeconds(ts);
            }

            if (dictRoot.ContainsKey(INFO_KEY))
            {
                var infoDict = (BDict)dictRoot[INFO_KEY];

                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    var str = BencodingUtils.EncodeBytes(infoDict);
                    Hash = sha1.ComputeHash(str);
                }

                if (infoDict.ContainsKey(FILES_KEY))
                {
                    //multi file mode
                    var fileList = (BList)infoDict[FILES_KEY];
                    foreach (IBencodingType bencodingType in fileList)
                    {
                        var fileDict = (BDict)bencodingType;

                        var filename = string.Empty;
                        var filesize = default(Int64);

                        if (fileDict.ContainsKey(PATH_KEY))
                        {
                            var filenameList = (BList)fileDict[PATH_KEY];
                            foreach (IBencodingType type in filenameList)
                            {
                                filename += (BString)type;
                                filename += "\\";
                            }
                            filename = filename.Trim('\\');
                        }

                        if (fileDict.ContainsKey(LENGTH_KEY))
                        {
                            filesize = (BInt)fileDict[LENGTH_KEY];
                        }

                        Files.Add(filename, filesize);
                    }
                }

                if (infoDict.ContainsKey(NAME_KEY))
                {
                    Name = (BString)infoDict[NAME_KEY];
                    if (Files.Count == 0 && infoDict.ContainsKey(LENGTH_KEY))
                    {
                        Files.Add(Name, (BInt)infoDict[LENGTH_KEY]);
                    }
                }

                if (infoDict.ContainsKey(PRIVATE_KEY))
                {
                    var isPrivate = (BInt)infoDict[PRIVATE_KEY];
                    Private = isPrivate != 0;
                }

                if (infoDict.ContainsKey(PIECES_KEY))
                {
                    var pieces = (BString)infoDict[PIECES_KEY];
                    for (var x = 0; x < pieces.ByteValue.Length; x += 20)
                    {
                        var hash = pieces.ByteValue.GetBytes(x, 20);
                        PieceHashes.Add(hash);
                    }
                }

                if (infoDict.ContainsKey(PIECE_LENGTH_KEY))
                {
                    PieceSize = (BInt)infoDict[PIECE_LENGTH_KEY];
                }
            }

            return(true);
        }