Lire les fichiers .part.met Emule

[Résolu]
Signaler
Messages postés
60
Date d'inscription
jeudi 8 mai 2003
Statut
Membre
Dernière intervention
18 février 2011
-
Messages postés
60
Date d'inscription
jeudi 8 mai 2003
Statut
Membre
Dernière intervention
18 février 2011
-
Bonjour tout le monde !

Mon problème est de traduire un composant du VB vers le Delphi, j'ai
essayé avec un logiciel (Delux Converter) mais ça ne marche pas du
tout...

Ce module sert à lire les différentes infos dans les fichier .part.met
de Emule (nom du fichier téléchargé, taille téléchargée, etc...)

Est-ce que qq'un saurait traduire cela ou alors redévelopper la même chose en delphi ?



merki d'avance





Voici le code en VB :

d'abord on charge le fichier avec LoadMetFile

puis on récupère les infos que l'on veut avec FileName, FileSize, etc...





VERSION 1.0 CLASS

BEGIN

MultiUse = -1 'True

Persistable = 0 'NotPersistable

DataBindingBehavior = 0 'vbNone

DataSourceBehavior = 0 'vbNone

MTSTransactionMode = 0 'NotAnMTSObject

END

Attribute VB_Name = "ReyEmuleReader"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = True

Attribute VB_PredeclaredId = False

Attribute VB_Exposed = False

Option Explicit

'sources de eMule à l'adresse : http://prdownloads.sourceforge.net/emule/eMule0.28b-Sources.zip?download



Private Const PARTFILE_VERSION = &HE0



Private Const FT_FILENAME = &H1

Private Const FT_FILESIZE =
&H2
' <long>

Private Const FT_FILETYPE =
&H3
' <string>

Private Const FT_FILEFORMAT =
&H4
' <string>

Private Const FT_LASTSEENCOMPLETE = &H5

Private Const FT_TRANSFERED =
&H8
' <long>

Private Const FT_GAPSTART = &H9

Private Const FT_GAPEND = &HA

Private Const FT_PARTFILENAME = &H12 ' <string>

Private Const FT_STATUS = &H14

Private Const FT_SOURCES = &H15

Private Const FT_PERMISSIONS = &H16

Private Const FT_DLPRIORITY = &H18

Private Const FT_ULPRIORITY = &H19



Public Enum enum_Status

PS_READY = 0

PS_EMPTY = 1

PS_WAITINGFORHASH = 2

PS_HASHING = 3

PS_ERROR = 4

PS_UNKNOWN = 6

PS_PAUSED = 7

PS_COMPLETING = 8

PS_COMPLETE = 9

End Enum



Dim mCorrompu As Boolean

Dim mFileNumber As Integer

Dim mFile As String

Dim mVersion As Byte

Dim mFileName As String

Dim mSize As Long

Dim mStatus As enum_Status

Dim mTransfered As Long



Private Type CTag_Type

Type As Byte

Length As Integer

SpecialTag As Byte

StringValue As String

Value As Long

TagName As String

End Type



Private Function LoadHashsetFromFile() As Boolean

Call Skip(16)

Dim i As Integer, Parts As Integer

Get #mFileNumber, , Parts

For i = 0 To Parts - 1

Skip (16)

Next i

End Function



Private Function CTag() As CTag_Type

Dim mCTag As CTag_Type

Dim tmpVal As String * 1024

Dim tmpSeek As Long



Get #mFileNumber, , mCTag.Type

If mCTag.Type <> 0 Then

Get #mFileNumber, , mCTag.Length

If mCTag.Length = 1 Then

Get #mFileNumber, , mCTag.SpecialTag

Else

tmpSeek = Seek(mFileNumber)

Get #mFileNumber, , tmpVal

mCTag.TagName = Left$(tmpVal, mCTag.Length)

Seek #mFileNumber, tmpSeek + mCTag.Length

End If



Select Case mCTag.Type

Case 2: 'String

Dim Longueur As Integer

Get #mFileNumber, , Longueur

tmpSeek = Seek(mFileNumber)

Get #mFileNumber, , tmpVal


mCTag.StringValue = Left$(tmpVal, Longueur)

Seek #mFileNumber, tmpSeek + Longueur

Case 3: 'int

Get #mFileNumber, , mCTag.Value

Case 4: 'long

Get #mFileNumber, , mCTag.Value

Case
1:
Stop ' Hash (Never Seen)

Case
5:
Stop ' Bool (Never Seen)

Case
6:
Stop ' Bool Array (Never Seen)

Case
7:
Stop ' Blob ( Never Seen )

Case Else:

Stop 'tag inconnu !!!

End Select

End If

CTag = mCTag

