2020-11-08 21:04:41 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2020-09-10 20:31:09 +10:00
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-11-03 20:59:13 +11:00
|
|
|
|
namespace UnityExplorer.Config
|
2020-09-10 20:31:09 +10:00
|
|
|
|
{
|
|
|
|
|
public class ModConfig
|
|
|
|
|
{
|
|
|
|
|
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
|
|
|
|
|
|
2020-11-08 21:04:41 +11:00
|
|
|
|
//[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
|
|
|
|
|
[XmlIgnore] private const string SETTINGS_PATH = ExplorerCore.EXPLORER_FOLDER + @"\config.xml";
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
|
|
|
|
[XmlIgnore] public static ModConfig Instance;
|
|
|
|
|
|
2020-10-08 06:15:42 +11:00
|
|
|
|
// Actual configs
|
2020-11-08 21:04:41 +11:00
|
|
|
|
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
|
|
|
|
public bool Force_Unlock_Mouse = true;
|
2020-11-12 16:15:41 +11:00
|
|
|
|
public int Default_Page_Limit = 25;
|
2020-11-08 21:04:41 +11:00
|
|
|
|
public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER;
|
|
|
|
|
public bool Log_Unity_Debug = false;
|
2020-11-12 20:31:08 +11:00
|
|
|
|
public bool Save_Logs_To_Disk = true;
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
2020-11-08 21:04:41 +11:00
|
|
|
|
public static event Action OnConfigChanged;
|
|
|
|
|
|
|
|
|
|
internal static void InvokeConfigChanged()
|
2020-09-10 20:31:09 +10:00
|
|
|
|
{
|
2020-11-08 21:04:41 +11:00
|
|
|
|
OnConfigChanged?.Invoke();
|
|
|
|
|
}
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
2020-11-08 21:04:41 +11:00
|
|
|
|
public static void OnLoad()
|
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
if (LoadSettings())
|
|
|
|
|
return;
|
2020-09-11 00:17:13 +10:00
|
|
|
|
|
|
|
|
|
Instance = new ModConfig();
|
|
|
|
|
SaveSettings();
|
2020-09-10 20:31:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:57:28 +10:00
|
|
|
|
public static bool LoadSettings()
|
2020-09-10 20:31:09 +10:00
|
|
|
|
{
|
2020-10-01 18:57:28 +10:00
|
|
|
|
if (!File.Exists(SETTINGS_PATH))
|
2020-09-11 00:17:13 +10:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var file = File.OpenRead(SETTINGS_PATH))
|
|
|
|
|
Instance = (ModConfig)Serializer.Deserialize(file);
|
|
|
|
|
}
|
2020-10-08 06:15:42 +11:00
|
|
|
|
catch
|
2020-09-11 00:17:13 +10:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
2020-09-11 00:17:13 +10:00
|
|
|
|
return Instance != null;
|
2020-09-10 20:31:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:57:28 +10:00
|
|
|
|
public static void SaveSettings()
|
2020-09-10 20:31:09 +10:00
|
|
|
|
{
|
2020-10-01 18:57:28 +10:00
|
|
|
|
if (File.Exists(SETTINGS_PATH))
|
2020-09-10 20:31:09 +10:00
|
|
|
|
File.Delete(SETTINGS_PATH);
|
|
|
|
|
|
2020-09-11 00:17:13 +10:00
|
|
|
|
using (var file = File.Create(SETTINGS_PATH))
|
|
|
|
|
Serializer.Serialize(file, Instance);
|
2020-09-10 20:31:09 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|