2020-09-18 18:38:11 +10:00
|
|
|
|
using System.IO;
|
2020-09-10 20:31:09 +10:00
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-10-23 01:50:33 +11:00
|
|
|
|
namespace ExplorerBeta.Config
|
2020-09-10 20:31:09 +10:00
|
|
|
|
{
|
|
|
|
|
public class ModConfig
|
|
|
|
|
{
|
|
|
|
|
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
|
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\Explorer";
|
2020-09-10 20:31:09 +10:00
|
|
|
|
[XmlIgnore] private const string SETTINGS_PATH = EXPLORER_FOLDER + @"\config.xml";
|
|
|
|
|
|
|
|
|
|
[XmlIgnore] public static ModConfig Instance;
|
|
|
|
|
|
2020-10-08 06:15:42 +11:00
|
|
|
|
// Actual configs
|
|
|
|
|
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
2020-09-10 20:31:09 +10:00
|
|
|
|
public Vector2 Default_Window_Size = new Vector2(550, 700);
|
2020-10-08 06:15:42 +11:00
|
|
|
|
public int Default_Page_Limit = 20;
|
|
|
|
|
public bool Bitwise_Support = false;
|
|
|
|
|
public bool Tab_View = true;
|
2020-10-10 20:19:56 +11:00
|
|
|
|
public string Default_Output_Path = @"Mods\Explorer";
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
|
|
|
|
public static void OnLoad()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(EXPLORER_FOLDER))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(EXPLORER_FOLDER);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-11 00:17:13 +10:00
|
|
|
|
if (LoadSettings()) return;
|
|
|
|
|
|
|
|
|
|
Instance = new ModConfig();
|
|
|
|
|
SaveSettings();
|
2020-09-10 20:31:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-11 00:17:13 +10:00
|
|
|
|
// returns true if settings successfully loaded
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|