public byte[] Encode() { Collection<byte> collection1 = new Collection<byte>(); collection1.Add(100); ArrayList list1 = new ArrayList(); foreach (string text1 in dict.Keys) { list1.Add(text1); } foreach (string text2 in list1) { ValueString text3 = new ValueString(text2); foreach (byte num1 in text3.Encode()) { collection1.Add(num1); } foreach (byte num2 in dict[text2].Encode()) { collection1.Add(num2); } } collection1.Add(0x65); byte[] buffer1 = new byte[collection1.Count]; collection1.CopyTo(buffer1, 0); return buffer1; }
public byte[] Encode() { Collection <byte> collection1 = new Collection <byte>(); collection1.Add(100); ArrayList list1 = new ArrayList(); foreach (string text1 in dict.Keys) { list1.Add(text1); } foreach (string text2 in list1) { ValueString text3 = new ValueString(text2); foreach (byte num1 in text3.Encode()) { collection1.Add(num1); } foreach (byte num2 in dict[text2].Encode()) { collection1.Add(num2); } } collection1.Add(0x65); byte[] buffer1 = new byte[collection1.Count]; collection1.CopyTo(buffer1, 0); return(buffer1); }
internal static IBEncodeValue Parse(Stream d, byte firstByte) { IBEncodeValue v; char first = (char)firstByte; // if (first == 'd') { v = new ValueDictionary(); } else if (first == 'l') { v = new ValueList(); } else if (first == 'i') { v = new ValueNumber(); } else { v = new ValueString(); } if (v is ValueString) { ((ValueString)v).Parse(d, (byte)first); } else { v.Parse(d); } return(v); }
public static BEncodeValue Parse(Stream d, byte firstByte) { BEncodeValue value2; char ch = (char)firstByte; switch (ch) { case 'd': value2 = new ValueDictionary(); break; case 'l': value2 = new ValueList(); break; case 'i': value2 = new ValueNumber(); break; default: value2 = new ValueString(); break; } if (value2 is ValueString) { ((ValueString)value2).Parse(d, (byte)ch); return(value2); } value2.Parse(d); return(value2); }
private void LoadTorrent() { if (!this.data.Contains("announce")) { throw new IncompleteTorrentData("No tracker URL"); } if (!this.data.Contains("info")) { throw new IncompleteTorrentData("No internal torrent information"); } ValueDictionary dictionary = (ValueDictionary)this.data["info"]; this.pieceLength = ((ValueNumber)dictionary["piece length"]).Integer; if (!dictionary.Contains("pieces")) { throw new IncompleteTorrentData("No piece hash data"); } ValueString str = (ValueString)dictionary["pieces"]; if ((str.Length % 20) != 0) { throw new IncompleteTorrentData("Missing or damaged piece hash codes"); } this.ParsePieceHashes(str.Bytes); if (this.SingleFile) { this.ParseSingleFile(); } else { this.ParseMultipleFiles(); } this.infohash = this.InfoHash; }
public byte[] Encode() { Collection <byte> collection = new Collection <byte>(); collection.Add(100); ArrayList list = new ArrayList(); foreach (string str in this.dict.Keys) { list.Add(str); } foreach (string str2 in list) { ValueString str3 = new ValueString(str2); foreach (byte num in str3.Encode()) { collection.Add(num); } foreach (byte num2 in this.dict[str2].Encode()) { collection.Add(num2); } } collection.Add(0x65); byte[] array = new byte[collection.Count]; collection.CopyTo(array, 0); return(array); }
internal void SetStringValue(string key, string value) { if (Contains(value)) { ((ValueString)this[key]).String = value; } else { this[key] = new ValueString(value); } }
private void LoadTorrent() { if (data.Contains("announce") == false) { throw new IncompleteTorrentData("No tracker URL"); } if (data.Contains("info") == false) { throw new IncompleteTorrentData("No internal torrent information"); } ValueDictionary info = (ValueDictionary)data["info"]; pieceLength = ((ValueNumber)info["piece length"]).Integer; if (info.Contains("pieces") == false) { throw new IncompleteTorrentData("No piece hash data"); } ValueString pieces = (ValueString)info["pieces"]; if ((pieces.Length % 20) != 0) { throw new IncompleteTorrentData("Missing or damaged piece hash codes"); } // Parse out the hash codes ParsePieceHashes(pieces.Bytes); // if (info.Contains("length") == true) // if (data.Contains("files") == true) // throw new Exception("This is not a single file"); // SingleFile = true; // Determine what files are in the torrent if (SingleFile) { ParseSingleFile(); } else { ParseMultipleFiles(); } infohash = InfoHash; }
public void Parse(Stream s) { for (byte num1 = (byte)s.ReadByte(); num1 != 0x65; num1 = (byte)s.ReadByte()) { if (!char.IsNumber((char)num1)) { throw new TorrentException("Key expected to be a string."); } ValueString text1 = new ValueString(); text1.Parse(s, num1); BEncodeValue value1 = BEncode.Parse(s); if (dict.ContainsKey(text1.String)) { dict[text1.String] = value1; } else { dict.Add(text1.String, value1); } } }
public void Parse(Stream s) { for (byte i = (byte)s.ReadByte(); i != 0x65; i = (byte)s.ReadByte()) { if (!char.IsNumber((char)i)) { return; } ValueString str = new ValueString(); str.Parse(s, i); BEncodeValue value2 = BEncode.Parse(s); if (str.String != null) { if (this.dict.ContainsKey(str.String)) { this.dict[str.String] = value2; } else { this.dict.Add(str.String, value2); } } } }
internal static IBEncodeValue Parse(Stream d, byte firstByte) { IBEncodeValue v; char first = (char)firstByte; // if (first == 'd') v = new ValueDictionary(); else if (first == 'l') v = new ValueList(); else if (first == 'i') v = new ValueNumber(); else v = new ValueString(); if (v is ValueString) ((ValueString)v).Parse(d, (byte)first); else v.Parse(d); return v; }