資源簡介
Torrent.cs
代碼片段和文件信息
using?System;
using?System.IO;
using?System.Text;
using?System.Collections.Generic;
using?System.Text.Regularexpressions;
namespace?System
{
????public?class?Torrent
????{
????????#region?私有成員字段
????????string?announce?=?““;
????????Listject>?announcelist?=?new?Listject>();
????????string?comment?=?““;
????????string?commentutf8?=?““;
????????string?createdby?=?““;
????????DateTime?creationdate?=?new?DateTime(1970?1?1?0?0?0);
????????string?encoding?=?““;
????????#endregion
????????#region?屬性
????????public?string?Announce?{?get?{?return?this.announce;?}?set?{?this.announce?=?value;?}?}
????????public?Listject>?AnnounceList?{?get?{?return?this.announcelist;?}?set?{?this.announcelist?=?value;?}?}
????????public?string?Comment?{?get?{?return?this.comment;?}?set?{?this.comment?=?value;?}?}
????????public?string?CommentUTF8?{?get?{?return?this.commentutf8;?}?set?{?this.commentutf8?=?value;?}?}
????????public?string?CommentBy?{?get?{?return?this.createdby;?}?set?{?this.createdby?=?value;?}?}
????????public?DateTime?CreationDate?{?get?{?return?this.creationdate;?}?set?{?this.creationdate?=?value;?}?}
????????public?string?TorrentEncoding?{?get?{?return?this.encoding;?}?set?{?this.encoding?=?value;?}?}
????????#endregion
????????FileStream?fs;
????????BinaryReader?br;
????????public?Torrent(string?path)
????????{
????????????fs?=?new?FileStream(path?FileMode.Open);
????????????br?=?new?BinaryReader(fs);
????????????byte[]?buf?=?new?byte[1];
????????????string?str?=?““;
????????????buf[0]?=?br.ReadByte();
????????????str?=?Encoding.UTF8.GetString(buf?0?1);
????????????if?(str?==?“d“)
????????????{
????????????????this.ReadAll();
????????????}
????????????else
????????????{
????????????????Exception?e?=?new?Exception(“無法解析此文件“);
????????????????throw?e;
????????????}
????????}
????????int?ReadInt(BinaryReader?br)
????????{
????????????return?0;
????????}
????????string?ReadString(BinaryReader?br)
????????{
????????????byte[]?buf?=?new?byte[1];
????????????string?str?=?““;
????????????buf[0]?=?br.ReadByte();
????????????str?=?Encoding.UTF8.GetString(buf);
????????????Regex?reg?=?new?Regex(“^[0-9]*$“);
????????????if?(reg.Match(str).Value?!=?string.Empty)
????????????{
????????????????buf[0]?=?br.ReadByte();
????????????????string?tmpstr?=?Encoding.UTF8.GetString(buf);
????????????????while?(tmpstr?!=?“:“)
????????????????{
????????????????????str?+=?tmpstr;
????????????????????buf[0]?=?br.ReadByte();
????????????????????tmpstr?=?Encoding.UTF8.GetString(buf);
????????????????}
????????????????int?j?=?Convert.ToInt32(str);
????????????????str?=?““;
????????????????byte[]?buf2?=?new?byte[j];
????????????????for?(int?i?=?0;?i?????????????????{
????????????????????buf2[i]?=?br.ReadByte();
????????????????}
????????????????str?=?Encoding.UTF8.GetString(buf2);
????????????????return?str;
????????????}
????????????else
????????????{
????????????
- 上一篇:C#獲取圖片并保存到本地
- 下一篇:C#使用HttpClient
評論
共有 條評論