Change ExplorerFolder path and refactor

This commit is contained in:
Sinai
2022-04-12 00:26:01 +10:00
parent f19a1dd25e
commit 96451477ee
10 changed files with 90 additions and 36 deletions

View File

@ -44,9 +44,10 @@ namespace UnityExplorer
private BepInExConfigHandler _configHandler;
public Harmony HarmonyInstance => s_harmony;
private static readonly Harmony s_harmony = new Harmony(ExplorerCore.GUID);
public string ExplorerFolder => Path.Combine(Paths.PluginPath, ExplorerCore.NAME);
private static readonly Harmony s_harmony = new(ExplorerCore.GUID);
public string ExplorerFolderName => ExplorerCore.DEFAULT_EXPLORER_FOLDER_NAME;
public string ExplorerFolderDestination => Paths.PluginPath;
public Action<object> OnLogMessage => LogSource.LogMessage;
public Action<object> OnLogWarning => LogSource.LogWarning;

View File

@ -8,7 +8,8 @@ namespace UnityExplorer
{
public interface IExplorerLoader
{
string ExplorerFolder { get; }
string ExplorerFolderDestination { get; }
string ExplorerFolderName { get; }
string UnhollowedModulesFolder { get; }
ConfigHandler ConfigHandler { get; }

View File

@ -20,9 +20,8 @@ namespace UnityExplorer
{
public class ExplorerMelonMod : MelonMod, IExplorerLoader
{
public static ExplorerMelonMod Instance;
public string ExplorerFolder => Path.Combine(MelonHandler.ModsDirectory, ExplorerCore.NAME);
public string ExplorerFolderName => ExplorerCore.DEFAULT_EXPLORER_FOLDER_NAME;
public string ExplorerFolderDestination => MelonHandler.ModsDirectory;
public string UnhollowedModulesFolder => Path.Combine(
Path.GetDirectoryName(MelonHandler.ModsDirectory),
@ -37,9 +36,7 @@ namespace UnityExplorer
public override void OnApplicationStart()
{
Instance = this;
_configHandler = new MelonLoaderConfigHandler();
ExplorerCore.Init(this);
}
}

View File

@ -10,6 +10,8 @@ namespace UnityExplorer.Loader.Standalone
{
public class ExplorerEditorLoader : ExplorerStandalone
{
public new string ExplorerFolderName => $"{ExplorerCore.DEFAULT_EXPLORER_FOLDER_NAME}~";
public static void Initialize()
{
Instance = new ExplorerEditorLoader();
@ -33,8 +35,8 @@ namespace UnityExplorer.Loader.Standalone
protected override void CheckExplorerFolder()
{
if (explorerFolder == null)
explorerFolder = Path.Combine(Application.dataPath, "UnityExplorer~");
if (explorerFolderDest == null)
explorerFolderDest = Application.dataPath;
}
}
}

View File

@ -29,15 +29,16 @@ namespace UnityExplorer
public ConfigHandler ConfigHandler => configHandler;
internal StandaloneConfigHandler configHandler;
public string ExplorerFolder
public string ExplorerFolderName => ExplorerCore.DEFAULT_EXPLORER_FOLDER_NAME;
public string ExplorerFolderDestination
{
get
{
CheckExplorerFolder();
return explorerFolder;
return explorerFolderDest;
}
}
protected static string explorerFolder;
protected static string explorerFolderDest;
Action<object> IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); };
Action<object> IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); };
@ -45,14 +46,14 @@ namespace UnityExplorer
/// <summary>
/// Call this to initialize UnityExplorer without adding a log listener or Unhollowed modules path.
/// The default Unhollowed path "UnityExplorer\Modules\" will be used.
/// The default Unhollowed path "sinai-dev-UnityExplorer\Modules\" will be used.
/// </summary>
/// <returns>The new (or active, if one exists) instance of ExplorerStandalone.</returns>
public static ExplorerStandalone CreateInstance() => CreateInstance(null, null);
/// <summary>
/// Call this to initialize UnityExplorer and add a listener for UnityExplorer's log messages, without specifying an Unhollowed modules path.
/// The default Unhollowed path "UnityExplorer\Modules\" will be used.
/// The default Unhollowed path "sinai-dev-UnityExplorer\Modules\" will be used.
/// </summary>
/// <param name="logListener">Your log listener to handle UnityExplorer logs.</param>
/// <returns>The new (or active, if one exists) instance of ExplorerStandalone.</returns>
@ -77,7 +78,7 @@ namespace UnityExplorer
OnLog += logListener;
if (string.IsNullOrEmpty(unhollowedModulesPath) || !Directory.Exists(unhollowedModulesPath))
instance.unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules");
instance.unhollowedPath = Path.Combine(ExplorerCore.ExplorerFolder, "Modules");
else
instance.unhollowedPath = unhollowedModulesPath;
@ -94,16 +95,10 @@ namespace UnityExplorer
protected virtual void CheckExplorerFolder()
{
if (explorerFolder == null)
if (explorerFolderDest == null)
{
explorerFolder =
Path.Combine(
Path.GetDirectoryName(
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)),
"UnityExplorer");
if (!Directory.Exists(explorerFolder))
Directory.CreateDirectory(explorerFolder);
string assemblyLocation = Uri.UnescapeDataString(new Uri(typeof(ExplorerCore).Assembly.CodeBase).AbsolutePath);
explorerFolderDest = Path.GetDirectoryName(assemblyLocation);
}
}
}

View File

@ -17,7 +17,7 @@ namespace UnityExplorer.Loader.Standalone
public override void Init()
{
CONFIG_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "config.cfg");
CONFIG_PATH = Path.Combine(ExplorerCore.ExplorerFolder, "config.cfg");
}
public override void LoadConfig()
@ -92,8 +92,8 @@ namespace UnityExplorer.Loader.Standalone
foreach (var config in ConfigManager.ConfigElements)
document.Put(config.Key, config.Value.BoxedValue.ToString());
if (!Directory.Exists(ExplorerCore.Loader.ExplorerFolder))
Directory.CreateDirectory(ExplorerCore.Loader.ExplorerFolder);
if (!Directory.Exists(ExplorerCore.ExplorerFolder))
Directory.CreateDirectory(ExplorerCore.ExplorerFolder);
File.WriteAllText(CONFIG_PATH, document.SerializedValue);
}