7502018d20
There is an asset in the store I grabbed. the coding is WAY above my head, I got about half of it and integrated and adapted what I can to it. im going as far as I can with it and ill come back in a few month when I understand t better.
82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using Mono.Cecil;
|
|
|
|
using System.Reflection;
|
|
|
|
namespace ModTool.Shared
|
|
{
|
|
/// <summary>
|
|
/// Utility for finding Assemblies.
|
|
/// </summary>
|
|
public class AssemblyUtility
|
|
{
|
|
public static List<string> GetAssemblies(string path, Func<string, bool> filter = null)
|
|
{
|
|
List<string> assemblies = new List<string>();
|
|
|
|
GetAssemblies(assemblies, path, filter);
|
|
|
|
return assemblies;
|
|
}
|
|
|
|
public static void GetAssemblies(List<string> assemblies, string path, Func<string, bool> filter = null)
|
|
{
|
|
var assemblyFiles = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
|
|
|
|
foreach (var assembly in assemblyFiles)
|
|
{
|
|
AssemblyName assemblyName;
|
|
|
|
try
|
|
{
|
|
assemblyName = AssemblyName.GetAssemblyName(assembly);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogUtility.LogDebug(e.Message);
|
|
continue;
|
|
}
|
|
|
|
string name = assemblyName.Name;
|
|
|
|
if (name == "ModTool" || name.StartsWith("ModTool."))
|
|
continue;
|
|
|
|
if (IsShared(assembly))
|
|
continue;
|
|
|
|
if (assembly.Contains("Editor"))
|
|
continue;
|
|
|
|
if(filter != null && !filter(assembly))
|
|
continue;
|
|
|
|
assemblies.Add(assembly);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is an assembly shared with the mod exporter?
|
|
/// </summary>
|
|
/// <param name="path">The assembly's file path.</param>
|
|
/// <returns>True if an assembly is shared with the mod exporter.</returns>
|
|
public static bool IsShared(string path)
|
|
{
|
|
string name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
foreach (string sharedAsset in ModToolSettings.sharedAssets)
|
|
{
|
|
if (!sharedAsset.EndsWith(".asmdef") && !sharedAsset.EndsWith(".dll"))
|
|
continue;
|
|
|
|
if (Path.GetFileNameWithoutExtension(sharedAsset) == name)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|