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