Why Ini file?
JSON[
^] is so much easier these days...
Also, it has been a while since I have worked with INI files but, acording to the
INI file specification - Wikipedia[
^], you can't use multiples of the same key. So this:
[Mods]
+=extendedtimeline.zip
-=BetterGraphicalImprovementsMod.zip
+=RuleTheWaves.zip
-=edfae.zip
Needs to be changed to something like:
[Mods]
file1=extendedtimeline.zip,+
file2=BetterGraphicalImprovementsMod.zip,-
file3=RuleTheWaves.zip,+
file4=edfae.zip,-
If you do choose to work with JSON, this article has a JsonHelper class that will convert to/from class/text(file):
Working with JSON in C# & VB[
^]
UPDATE: Here is what it would look like if you changed to JSON and used the helper class from the link above:
1. Config file:
{
"Mods": {
"Files": [{
"Name": "extendedtimeline.zip",
"IsActive": true
},
{
"Name": "BetterGraphicalImprovementsMod.zip",
"IsActive": false
},
{
"Name": "RuleTheWaves.zip",
"IsActive": true
},
{
"Name": "edfae.zip",
"IsActive": false
}]
}
}
2. As a class structure:
Class Settings
Public Property Mods As ModFiles
End Class
Class ModFiles
Public Property Files As List(Of ModFile)
End Class
Class ModFile
Public Property Name As String
Public Property IsActive As Boolean
End Class
3. And the code to read/write the config file:
Imports Newtonsoft.Json
Module Module1
Private settingsFilename As String = "Settings.Json"
Private ReadOnly appPath As String = Environment.CurrentDirectory
Private ReadOnly fullPath As String = IO.Path.Combine(appPath, settingsFilename)
Private Property AppSettings() As Settings
Sub Main()
If IO.File.Exists(fullPath) Then
Dim rawJson = IO.File.ReadAllText(fullPath)
AppSettings = JsonHelper.ToClass(Of Settings)(rawJson)
Else
AppSettings = New Settings() With {
.Mods = New ModFiles() With {
.Files = New List(Of ModFile)() From {
New ModFile() With {
.Name = "extendedtimeline.zip",
.IsActive = True},
New ModFile() With {
.Name = "BetterGraphicalImprovementsMod.zip"},
New ModFile() With {
.Name = "RuleTheWaves.zip",
.IsActive = True},
New ModFile() With {
.Name = "edfae.zip"}
}
}
}
Dim rawJson = JsonHelper.FromClass(AppSettings)
IO.File.WriteAllText(fullPath, rawJson)
End If
Debugger.Break()
End Sub
End Module