End Function



Private Function Skip(Size As Integer)

Seek mFileNumber, Seek(mFileNumber) + Size

Skip = Seek(mFileNumber)

End Function



Public Sub LoadMetFile(File As String)

mFileNumber = FreeFile

mFile = File

Open File For Binary Access Read As mFileNumber



'****** VERSION

Get #mFileNumber, , mVersion

If mVersion <> PARTFILE_VERSION Then

mCorrompu = 1

'MsgBox "Erreur d'ouverture de part.met"

'End

End If



'****** DATE

Skip (4)



'****** HASHSET

Dim mHash As String * 16

Call LoadHashsetFromFile



'****** TagCount

Dim mTagCount As Long

Get #mFileNumber, , mTagCount



'****** Tags

Dim mCTag As CTag_Type

Dim i As Long

For i = 0 To mTagCount

mCTag = CTag()

Select Case mCTag.SpecialTag

Case
FT_FILENAME:
mFileName = mCTag.StringValue

Case
FT_FILESIZE:
mSize = mCTag.Value

Case
FT_TRANSFERED:
mTransfered = mCTag.Value

Case
FT_STATUS:
mStatus = mCTag.Value

End Select

Next i

Close mFileNumber

End Sub



Public Property Get Corrompu() As Boolean:
Corrompu = mCorrompu: End Property

Public Property Get File() As String: File = mFile: End Property

Public Property Get FileName() As String: FileName = mFileName: End Property

Public Property Get FileSize() As Long: FileSize = mSize: End Property

Public Property Get Transfered() As Long: Transfered = mTransfered: End Property

Public Property Get Status() As enum_Status: Status = mStatus: End Property

Public Property Get Version() As Byte: Version = mVersion: End Property

Public Property Get StatusText() As String

Select Case mStatus

Case
PS_READY:
StatusText = "Ready"

Case
PS_EMPTY:
StatusText = "Empty"

Case PS_WAITINGFORHASH: StatusText = "Waiting For Hash"

Case
PS_HASHING:
StatusText = "Hashing"

Case
PS_ERROR:
StatusText = "Error"

Case
PS_UNKNOWN:
StatusText = "Unknown"

Case
PS_PAUSED:
StatusText = "Paused"

Case
PS_COMPLETING:
StatusText = "Completing"

Case
PS_COMPLETE:
StatusText = "Complete"

End Select

End Property

1 réponse

Messages postés
60
Date d'inscription
jeudi 8 mai 2003
Statut
Membre
Dernière intervention
18 février 2011

Bon ben devant l'enthousiasme général soulevé par ma question j'ai réussi a me débrouiller seul (non sans avoir énormement galéré !)



Si jamais ça doit intéresser quelqu'un un jour voici le code traduit en Delphi

Si vous avez des remarques n'hésitez pas







unit MetReader;



interface

uses

SysUtils;



const

FT_FILENAME = $1;

FT_FILESIZE = $2;

FT_STATUS = $14;

FT_TRANSFERED = $8;

PARTFILE_VERSION = $E0;



PS_READY = 0;

PS_EMPTY = 1;

PS_WAITINGFORASH = 2;

PS_HASHING = 3;

PS_ERROR = 4;

PS_UNKNOW = 6;

PS_PAUSED = 7;

PS_COMPLETING = 8;

PS_COMPLETE = 9;



type

TCTag_Type = record

Tyype: byte;

Length: SmallInt;

SpecialTag: byte;

StringValue: string;

Value: Integer;

TagName: string;

end;



TReyEmuleReader = class(TObject)

private

function LoadHashsetFromFile: boolean;

function CTag: TCTag_type;

function Skip(Size: integer): variant;

public

procedure LoadMetFile(Fichier: string);

function GetCorrompu: boolean;

function GetFile: string;

function GetFileName: string;

function GetFileSize: longint;

function GetTransfered: longint;

function GetStatus: integer;

function GetVersion: byte;

function GetStatusText: string;

end;



implementation



var

mCorrompu: boolean;

mFile: string;

mFileName: string;

mFileNumber: File;

mSize: longint;

mStatus: integer;

mTransfered: longint;

mVersion: byte;



function TReyEmuleReader.LoadHashSetFromFile : boolean;

var

i: integer;

Parts: SmallInt;

begin

Skip(16);

BlockRead(mFileNumber, Parts, SizeOf(Parts));

for i := 0 to Parts - 1 do

Skip(16);

LoadHashSetFromFile := true;

end;



function TReyEmuleReader.CTag : TCTag_Type;

var

Longueur: SmallInt;

mCTag: TCTag_Type;

tmpSeek: Integer;

tmpVal: String[255];

NumWritten: integer;

