private static void ParseInfo(TorrentInfo torrent, TorrentFileInfo singleFile, ref bool isSingleFile, BDictionary dictionary) { Contract.Requires(torrent != null); Contract.Requires(singleFile != null); Contract.Requires(dictionary != null); foreach (var info in dictionary) { if (info.Key == null) { continue; } if (info.Key.Value == "name") { if (info.Value != null) { torrent.Name = info.Value.ToString(); } } else if (info.Key.Value == "piece length") { BInteger integer = info.Value as BInteger; if (integer != null) { torrent.PieceLength = integer.Value; } } else if (info.Key.Value == "pieces") { if (info.Value != null) { torrent.Pieces = info.Value.ToString(); } } else if (info.Key.Value == "private") { BInteger integer = info.Value as BInteger; if (integer != null) { torrent.Private = integer.Value != 0; } } else if (info.Key.Value == "files") { BList files = info.Value as BList; if (files != null) { foreach (var file in files) { BDictionary dict = file as BDictionary; if (dict != null) { torrent.Files.Add(TorrentFileInfo.Parse(dict)); } } } } else if (info.Key.Value == "file-duration") { isSingleFile = true; BList items = info.Value as BList; if (items != null) { foreach (var item in items) { BInteger integer = item as BInteger; if (integer != null) { singleFile.Duration.Add(integer.Value); } } } } else if (info.Key.Value == "file-media") { isSingleFile = true; BList items = info.Value as BList; if (items != null) { foreach (var item in items) { BInteger integer = item as BInteger; if (integer != null) { singleFile.Media.Add(integer.Value); } } } } else if (info.Key.Value == "profiles") { isSingleFile = true; BList items = info.Value as BList; if (items != null) { foreach (var item in items) { BDictionary dictItems = item as BDictionary; if (dictItems != null) { TorrentFileProfileCollection profiles = new TorrentFileProfileCollection(); profiles.AddRange(dictItems.Select(dictItem => new TorrentFileProfile { Name = dictItem.Key.ToString(), Value = dictItem.Value.ToString() })); singleFile.Profiles.Add(profiles); } } } } } }