private void ParseMultipleFiles() { ValueDictionary info = (ValueDictionary)data["info"]; ValueList files = (ValueList)info["files"]; torrentFiles = null; torrentFiles = new Collection <TorrentFile>(); foreach (ValueDictionary o in files) { ValueList components = (ValueList)o["path"]; bool first = true; string path = ""; foreach (ValueString vs in components) { if (!first) { path += "/"; } first = false; path += vs.String; } _totalLength += (ulong)((ValueNumber)o["length"]).Integer; TorrentFile f = new TorrentFile(((ValueNumber)o["length"]).Integer, path); torrentFiles.Add(f); } }
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; }
private void ParseMultipleFiles() { ValueDictionary dictionary = (ValueDictionary)this.data["info"]; ValueList list = (ValueList)dictionary["files"]; this.torrentFiles = null; this.torrentFiles = new Collection <TorrentFile>(); foreach (ValueDictionary dictionary2 in list) { ValueList list2 = (ValueList)dictionary2["path"]; bool flag = true; string apath = ""; foreach (ValueString str2 in list2) { if (!flag) { apath = apath + "/"; } flag = false; apath = apath + str2.String; } this._totalLength += (ulong)((ValueNumber)dictionary2["length"]).Integer; TorrentFile item = new TorrentFile(((ValueNumber)dictionary2["length"]).Integer, apath); this.torrentFiles.Add(item); } }
private void ParseSingleFile() { ValueDictionary info = (ValueDictionary)data["info"]; _totalLength = (ulong)((ValueNumber)info["length"]).Integer; TorrentFile f = new TorrentFile(((ValueNumber)info["length"]).Integer, ((ValueString)info["name"]).String); torrentFiles.Add(f); }
private void ParseSingleFile() { ValueDictionary dictionary = (ValueDictionary)this.data["info"]; this._totalLength = (ulong)((ValueNumber)dictionary["length"]).Integer; TorrentFile item = new TorrentFile(((ValueNumber)dictionary["length"]).Integer, ((ValueString)dictionary["name"]).String); this.torrentFiles.Add(item); }
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; }
internal bool OpenTorrent(string localFilename) { data = null; // clear any old data bool hasOpened = false; localTorrentFile = localFilename; data = new ValueDictionary(); FileStream fs = null; BinaryReader r = null; try { fs = File.OpenRead(localFilename); r = new BinaryReader(fs); // Parse the BEncode .torrent file data = (ValueDictionary)BEncode.Parse(r.BaseStream); // Check the torrent for its form, initialize this object LoadTorrent(); hasOpened = true; r.Close(); fs.Close(); } catch (IOException) { hasOpened = false; } finally { if (r != null) { r.Close(); } if (fs != null) { fs.Close(); } } return(hasOpened); }
public bool OpenTorrent(string localFilename) { this.data = null; bool flag = false; this.localTorrentFile = localFilename; this.data = new ValueDictionary(); FileStream input = null; BinaryReader reader = null; try { input = File.OpenRead(localFilename); reader = new BinaryReader(input); this.data = (ValueDictionary)BEncode.Parse(reader.BaseStream); this.LoadTorrent(); flag = true; reader.Close(); input.Close(); } catch (IOException) { flag = false; } finally { if (reader != null) { reader.Close(); } if (input != null) { input.Close(); } } return(flag); }
internal Torrent() { data = new ValueDictionary(); localTorrentFile = String.Empty; torrentFiles = new Collection <TorrentFile>(); }
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 Torrent() { this.data = new ValueDictionary(); this.localTorrentFile = string.Empty; this.torrentFiles = new Collection <TorrentFile>(); }
internal Torrent() { data = new ValueDictionary(); localTorrentFile = String.Empty; torrentFiles = new Collection<TorrentFile>(); }
internal bool OpenTorrent(string localFilename) { data = null; // clear any old data bool hasOpened = false; localTorrentFile = localFilename; data = new ValueDictionary(); FileStream fs = null; BinaryReader r = null; try { fs = File.OpenRead(localFilename); r = new BinaryReader(fs); // Parse the BEncode .torrent file data = (ValueDictionary)BEncode.Parse(r.BaseStream); // Check the torrent for its form, initialize this object LoadTorrent(); hasOpened = true; r.Close(); fs.Close(); } catch (IOException) { hasOpened = false; } finally { if (r != null) r.Close(); if (fs != null) fs.Close(); } return hasOpened; }