PageRenderTime 100ms CodeModel.GetById 93ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/FileArchive/FileTable.vb

#
Visual Basic | 61 lines | 48 code | 10 blank | 3 comment | 0 complexity | e57e86299849a3782236e440630096e0 MD5 | raw file
 1''' <summary>
 2''' Represents a table of files contained in an archive.
 3''' </summary>
 4Public Class FileTable
 5
 6    Private FFiles As New List(Of EntryData)
 7
 8    Friend ReadOnly Property Files(ByVal index As Integer) As EntryData
 9        Get
10            Return FFiles(index)
11        End Get
12    End Property
13
14    Public ReadOnly Property FileNames() As String()
15        Get
16            Dim Result(FFiles.Count - 1) As String
17            For I As Integer = 0 To FFiles.Count - 1
18                Result(I) = FFiles(I).FileName
19            Next
20            Return Result
21        End Get
22    End Property
23
24    Public ReadOnly Property VirtualFileNames() As String()
25        Get
26            Dim Result(FFiles.Count - 1) As String
27            For I As Integer = 0 To FFiles.Count - 1
28                Result(I) = FFiles(I).VirtualFileName
29            Next
30            Return Result
31        End Get
32    End Property
33
34    Public ReadOnly Property FileCount() As Integer
35        Get
36            Return FFiles.Count
37        End Get
38    End Property
39
40    Public Sub AddFile(ByVal virtualFileName As String, ByVal fileName As String)
41        FFiles.Add(New EntryData(fileName, virtualFileName, 0))
42    End Sub
43
44    Friend Sub AddFile(ByVal virtualFileName As String, ByVal fileName As String, ByVal position As Integer)
45        FFiles.Add(New EntryData(fileName, virtualFileName, position))
46    End Sub
47
48    Friend Sub SetFilePosition(ByVal virtualFileName As String, ByVal position As Integer)
49        For Each File As EntryData In FFiles
50            If File.VirtualFileName = virtualFileName Then File.Position = position
51        Next
52    End Sub
53
54    Friend Function GetFilePosition(ByVal virtualFileName As String) As Integer
55        For Each File As EntryData In FFiles
56            If File.VirtualFileName = virtualFileName Then Return File.Position
57        Next
58        Throw New ApplicationException("Cannot find the file: '" + virtualFileName + "' in the archive.")
59    End Function
60
61End Class