public TorrentReader(string archivo) { FileStream f = new FileStream(archivo, FileMode.Open, FileAccess.Read); BEncodeDecoder parser = new BEncodeDecoder(); decodedTorrent = parser.parse(f); comment = ((BEncodeString)decodedTorrent.getValue(new BEncodeString("comment"))).ToString(); announceURL = ((BEncodeString)decodedTorrent.getValue(new BEncodeString("announce"))).ToString(); announceList = (BEncodeList)decodedTorrent.getValue(new BEncodeString("announce-list")); try { encoding = ((BEncodeString)decodedTorrent.getValue(new BEncodeString("encoding"))).ToString(); } catch (Exception e) { } string test = ((BEncodeDictionary)decodedTorrent.getValue(new BEncodeString("info"))).ToBencodeDictionary(); char[] tester = test.ToCharArray(); byte[] total = new byte[tester.Length]; int counter = 0; foreach(char chars in tester) { total[counter] = (byte)chars; counter += 1; } info_hash_byte = SHA1CryptoServiceProvider.Create().ComputeHash(total); info_hash = BitConverter.ToString(info_hash_byte).Replace("-", ""); content_length = ((BEncodeInteger)((BEncodeDictionary)decodedTorrent.getValue(new BEncodeString("info"))).getValue(new BEncodeString("length"))).getValue(); filename = ((BEncodeString)((BEncodeDictionary)decodedTorrent.getValue(new BEncodeString("info"))).getValue(new BEncodeString("name"))).ToString(); created_by = ((BEncodeString)decodedTorrent.getValue(new BEncodeString("created by"))).ToString(); }
private BEncodeList decodeList() { BEncodeList value = new BEncodeList(); char start = (char)reader.ReadByte(); bool hasFinal = false; if (start == 'l') { while (true) { char actual = (char)reader.PeekChar(); if (actual == 'e') { hasFinal = true; reader.ReadByte(); break; } if (actual == 'd') { value.Add(decodeDictionary()); } else if (actual == 'l') { value.Add(decodeList()); } else if (actual == 'i') { value.Add(decodeInteger()); } else if (char.IsDigit(actual)) { value.Add(decodeString()); } else { throw new BEncodeException("cant recognize type in list"); } } } else { throw new BEncodeException("list must start with l"); } if (!hasFinal) { throw new BEncodeException("list must finish with e"); } return value; }
public void Add(BEncodeString key, BEncodeList value) { data.Add(key, value); }
public void Add(BEncodeList value) { data.Add(value); }