Die Community zu .NET und Classic VB.
Menü

HAL

 von 

Übersicht 

Beschreibung

Archivformat von Mirage, Inc. zum speichern von Spieldaten. Es wird keine Komprimierung verwendet.

Allgemeiner Aufbau  

Header
Header String * 4
FileCount Long
? String * 24
Informationen zu den Daten
FileLen Long
FilePos Long
? Long
? Long
Entry String * 16
Datenblock
Datenblock Enthält die Daten der im Archiv gespeicherten Dateien

Weitere Informationen  

Header APUK
FileCount Anzahl der im Archiv befindlichen Dateien
Entry Dateiname
FileLen Länge der Datei in Bytes
FilePos Position der Datei im Archiv

Beispiel  

Option Explicit

Dim haIndex As Long
Dim haCached As String
Dim haEntries(0 To 5000) As String * 16
Dim haFileAnz As Long
Dim haFileLen(0 To 5000) As Long
Dim haFilePos(0 To 5000) As Long
Dim haHeader As String * 4

'---------------------------------
'Lädt alle Infos in den Speicher
'---------------------------------
Public Sub CacheHAL(HALFile As String)
    Dim haFile As Integer
    Dim k As Long
    haFile = FreeFile
    Dim Temp As String * 24
    Dim Temp2 As Long
    Open HALFile For Binary As haFile
        Get haFile, 1, haHeader
        Get haFile, , haFileAnz
        Get haFile, , Temp
        For k = 0 To haFileAnz - 1
            Get haFile, , haFileLen(k)
            Get haFile, , haFilePos(k)
            haFilePos(k) = haFilePos(k) + 1
            Get haFile, , Temp2
            Get haFile, , Temp2
            Get haFile, , haEntries(k)
            haEntries(k) = Left(haEntries(k), InStr(haEntries(k), _
         Chr(0)) - 1)
        Next k
    Close haFile
    haCached = HALFile
End Sub

'---------------------------------------
'Gibt die Anzahl der Dateien im Archiv
'zurück
'---------------------------------------
Public Function GetFileCount(HALFile As String)
    If Not haCached = HALFile Then
        CacheHAL HALFile
    End If
    GetFileCount = haFileAnz
End Function

'----------------------------------------
'Gibt den Dateinamen der Datei "FileIndx"
'zurück
'----------------------------------------
Public Function GetEntry(HALFile As String, FileIndx As Long) As String
    If Not haCached = HALFile Then
        CacheHAL HALFile
    End If
    GetEntry = haEntries(FileIndx)
End Function

'---------------------------------------
'Extrahiert eine Datei aus dem Archiv
'---------------------------------------
Public Function ExtractFile(HALFile As String, FileIndx As Integer, _
    Optional DestFile As String) As Boolean
    Dim FileData As String
    Dim haFile As Integer
    Dim DestFileNr As Integer
    Dim z As Integer
    haFile = FreeFile
    Open HALFile For Binary As haFile
        DestFileNr = FreeFile
        FileData = Space(haFileLen(FileIndx))
        Get haFile, haFilePos(FileIndx), FileData
        If DestFile = "" Then
          DestFile = RTrim(haEntries(FileIndx))
            z% = InStrRev(DestFile, "/")
           DestFile = Right(DestFile, Len(DestFile) - z%)
        End If
        Open DestFile For Binary As DestFileNr
            Put DestFileNr, , FileData
        Close DestFileNr
    Close haFile
End Function