d808c05fb3
- primo rilascio.
118 lines
4.3 KiB
VB.net
118 lines
4.3 KiB
VB.net
'----------------------------------------------------------------------------
|
|
' EgalTech 2015-2015
|
|
'----------------------------------------------------------------------------
|
|
' File : MruList.vb Data : 27.02.15 Versione : 1.6b7
|
|
' Contenuto : Classe MruList (gestione elenco file appena usati).
|
|
'
|
|
'
|
|
'
|
|
' Modifiche : 27.02.15 DS Creazione modulo.
|
|
'
|
|
'
|
|
'----------------------------------------------------------------------------
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
|
|
Imports EgtUILib
|
|
|
|
Public Class MruList
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private m_sIniFile As String
|
|
Private m_sSection As String
|
|
Private m_nMaxEntries As Integer
|
|
Private m_FileNames As Collection
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Sub Init(ByVal sIniFile As String, ByVal sSection As String, ByVal nMaxEntries As Integer)
|
|
' Inizializzo
|
|
m_sIniFile = sIniFile
|
|
m_sSection = sSection
|
|
m_nMaxEntries = nMaxEntries
|
|
m_FileNames = New Collection
|
|
' Carico lista da Ini.
|
|
LoadMruList()
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private Sub LoadMruList()
|
|
' Pulisco la lista dei file
|
|
m_FileNames.Clear()
|
|
' Carico la lista dei file salvati in INI
|
|
Dim sFileName As String = String.Empty
|
|
For i As Integer = 1 To m_nMaxEntries
|
|
Dim sKey As String = K_FILE + i.ToString()
|
|
If GetPrivateProfileString(m_sSection, sKey, "", sFileName, m_sIniFile) > 0 Then
|
|
m_FileNames.Add(sFileName, sFileName)
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private Sub SaveMruList()
|
|
For i As Integer = 1 To m_nMaxEntries
|
|
Dim sKey As String = K_FILE + i.ToString()
|
|
If i <= m_FileNames.Count Then
|
|
WritePrivateProfileString(m_sSection, sKey, m_FileNames(i).ToString, m_sIniFile)
|
|
Else
|
|
WritePrivateProfileString(m_sSection, sKey, "", m_sIniFile)
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Sub Add(ByVal sFileName As String)
|
|
' Se già presente, rimuovo il file dalla lista
|
|
Dim i As Integer = FileNameIndex(sFileName)
|
|
If i > 0 Then
|
|
m_FileNames.Remove(i)
|
|
End If
|
|
' Aggiungo il file in cima alla lista
|
|
If m_FileNames.Count > 0 Then
|
|
m_FileNames.Add(sFileName, sFileName, m_FileNames.Item(1))
|
|
Else
|
|
m_FileNames.Add(sFileName, sFileName)
|
|
End If
|
|
' Se la lista ha superato la massima dimensione, cancello l'ultimo record
|
|
If m_FileNames.Count > m_nMaxEntries Then
|
|
m_FileNames.Remove(m_nMaxEntries + 1)
|
|
End If
|
|
' Salvo la lista aggiornata
|
|
SaveMruList()
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private Function FileNameIndex(ByVal sFileName As String) As Integer
|
|
For i As Integer = 1 To m_FileNames.Count
|
|
If String.Compare(m_FileNames(i).ToString, sFileName, True) = 0 Then
|
|
Return i
|
|
End If
|
|
Next
|
|
Return 0
|
|
End Function
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Sub Remove(ByVal sFileName As String)
|
|
Dim i As Integer = FileNameIndex(sFileName)
|
|
If i > 0 Then
|
|
' Rimuovo il file
|
|
m_FileNames.Remove(i)
|
|
' Salvo lalista aggiornata
|
|
SaveMruList()
|
|
End If
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Function GetFileName(ByVal nInd As Integer, ByRef sFileName As String) As Boolean
|
|
If nInd > 0 And nInd <= m_FileNames.Count() Then
|
|
sFileName = m_FileNames(nInd).ToString()
|
|
Return True
|
|
Else
|
|
sFileName = String.Empty
|
|
Return False
|
|
End If
|
|
|
|
End Function
|
|
|
|
End Class
|