|
4 | 4 | using System.Linq;
|
5 | 5 | using System.Text;
|
6 | 6 | using UnityExplorer.Config;
|
7 |
| -using IniParser.Parser; |
8 | 7 | using System.IO;
|
9 | 8 | using UnityEngine;
|
| 9 | +using Tomlet; |
| 10 | +using Tomlet.Models; |
10 | 11 |
|
11 | 12 | namespace UnityExplorer.Loader.STANDALONE
|
12 | 13 | {
|
13 | 14 | public class StandaloneConfigHandler : ConfigHandler
|
14 | 15 | {
|
15 |
| - internal static IniDataParser _parser; |
16 | 16 | internal static string CONFIG_PATH;
|
17 | 17 |
|
18 | 18 | public override void Init()
|
19 | 19 | {
|
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"); |
23 | 21 | }
|
24 | 22 |
|
25 | 23 | public override void LoadConfig()
|
@@ -52,14 +50,11 @@ public bool TryLoadConfig()
|
52 | 50 | if (!File.Exists(CONFIG_PATH))
|
53 | 51 | return false;
|
54 | 52 |
|
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) |
60 | 55 | {
|
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); |
63 | 58 | }
|
64 | 59 |
|
65 | 60 | return true;
|
@@ -89,18 +84,14 @@ public override void OnAnyConfigChanged()
|
89 | 84 |
|
90 | 85 | public override void SaveConfig()
|
91 | 86 | {
|
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()); |
99 | 90 |
|
100 | 91 | if (!Directory.Exists(ExplorerCore.Loader.ExplorerFolder))
|
101 | 92 | Directory.CreateDirectory(ExplorerCore.Loader.ExplorerFolder);
|
102 | 93 |
|
103 |
| - File.WriteAllText(CONFIG_PATH, data.ToString()); |
| 94 | + File.WriteAllText(CONFIG_PATH, document.SerializedValue); |
104 | 95 | }
|
105 | 96 | }
|
106 | 97 | }
|
|
0 commit comments