private void ShowTorrentInformation() { try { BEncodedValue value; BEncodedString str; bool b; txtInfo.Clear(); txtInfo.AppendText("种子文件: " + currentTorrentFilename + Environment.NewLine); b = torrent.TryGetValue("created by", out value); if (b) { str = value as BEncodedString; if (str != null) { txtInfo.AppendText("创建程序: " + str.ToString() + Environment.NewLine); } } b = torrent.TryGetValue("creation date", out value); if (b) { str = value as BEncodedString; if (str != null) { string creationDateString = str.ToString(); try { long longDate; longDate = Convert.ToInt64(creationDateString); DateTime creationDate = DateTime.FromBinary(longDate); txtInfo.AppendText("创建日期: " + creationDate.ToString() + Environment.NewLine); } catch (Exception) { txtInfo.AppendText("创建日期: (无效)" + Environment.NewLine); } } } b = torrent.TryGetValue("encoding", out value); if (b) { str = value as BEncodedString; if (str != null) { txtInfo.AppendText("编码: " + str.ToString() + Environment.NewLine); } } // 如果不存在,那肯定不是种子文件 value = torrent["info"]; BEncodedDictionary dict = (BEncodedDictionary)value; BEncodedString torrentName = (BEncodedString)dict["name"]; txtInfo.AppendText("种子名称: " + torrentName.ToString() + Environment.NewLine); BEncodedNumber pieceLength = (BEncodedNumber)dict["piece length"]; txtInfo.AppendText("分块大小: "); string postfix; double val = 0; var num = pieceLength.Number; if (num < 1024) { postfix = " B"; val = num; } else if (num < 1024 * 1024) { postfix = " KB"; val = num / (double)1024; } else if (num < 1024 * 1024 * 1024) { postfix = " MB"; val = num / (double)(1024 * 1024); } else { postfix = " GB"; val = num / (double)(1024 * 1024 * 1024); } val = Math.Round(val, 2); txtInfo.AppendText(val.ToString() + postfix + Environment.NewLine); BEncodedString pieces = (BEncodedString)dict["pieces"]; txtInfo.AppendText("分块数量: " + (pieces.TextBytes.Length / 20).ToString() + Environment.NewLine); } catch (Exception) { isHandlingTorrent = false; txtInfo.AppendText("解析种子时出现错误。"); } }