begin

SetLength(tmpVal, 255);

BlockRead(mFileNumber, mCTag.Tyype, SizeOf(mCTag.Tyype), NumWritten);

if (mCTag.Tyype <> 0) then

begin

BlockRead(mFileNumber, mCTag.Length, SizeOf(mCTag.Length), NumWritten);

if (mCTag.Length = 1) then

begin


BlockRead(mFileNumber, mCTag.SpecialTag, SizeOf(mCTag.SpecialTag),
NumWritten);

end else begin

tmpSeek := FilePos(mFileNumber);


BlockRead(mFileNumber, tmpVal[1], SizeOf(tmpVal) - 1, NumWritten);

mcTag.TagName := copy(tmpVal, 1, mCTag.Length);

Seek(mFileNumber, tmpSeek + mCTag.Length);

end;



case mCTag.Tyype of

2: //string

begin


BlockRead(mFileNumber, Longueur, SizeOf(Longueur), NumWritten);

tmpSeek := FilePos(mFileNumber);


BlockRead(mFileNumber, tmpVal[1], SizeOf(tmpVal) - 1, NumWritten);


mcTAG.StringValue := Copy(tmpVal, 1, Longueur);


Seek(mFileNumber, tmpSeek + Longueur);

end;

3: //int


BlockRead(mFileNumber, mCTag.Value, SizeOf(mCTag.Value), NumWritten);

4: //long


BlockRead(mFileNumber, mCTag.Value, SizeOf(mCTag.Value), NumWritten);

1: //Hash (Never Seen)

halt;

5: //Bool (Never Seen)

halt;

6: //Boo Array (Never Seen)

halt;

7: //Blob (Never Seen)

halt;

Else //tag inconnu !!!

halt;

end;

end;

CTag := mCTag;

end;



function TReyEmuleReader.Skip(Size : integer) : variant;

begin

Seek(mFileNumber, FilePos(mFileNumber) + Size);

Skip := FilePos(mFileNumber);

end;



function TReyEmuleReader.GetCorrompu : boolean;

begin

GetCorrompu := mCorrompu;

end;



function TReyEmuleReader.GetFile : string;

begin

GetFile := mFile;

end;



function TReyEmuleReader.GetFileName : string;

begin

GetFileName := mFileName;

end;



function TReyEmuleReader.GetFileSize : longint;

begin

GetFileSize := mSize;

end;



function TReyEmuleReader.GetTransfered : longint;

begin

GetTransfered := mTransfered;

end;



function TReyEmuleReader.GetStatus : integer;

begin

GetStatus := mStatus;

end;



function TReyEmuleReader.GetVersion : byte;

begin

GetVersion := mVersion;

end;



function TReyEmuleReader.GetStatusText : string;

begin

case mStatus of

PS_READY :

GetStatusText := 'Ready';

PS_EMPTY :

GetStatusText := 'Empty';

PS_WAITINGFORASH :

GetStatusText := 'Waiting for hash';

PS_HASHING :

GetStatusText := 'Hashing';

PS_ERROR :

GetStatusText := 'Error';

PS_UNKNOW :

GetStatusText := 'Unknow';

PS_PAUSED :

GetStatusText := 'Paused';

PS_COMPLETING :

GetStatusText := 'Completing';

PS_COMPLETE :

GetStatusText := 'Complete';

end;

end;



procedure TReyEmuleReader.LoadMetFile(Fichier : string);

var

i : longint;

mCTag : TCTag_Type;

mTagCount : integer;

begin

mFile := Fichier;

mVersion := 0;

mCorrompu := false;

mFileName := '';

mSize := 0;

mTransfered := 0;

mStatus := 0;



AssignFile(mFileNumber, mFile);

FileMode := 0;

Reset(mFileNumber, 1);

//**** VERSION

BlockRead(mFileNumber, mVersion, SizeOf(mVersion));

if (mVersion <> PARTFILE_VERSION) then

begin

mCorrompu := true;

//MessageDlg('Fichier Corrompu', mtInformation, [mbOk], 0);

Exit;

end;

//**** DATE

Skip(4);

//**** HASHSET

LoadHashSetFromFile;

//**** TagCount

BlockRead(mFileNumber, mTagCount, SizeOf(mTagCount));

//**** Tags

for i := 0 to mTagCount do

begin

mCTag := CTag;

case mCTag.SpecialTag of

FT_FILENAME :

mFileName := mCTag.StringValue;

FT_FILESIZE :

mSize := mCTag.Value;

FT_TRANSFERED :

mTransfered := mCTag.Value;

FT_STATUS :

mStatus := mCTag.Value;

end;

end;

CloseFile(mFileNumber);

end;



end.