Browse Source

Implement subfolder plugin loading

pull/102/head
Arimodu 1 year ago
parent
commit
788048d81c
1 changed files with 40 additions and 7 deletions
  1. +40
    -7
      IPA.Loader/Loader/PluginLoader.cs

+ 40
- 7
IPA.Loader/Loader/PluginLoader.cs View File

@ -83,9 +83,37 @@ namespace IPA.Loader
private static readonly Regex embeddedTextDescriptionPattern = new(@"#!\[(.+)\]", RegexOptions.Compiled | RegexOptions.Singleline); private static readonly Regex embeddedTextDescriptionPattern = new(@"#!\[(.+)\]", RegexOptions.Compiled | RegexOptions.Singleline);
public static string[] LoadFilesRecursively(string folderPath, string fileName)
{
var dlls = new List<string>();
dlls.AddRange(Directory.GetFiles(folderPath, fileName));
foreach (var subfolder in Directory.GetDirectories(folderPath))
{
dlls.AddRange(LoadFilesRecursively(subfolder, fileName));
}
return dlls.ToArray();
}
public static string[] LoadDirectoriesRecursively(string folderPath)
{
var directories = new List<string>();
foreach (var subfolder in Directory.GetDirectories(folderPath))
{
directories.AddRange(LoadDirectoriesRecursively(subfolder));
}
directories.Add(folderPath);
return directories.ToArray();
}
internal static void LoadMetadata() internal static void LoadMetadata()
{ {
string[] plugins = Directory.GetFiles(UnityGame.PluginsPath, "*.dll");
string[] plugins = LoadFilesRecursively(UnityGame.PluginsPath, "*.dll");
try try
{ {
@ -116,13 +144,18 @@ namespace IPA.Loader
} }
using var resolver = new CecilLibLoader(); using var resolver = new CecilLibLoader();
resolver.AddSearchDirectory(UnityGame.LibraryPath);
resolver.AddSearchDirectory(UnityGame.PluginsPath);
foreach (var libSubDirectory in LoadDirectoriesRecursively(UnityGame.LibraryPath))
resolver.AddSearchDirectory(libSubDirectory);
foreach (var pluginSubDirectory in LoadDirectoriesRecursively(UnityGame.PluginsPath))
resolver.AddSearchDirectory(pluginSubDirectory);
foreach (var plugin in plugins) foreach (var plugin in plugins)
{ {
var metadata = new PluginMetadata var metadata = new PluginMetadata
{ {
File = new FileInfo(Path.Combine(UnityGame.PluginsPath, plugin)),
File = new FileInfo(plugin),
IsSelf = false IsSelf = false
}; };
@ -263,15 +296,15 @@ namespace IPA.Loader
} }
} }
IEnumerable<string> bareManifests = Directory.GetFiles(UnityGame.PluginsPath, "*.json");
bareManifests = bareManifests.Concat(Directory.GetFiles(UnityGame.PluginsPath, "*.manifest"));
IEnumerable<string> bareManifests = LoadFilesRecursively(UnityGame.PluginsPath, "*.json");
bareManifests = bareManifests.Concat(LoadFilesRecursively(UnityGame.PluginsPath, "*.manifest"));
foreach (var manifest in bareManifests) foreach (var manifest in bareManifests)
{ {
try try
{ {
var metadata = new PluginMetadata var metadata = new PluginMetadata
{ {
File = new FileInfo(Path.Combine(UnityGame.PluginsPath, manifest)),
File = new FileInfo(manifest),
IsSelf = false, IsSelf = false,
IsBare = true, IsBare = true,
}; };


Loading…
Cancel
Save