mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-01 19:13:03 +08:00
Use Tomlet for Standalone config, fix ML double reference
This commit is contained in:
@ -4,22 +4,20 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityExplorer.Config;
|
using UnityExplorer.Config;
|
||||||
using IniParser.Parser;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Tomlet;
|
||||||
|
using Tomlet.Models;
|
||||||
|
|
||||||
namespace UnityExplorer.Loader.STANDALONE
|
namespace UnityExplorer.Loader.STANDALONE
|
||||||
{
|
{
|
||||||
public class StandaloneConfigHandler : ConfigHandler
|
public class StandaloneConfigHandler : ConfigHandler
|
||||||
{
|
{
|
||||||
internal static IniDataParser _parser;
|
|
||||||
internal static string CONFIG_PATH;
|
internal static string CONFIG_PATH;
|
||||||
|
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
CONFIG_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "config.ini");
|
CONFIG_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "config.cfg");
|
||||||
_parser = new IniDataParser();
|
|
||||||
_parser.Configuration.CommentString = "#";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadConfig()
|
public override void LoadConfig()
|
||||||
@ -52,14 +50,11 @@ namespace UnityExplorer.Loader.STANDALONE
|
|||||||
if (!File.Exists(CONFIG_PATH))
|
if (!File.Exists(CONFIG_PATH))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
string ini = File.ReadAllText(CONFIG_PATH);
|
var document = TomlParser.ParseFile(CONFIG_PATH);
|
||||||
|
foreach (var key in document.Keys)
|
||||||
var data = _parser.Parse(ini);
|
|
||||||
|
|
||||||
foreach (var config in data.Sections["Config"])
|
|
||||||
{
|
{
|
||||||
if (ConfigManager.ConfigElements.TryGetValue(config.KeyName, out IConfigElement configElement))
|
var config = ConfigManager.ConfigElements[key];
|
||||||
configElement.BoxedValue = StringToConfigValue(config.Value, configElement.ElementType);
|
config.BoxedValue = StringToConfigValue(document.GetValue(key).StringValue, config.ElementType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -89,18 +84,14 @@ namespace UnityExplorer.Loader.STANDALONE
|
|||||||
|
|
||||||
public override void SaveConfig()
|
public override void SaveConfig()
|
||||||
{
|
{
|
||||||
var data = new IniParser.Model.IniData();
|
var document = TomlDocument.CreateEmpty();
|
||||||
|
foreach (var config in ConfigManager.ConfigElements)
|
||||||
data.Sections.AddSection("Config");
|
document.Put(config.Key, config.Value.BoxedValue.ToString());
|
||||||
var sec = data.Sections["Config"];
|
|
||||||
|
|
||||||
foreach (var entry in ConfigManager.ConfigElements)
|
|
||||||
sec.AddKey(entry.Key, entry.Value.BoxedValue.ToString());
|
|
||||||
|
|
||||||
if (!Directory.Exists(ExplorerCore.Loader.ExplorerFolder))
|
if (!Directory.Exists(ExplorerCore.Loader.ExplorerFolder))
|
||||||
Directory.CreateDirectory(ExplorerCore.Loader.ExplorerFolder);
|
Directory.CreateDirectory(ExplorerCore.Loader.ExplorerFolder);
|
||||||
|
|
||||||
File.WriteAllText(CONFIG_PATH, data.ToString());
|
File.WriteAllText(CONFIG_PATH, document.SerializedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,11 +106,14 @@
|
|||||||
<HintPath>..\lib\mcs-unity\mcs\bin\Release\mcs.dll</HintPath>
|
<HintPath>..\lib\mcs-unity\mcs\bin\Release\mcs.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<!-- Non-MelonLoader (it includes Tomlet) -->
|
||||||
|
<ItemGroup Condition="'$(IsMelonLoader)'=='false'">
|
||||||
|
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
<!-- MelonLoader refs -->
|
<!-- MelonLoader refs -->
|
||||||
<ItemGroup Condition="'$(IsMelonLoader)'=='true'">
|
<ItemGroup Condition="'$(IsMelonLoader)'=='true'">
|
||||||
<Reference Include="MelonLoader">
|
<Reference Include="MelonLoader">
|
||||||
|
Reference in New Issue
Block a user