2ff390d577
- Primo commit.
68 lines
2.5 KiB
VB.net
68 lines
2.5 KiB
VB.net
Imports System.IO
|
|
Imports System.Runtime.InteropServices
|
|
Imports System.Text
|
|
|
|
Public Class IniManager
|
|
|
|
#Region "METODO NON FUNZIONANTE"
|
|
|
|
<DllImport("kernel32")>
|
|
Public Shared Function GetPrivateProfileString(ByVal section As String, ByVal key As String,
|
|
ByVal def As String, ByVal retVal As StringBuilder,
|
|
ByVal size As Integer, ByVal filePath As String) As Integer
|
|
End Function
|
|
|
|
Public Function GetIniValue(section As String, key As String, filename As String, Optional defaultValue As String = "") As String
|
|
Dim sb As New StringBuilder(500)
|
|
If GetPrivateProfileString(section, key, defaultValue, sb, sb.Capacity, filename) > 0 Then
|
|
Return sb.ToString
|
|
Else
|
|
Return defaultValue
|
|
End If
|
|
End Function
|
|
|
|
#End Region
|
|
|
|
#Region "METODO FUNZIONANTE"
|
|
|
|
Public Function ReadIni() As String
|
|
Dim reader As StreamReader = My.Computer.FileSystem.OpenTextFileReader("C:\EgtProg\LicenceManager\config.ini")
|
|
|
|
Dim a As String
|
|
Dim result As String = ""
|
|
Do
|
|
a = reader.ReadLine
|
|
If (a Is Nothing) Then Exit Do
|
|
Dim fileline As String = a.Trim()
|
|
If (fileline.StartsWith("[") And fileline.EndsWith("]")) Then Continue Do
|
|
'
|
|
' Code here
|
|
'
|
|
Dim index As Integer = fileline.IndexOf("=")
|
|
If (index < 0) Then Continue Do
|
|
Dim key As String = fileline.Substring(0, index).Trim()
|
|
' Dim ID As String = fileline.Substring(0, fileline.IndexOf(":"))
|
|
Dim value As String = fileline.Substring(index + 1).Trim()
|
|
' String comment = ""
|
|
index = value.IndexOf("'")
|
|
If (index > -1) Then
|
|
' ID = fileline.Substring(0, fileline.IndexOf(":"))
|
|
' comment = value.Substring(index).Trim()
|
|
value = value.Substring(0, index).Trim()
|
|
End If
|
|
result &= key & "=" & value & ";"
|
|
Loop Until a Is Nothing
|
|
' result.TrimEnd(";")
|
|
reader.Close()
|
|
Return result
|
|
End Function
|
|
|
|
#End Region
|
|
|
|
'Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
|
|
' Debug.WriteLine(GetIniValue("B_Empty_IndexList", "Count", My.Application.Info.DirectoryPath & "\WorldInfo.ini"))
|
|
' Debug.WriteLine(GetIniValue("B_Use_IndexList", "Count", My.Application.Info.DirectoryPath & "\WorldInfo.ini"))
|
|
'End Sub
|
|
|
|
End Class
|