对于这个类在解析Torrent 文件时候可能有错误,请大家指正。先把文件解析的类贴出来,连接有空再发把。
使用
TorrentFile File = new TorrentFile(openFileDialog1.FileName);
File.TorrentFileInfoClass[] 文件信息
File.TorrentAnnounceList 服务器列表
全部代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace Zgke.OtherFile
{
/// <summary>
/// Torrent文件
///
/// 2008-08-28
/// </summary>
public class TorrentFile
{
#region 私有字段
private string _OpenError = "";
private bool _OpenFile = fal;
private string _TorrentAnnounce = "";
private IList<string> _TorrentAnnounceList = new List<string>();
private DateTime _TorrentCreateTime = new DateTime(1970,1,1,0,0,0);
private long _TorrentCodePage = 0;
private string _TorrentComment = "";
private string _TorrentCreatedBy = "";
private string _TorrentEncoding = "";
private string _TorrentCommentUTF8 = "";
private IList<TorrentFileInfoClass> _TorrentFileInfo = new List<TorrentFileInfoClass>();
private string _TorrentName = "";
private string _TorrentNameUTF8 = "";
private long _TorrentPieceLength = 0;
private byte[] _TorrentPieces;
private string _TorrentPublisher = "";
private string _TorrentPublisherUTF8 = "";
private string _TorrentPublisherUrl = "";
private string _TorrentPublisherUrlUTF8 = "";
private IList<string> _TorrentNotes = new List<string>();
#endregion
#region 属性
/// <summary>
/// 错误信息
/// </summary>
public string OpenError { t { _OpenError = value; } get { return _OpenError; } }
/// <summary>
/// 是否正常打开文件
/// </summary>
public bool OpenFile { t { _OpenFile = value; } get { return _OpenFile; } }
/// <summary>
/// 服务器的URL(字符串)
/// </summary>
public string TorrentAnnounce { t { _TorrentAnnounce = value; } get { return _TorrentAnnounce; } }
/// <summary>
/// 备用tracker服务器列表(列表)
读后感结尾 /// </summary>
public IList<string> TorrentAnnounceList { t { _TorrentAnnounceList = value; } get { return _TorrentAnnounceList; } }
爱在记忆中找你 /// <summary>
/// 种子创建的时间,Unix标准时间格式,从1970 1月1日 00:00:00到创建时间的秒数(整数)
/// </summary>
public DateTime TorrentCreateTime { t { _TorrentCreateTime = value; } get { return _TorrentCreateTime; } }
/// <summary>
/// 未知数字CodePage
/// </summary>
public long TorrentCodePage { t { _TorrentCodePage = value; } get { return _TorrentCodePage; } }
军统局长 /// <summary>
/// 种子描述
/// </summary>
public string TorrentComment { t { _TorrentComment = value; } get { return _TorrentComment; } }
/// <summary>
/// 编码方式
/// </summary>
public string TorrentCommentUTF8 { t { _TorrentCommentUTF8 = value; } get { return _TorrentCommentUTF8; } }
/// <summary>
/// 创建人
/// </summary>
public string TorrentCreatedBy { t { _TorrentCreatedBy = value; } get { return _TorrentCreatedBy; } }
/// <summary>
/// 编码方式
/// </summary>
public string TorrentEncoding { t { _TorrentEncoding = value; } get { return _TorrentEncoding; } }
/// <summary>
/// 文件信息
/// </summary>
public IList<TorrentFileInfoClass> TorrentFileInfo { t { _TorrentFileInfo = value; } get { return _TorrentFileInfo; } }水上乐园
/// <summary>
/// 种子名
/// </summary>
public string TorrentName { t { _TorrentName = value; } get { return _TorrentName; } }
/// <summary>
/// 种子名UTF8
/// </summary>
public string TorrentNameUTF8 { t { _TorrentNameUTF8 = value; } get { return _TorrentNameUTF8; } }
/// <summary>
/// 每个块的大小,单位字节(整数)
/// </summary>
public long TorrentPieceLength { t { _TorrentPieceLength = value; } get { return _TorrentPieceLength; } }
/// <summary>
/// 每个块的20个字节的SHA1 Hash的值(二进制格式)
/// </summary>
private byte[] TorrentPieces { t { _TorrentPieces = value; } get { return _TorrentPieces; } }
/// <summary>
/// 出版
/// </summary>
public string TorrentPublisher { t { _TorrentPublisher = value; } get { return _TorrentPublisher; } }
/// <summary>
/// 出版UTF8
/// </summary>
public string TorrentPublisherUTF8 { t { _TorrentPublisherUTF8 = value; } get { return _TorrentPublisherUTF8; } }
减刑的条件和限度 /// <summary>
/// 出版地址
/// </summary>
public string TorrentPublisherUrl { t { _TorrentPublisherUrl = value; } get { return _TorrentPublisherUrl; } }
/// <summary>
/// 出版地址
/// </summary>
public string TorrentPublisherUrlUTF8 { t { _TorrentPublisherUrlUTF8 = value; } get { return _TorrentPublisherUrlUTF8; } }
/// <summary>
/// NODES
/// </summary>
public IList<string> TorrentNotes { t { _TorrentNotes = value; } get { return _TorrentNotes; } }
#endregion
public TorrentFile(string FileName)
{
System.IO.FileStream TorrentFile = new System.IO.FileStream(FileName, System.IO.FileMode.Open);
byte[] TorrentBytes = new byte[TorrentFile.Length];
TorrentFile.Read(TorrentBytes, 0, TorrentBytes.Length);
TorrentFile.Clo();
if ((char)TorrentBytes[0] != 'd')
{
if (OpenError.Length == 0) OpenError = "错误的Torrent文件,开头第1字节不是100";
return;
}
GetTorrentData(TorrentBytes);
}
#region 开始读数据
/// <summary>仇组词组
/// 开始读取
/// </summary>负的笔顺
/// <param name="TorrentBytes"></param>
private void GetTorrentData(byte[] TorrentBytes)
{
int StarIndex = 1;
while (true)
{
object Keys = GetKeyText(TorrentBytes, ref StarIndex);
if (Keys == null)
{
if (StarIndex >= TorrentBytes.Length) OpenFile = true;
短路故障指示器 break;
}