C#解析Torrent 文件源码文档格式.docx
- 文档编号:8488561
- 上传时间:2023-05-11
- 格式:DOCX
- 页数:18
- 大小:17.98KB
C#解析Torrent 文件源码文档格式.docx
《C#解析Torrent 文件源码文档格式.docx》由会员分享,可在线阅读,更多相关《C#解析Torrent 文件源码文档格式.docx(18页珍藏版)》请在冰点文库上搜索。
"
;
privatebool_OpenFile=false;
privatestring_TorrentAnnounce="
privateIList<
string>
_TorrentAnnounceList=newList<
();
privateDateTime_TorrentCreateTime=newDateTime(1970,1,1,0,0,0);
privatelong_TorrentCodePage=0;
privatestring_TorrentComment="
privatestring_TorrentCreatedBy="
privatestring_TorrentEncoding="
privatestring_TorrentCommentUTF8="
TorrentFileInfoClass>
_TorrentFileInfo=newList<
privatestring_TorrentName="
privatestring_TorrentNameUTF8="
privatelong_TorrentPieceLength=0;
privatebyte[]_TorrentPieces;
privatestring_TorrentPublisher="
privatestring_TorrentPublisherUTF8="
privatestring_TorrentPublisherUrl="
privatestring_TorrentPublisherUrlUTF8="
_TorrentNotes=newList<
#endregion
#region属性
///错误信息
publicstringOpenError{set{_OpenError=value;
}get{return_OpenError;
}}
///是否正常打开文件
publicboolOpenFile{set{_OpenFile=value;
}get{return_OpenFile;
///服务器的URL(字符串)
publicstringTorrentAnnounce{set{_TorrentAnnounce=value;
}get{return_TorrentAnnounce;
///备用tracker服务器列表(列表)
publicIList<
TorrentAnnounceList{set{_TorrentAnnounceList=value;
}get{return_TorrentAnnounceList;
///种子创建的时间,Unix标准时间格式,从19701月1日00:
00:
00到创建时间的秒数(整数)
publicDateTimeTorrentCreateTime{set{_TorrentCreateTime=value;
}get{return_TorrentCreateTime;
///未知数字CodePage
publiclongTorrentCodePage{set{_TorrentCodePage=value;
}get{return_TorrentCodePage;
///种子描述
publicstringTorrentComment{set{_TorrentComment=value;
}get{return_TorrentComment;
///编码方式
publicstringTorrentCommentUTF8{set{_TorrentCommentUTF8=value;
}get{return_TorrentCommentUTF8;
///创建人
publicstringTorrentCreatedBy{set{_TorrentCreatedBy=value;
}get{return_TorrentCreatedBy;
publicstringTorrentEncoding{set{_TorrentEncoding=value;
}get{return_TorrentEncoding;
///文件信息
TorrentFileInfo{set{_TorrentFileInfo=value;
}get{return_TorrentFileInfo;
///种子名
publicstringTorrentName{set{_TorrentName=value;
}get{return_TorrentName;
///种子名UTF8
publicstringTorrentNameUTF8{set{_TorrentNameUTF8=value;
}get{return_TorrentNameUTF8;
///每个块的大小,单位字节(整数)
publiclongTorrentPieceLength{set{_TorrentPieceLength=value;
}get{return_TorrentPieceLength;
///每个块的20个字节的SHA1Hash的值(二进制格式)
privatebyte[]TorrentPieces{set{_TorrentPieces=value;
}get{return_TorrentPieces;
///出版
publicstringTorrentPublisher{set{_TorrentPublisher=value;
}get{return_TorrentPublisher;
///出版UTF8
publicstringTorrentPublisherUTF8{set{_TorrentPublisherUTF8=value;
}get{return_TorrentPublisherUTF8;
///出版地址
publicstringTorrentPublisherUrl{set{_TorrentPublisherUrl=value;
}get{return_TorrentPublisherUrl;
publicstringTorrentPublisherUrlUTF8{set{_TorrentPublisherUrlUTF8=value;
}get{return_TorrentPublisherUrlUTF8;
///NODES
TorrentNotes{set{_TorrentNotes=value;
}get{return_TorrentNotes;
publicTorrentFile(stringFileName)
System.IO.FileStreamTorrentFile=newSystem.IO.FileStream(FileName,System.IO.FileMode.Open);
byte[]TorrentBytes=newbyte[TorrentFile.Length];
TorrentFile.Read(TorrentBytes,0,TorrentBytes.Length);
TorrentFile.Close();
if((char)TorrentBytes[0]!
='
d'
)
if(OpenError.Length==0)OpenError="
错误的Torrent文件,开头第1字节不是100"
return;
}
GetTorrentData(TorrentBytes);
#region开始读数据
///开始读取
paramname="
TorrentBytes"
>
<
/param>
privatevoidGetTorrentData(byte[]TorrentBytes)
intStarIndex=1;
while(true)
objectKeys=GetKeyText(TorrentBytes,refStarIndex);
if(Keys==null)
if(StarIndex>
=TorrentBytes.Length)OpenFile=true;
break;
if(GetValueText(TorrentBytes,refStarIndex,Keys.ToString().ToUpper())==false)break;
///读取结构
StarIndex"
Keys"
returns>
/returns>
privateboolGetValueText(byte[]TorrentBytes,refintStarIndex,stringKeys)
switch(Keys)
case"
ANNOUNCE"
:
TorrentAnnounce=GetKeyText(TorrentBytes,refStarIndex).ToString();
ANNOUNCE-LIST"
intListCount=0;
ArrayList_TempList=GetKeyData(TorrentBytes,refStarIndex,refListCount);
for(inti=0;
i!
=_TempList.Count;
i++)
TorrentAnnounceList.Add(_TempList[i].ToString());
}
CREATIONDATE"
objectDate=GetKeyNumb(TorrentBytes,refStarIndex).ToString();
if(Date==null)
CREATIONDATE返回不是数字类型"
returnfalse;
TorrentCreateTime=TorrentCreateTime.AddTicks(long.Parse(Date.ToString()));
CODEPAGE"
objectCodePageNumb=GetKeyNumb(TorrentBytes,refStarIndex);
if(CodePageNumb==null)
CODEPAGE返回不是数字类型"
TorrentCodePage=long.Parse(CodePageNumb.ToString());
ENCODING"
TorrentEncoding=GetKeyText(TorrentBytes,refStarIndex).ToString();
CREATEDBY"
TorrentCreatedBy=GetKeyText(TorrentBytes,refStarIndex).ToString();
COMMENT"
TorrentComment=GetKeyText(TorrentBytes,refStarIndex).ToString();
COMMENT.UTF-8"
TorrentCommentUTF8=GetKeyText(TorrentBytes,refStarIndex).ToString();
INFO"
intFileListCount=0;
GetFileInfo(TorrentBytes,refStarIndex,refFileListCount);
NAME"
TorrentName=GetKeyText(TorrentBytes,refStarIndex).ToString();
NAME.UTF-8"
TorrentNameUTF8=GetKeyText(TorrentBytes,refStarIndex).ToString();
PIECELENGTH"
objectPieceLengthNumb=GetKeyNumb(TorrentBytes,refStarIndex);
if(PieceLengthNumb==null)
PIECELENGTH返回不是数字类型"
TorrentPieceLength=long.Parse(PieceLengthNumb.ToString());
PIECES"
TorrentPieces=GetKeyByte(TorrentBytes,refStarIndex);
PUBLISHER"
TorrentPublisher=GetKeyText(TorrentBytes,refStarIndex).ToString();
PUBLISHER.UTF-8"
TorrentPublisherUTF8=GetKeyText(TorrentBytes,refStarIndex).ToString();
PUBLISHER-URL"
TorrentPublisherUrl=GetKeyText(TorrentBytes,refStarIndex).ToString();
PUBLISHER-URL.UTF-8"
TorrentPublisherUrlUTF8=GetKeyText(TorrentBytes,refStarIndex).ToString();
NODES"
intNodesCount=0;
ArrayList_NodesList=GetKeyData(TorrentBytes,refStarIndex,refNodesCount);
intIPCount=_NodesList.Count/2;
=IPCount;
TorrentNotes.Add(_NodesList[i*2]+"
+_NodesList[(i*2)+1]);
default:
returntrue;
#region获取数据
///获取列表方式"
I1:
Xe"
="
X"
会调用GetKeyText
ListCount"
privateArrayListGetKeyData(byte[]TorrentBytes,refintStarIndex,refintListCount)
ArrayList_TempList=newArrayList();
stringTextStar=Encoding.UTF8.GetString(TorrentBytes,StarIndex,1);
switch(TextStar)
l"
StarIndex++;
ListCount++;
e"
ListCount--;
if(ListCount==0)return_TempList;
i"
_TempList.Add(GetKeyNumb(TorrentBytes,refStarIndex).ToString());
objectListText=GetKeyText(TorrentBytes,refStarIndex);
if(ListText!
=null)
_TempList.Add(ListText.ToString());
else
if(OpenError.Length==0)
OpenError="
错误的Torrent文件,ANNOUNCE-LIST错误"
return_TempList;
///获取字符串
privateobjectGetKeyText(byte[]TorrentBytes,refintStarIndex)
intNumb=0;
intLeftNumb=0;
for(inti=StarIndex;
=TorrentBytes.Length;
if((char)TorrentBytes[i]=='
'
)break;
e'
{
LeftNumb++;
continue;
Numb++;
StarIndex+=LeftNumb;
stringTextNumb=Encoding
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C#解析Torrent 文件源码 C# 解析 Torrent 文件 源码
![提示](https://static.bingdoc.com/images/bang_tan.gif)