Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 67c602b

Browse files
committed
Use Tomlet for Standalone config, fix ML double reference
1 parent 8fb7d87 commit 67c602b

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/Loader/Standalone/StandaloneConfigHandler.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
using System.Linq;
55
using System.Text;
66
using UnityExplorer.Config;
7-
using IniParser.Parser;
87
using System.IO;
98
using UnityEngine;
9+
using Tomlet;
10+
using Tomlet.Models;
1011

1112
namespace UnityExplorer.Loader.STANDALONE
1213
{
1314
public class StandaloneConfigHandler : ConfigHandler
1415
{
15-
internal static IniDataParser _parser;
1616
internal static string CONFIG_PATH;
1717

1818
public override void Init()
1919
{
20-
CONFIG_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "config.ini");
21-
_parser = new IniDataParser();
22-
_parser.Configuration.CommentString = "#";
20+
CONFIG_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "config.cfg");
2321
}
2422

2523
public override void LoadConfig()
@@ -52,14 +50,11 @@ public bool TryLoadConfig()
5250
if (!File.Exists(CONFIG_PATH))
5351
return false;
5452

55-
string ini = File.ReadAllText(CONFIG_PATH);
56-
57-
var data = _parser.Parse(ini);
58-
59-
foreach (var config in data.Sections["Config"])
53+
var document = TomlParser.ParseFile(CONFIG_PATH);
54+
foreach (var key in document.Keys)
6055
{
61-
if (ConfigManager.ConfigElements.TryGetValue(config.KeyName, out IConfigElement configElement))
62-
configElement.BoxedValue = StringToConfigValue(config.Value, configElement.ElementType);
56+
var config = ConfigManager.ConfigElements[key];
57+
config.BoxedValue = StringToConfigValue(document.GetValue(key).StringValue, config.ElementType);
6358
}
6459

6560
return true;
@@ -89,18 +84,14 @@ public override void OnAnyConfigChanged()
8984

9085
public override void SaveConfig()
9186
{
92-
var data = new IniParser.Model.IniData();
93-
94-
data.Sections.AddSection("Config");
95-
var sec = data.Sections["Config"];
96-
97-
foreach (var entry in ConfigManager.ConfigElements)
98-
sec.AddKey(entry.Key, entry.Value.BoxedValue.ToString());
87+
var document = TomlDocument.CreateEmpty();
88+
foreach (var config in ConfigManager.ConfigElements)
89+
document.Put(config.Key, config.Value.BoxedValue.ToString());
9990

10091
if (!Directory.Exists(ExplorerCore.Loader.ExplorerFolder))
10192
Directory.CreateDirectory(ExplorerCore.Loader.ExplorerFolder);
10293

103-
File.WriteAllText(CONFIG_PATH, data.ToString());
94+
File.WriteAllText(CONFIG_PATH, document.SerializedValue);
10495
}
10596
}
10697
}

src/UnityExplorer.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@
106106
<HintPath>..\lib\mcs-unity\mcs\bin\Release\mcs.dll</HintPath>
107107
<Private>False</Private>
108108
</Reference>
109-
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
110-
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
111-
<Private>False</Private>
112-
</Reference>
113109
</ItemGroup>
110+
<!-- Non-MelonLoader (it includes Tomlet) -->
111+
<ItemGroup Condition="'$(IsMelonLoader)'=='false'">
112+
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
113+
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
114+
<Private>False</Private>
115+
</Reference>
116+
</ItemGroup>
114117
<!-- MelonLoader refs -->
115118
<ItemGroup Condition="'$(IsMelonLoader)'=='true'">
116119
<Reference Include="MelonLoader">

0 commit comments

Comments
 (0)