Пример #1
0
        private TorrentInfo Load(Stream torrentStream)
        {
            try
            {
                InnerDictionary = (IBencodingDictionary)Bencoding.Parse(torrentStream);

                var info = InnerDictionary.Value["info"] as IBencodingDictionary;

                isMFile = true;

                if (info.ContainsKey("files"))
                {
                    var files = info.Value["files"].Value as IBencodingObject[];

                    _files.AddRange(
                        files.Cast <IBencodingDictionary>()
                        .Select(z => new TorrentFileInfo(
                                    (z.Value["path"].Value as IBencodingObject[])
                                    .Cast <IBencodingObject <string> >().Select(x => x.Value).ToArray(),
                                    (long)z.Value["length"].Value)));
                }
                else
                {
                    _files.Add(new TorrentFileInfo(new string[] { (string)info.Value["name"].Value }, (long)info.Value["length"].Value));
                }
            }
            catch (Exception) { throw new ArgumentException("error torrent file"); }

            return(this);
        }
Пример #2
0
        internal BencodingList(BinaryReader reader)
        {
            _value = new List <IBencodingObject>();
            byte b;

            while ((b = reader.ReadByte()) != Bencoding.EndByte)
            {
                _value.Add(Bencoding.Parse(b, reader));
            }
        }
Пример #3
0
        internal BencodingDictionary(BinaryReader reader)
        {
            _value = new List <KeyValuePair <BencodingString, IBencodingObject> >();
            _dic   = new Dictionary <string, IBencodingObject>();

            byte b;

            while ((b = reader.ReadByte()) != Bencoding.EndByte)
            {
                var key   = new BencodingString(b, reader);
                var value = Bencoding.Parse(reader);
                _value.Add(new KeyValuePair <BencodingString, IBencodingObject>(key, value));
            }
            foreach (var item in _value)
            {
                _dic.Add(item.Key.Value, item.Value);
            }
        }