private void CheckMetadata(BencodedString announce, BencodedDictionary info) { if (announce == null || info == null) { throw new TorrentException("Invalid metadata, \'announce\'/\'info\' not of expected type."); } }
private void CheckMetadata(BencodedString announce, BencodedDictionary info) { if (announce == null || info == null) { throw new TorrentException(string.Format("Invalid metadata, 'announce'/'info' not of expected type.")); } }
private void LoadMetadata() { BencodedDictionary metadata = GetMetadata(); var announce = metadata["announce"] as BencodedString; var info = metadata["info"] as BencodedDictionary; CheckMetadata(announce, info); var pieceLength = info["piece length"] as BencodedInteger; List <byte[]> checksumList = GetRawChecksums(info, pieceLength); BencodedString name = GetNameFromInfo(info); List <FileEntry> decodedFiles = DecodeFiles(info, name); if (metadata.ContainsKey("announce-list")) { var announceList = (BencodedList)metadata["announce-list"]; AnnounceList = DecodeAnnounceList(announceList).AsReadOnly(); } AnnounceURL = announce; Checksums = checksumList.AsReadOnly(); Files = decodedFiles.AsReadOnly(); PieceLength = pieceLength; PieceCount = Checksums.Count; Name = name; InfoHash = ComputeInfoHash(info); Announces = CreateAnnouces(AnnounceURL, AnnounceList); TotalLength = Files.Sum(f => f.Length); }
public override bool Equals(object obj) { try { BString other = (BString)obj; return(BencodedString.Equals(other.BencodedString)); } catch (InvalidCastException e) { throw new InvalidCastException(e.Message); } }
private List <FileEntry> DecodeFiles(BencodedDictionary info, BencodedString name) { var decodedFiles = new List <FileEntry>(); if (info.ContainsKey("files")) { var files = info["files"] as BencodedList; CheckInfoFiles(files); foreach (BencodedDictionary file in files) { var torrentFile = CreateTorrentFile(file); decodedFiles.Add(torrentFile); } } else { var fileLength = info["length"] as BencodedInteger; CheckFileLength(fileLength); decodedFiles.Add(new FileEntry(name, fileLength)); } return(decodedFiles); }
private List<FileEntry> DecodeFiles(BencodedDictionary info, BencodedString name) { var decodedFiles = new List<FileEntry>(); if (info.ContainsKey("files")) { var files = info["files"] as BencodedList; CheckInfoFiles(files); foreach (BencodedDictionary file in files) { FileEntry torrentFile = CreateTorrentFile(file); decodedFiles.Add(torrentFile); } } else { var fileLength = info["length"] as BencodedInteger; CheckFileLength(fileLength); decodedFiles.Add(new FileEntry(name, fileLength)); } return decodedFiles; }
private void CheckMetadata(BencodedString announce, BencodedDictionary info) { if (announce == null || info == null) throw new TorrentException(string.Format("Invalid metadata, 'announce'/'info' not of expected type.")); }