📄 parse.pas
字号:
unit Parse;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, Torrent_TLB, StdVcl, TorrentFile, Classes, SysUtils, Contnrs;
type
TParse = class(TASPObject, IParse)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure LoadFile(const Path: WideString); safecall;
procedure Close; safecall;
function Get_Announce: WideString; safecall;
function Get_BinaryHash: WideString; safecall;
function Get_CreatedBy: WideString; safecall;
function Get_CreationDate: WideString; safecall;
function Get_Error: WideString; safecall;
function Get_FileList: WideString; safecall;
function Get_Hash: WideString; safecall;
function Get_Name: WideString; safecall;
function Get_Size: Int64; safecall;
function Get_AnnounceList: WideString; safecall;
private
_Announce: string;
_AnnounceList: string;
_Hash: string;
_Name: string;
_FileList: string;
_Error: string;
_CreatedBy: string;
_BinaryHash: string;
_CreationDate: string;
_Size: int64;
end;
implementation
uses ComServ;
procedure TParse.OnEndPage;
begin
Close;
inherited OnEndPage;
end;
procedure TParse.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;
procedure TParse.LoadFile(const Path: WideString);
var
tf: TTorrentFile;
stream: TFileStream;
tsf: TTorrentSubFile;
i: integer;
an : TStringList;
begin
_Announce := '';
_AnnounceList := '';
_FileList := '';
_Size := 0;
_CreatedBy := '';
_BinaryHash := '';
_CreationDate := '';
_Error := '';
if FileExists(Path) = false then
begin
_Error := '文件不存在';
exit;
end;
tf := TTorrentFile.Create();
stream := TFileStream.Create(Path, $0000);
tf.Load(stream);
for i:= 0 to tf.AnnounceList.Count - 1 do
begin
an := tf.AnnounceList.Items[i] as TStringList;
_AnnounceList := _AnnounceList + an.Text + #13#10;
end;
//
for i := 0 to tf.Files.Count - 1 do
begin
tsf := tf.Files[i] as TTorrentSubFile;
_FileList := _FileList + tsf.Name + #13#10;
_Size := _Size + tsf.Len;
end;
_Announce := tf.Announce;
_Name := tf.Name;
_Hash := tf.Hash;
tf.Free;
stream.Free;
end;
procedure TParse.Close;
begin
FreeAndNil(_Announce);
FreeAndNil(_AnnounceList);
FreeAndNil(_Hash);
FreeAndNil(_Name);
FreeAndNil(_FileList);
FreeAndNil(_Error);
FreeAndNil(_CreatedBy);
FreeAndNil(_BinaryHash);
FreeAndNil(_CreationDate);
FreeAndNil(_Size);
end;
function TParse.Get_Announce: WideString;
begin
result := _Announce;
end;
function TParse.Get_BinaryHash: WideString;
begin
result := _BinaryHash;
end;
function TParse.Get_CreatedBy: WideString;
begin
result := _CreatedBy;
end;
function TParse.Get_CreationDate: WideString;
begin
result := _CreationDate;
end;
function TParse.Get_Error: WideString;
begin
result := _Error;
end;
function TParse.Get_FileList: WideString;
begin
result := _FileList;
end;
function TParse.Get_Hash: WideString;
begin
result := _Hash;
end;
function TParse.Get_Name: WideString;
begin
result := _Name;
end;
function TParse.Get_Size: Int64;
begin
result := _Size;
end;
function TParse.Get_AnnounceList: WideString;
begin
result := _AnnounceList;
end;
initialization
TAutoObjectFactory.Create(ComServer, TParse, Class_Parse,
ciMultiInstance, tmApartment);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -