// Copyright (c) Nate McMaster, Dalamud contributors. // Licensed under the Apache License, Version 2.0. See License.txt in the Loader root for license information. using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.Loader; namespace Dalamud.Plugin.Internal.Loader; /// /// Represents the configuration for a plugin loader. /// internal class LoaderConfig { /// /// Initializes a new instance of the class. /// /// The full file path to the main assembly for the plugin. public LoaderConfig(string mainAssemblyPath) { if (string.IsNullOrEmpty(mainAssemblyPath)) throw new ArgumentException("Value must be null or not empty", nameof(mainAssemblyPath)); if (!Path.IsPathRooted(mainAssemblyPath)) throw new ArgumentException("Value must be an absolute file path", nameof(mainAssemblyPath)); if (!File.Exists(mainAssemblyPath)) throw new ArgumentException("Value must exist", nameof(mainAssemblyPath)); this.MainAssemblyPath = mainAssemblyPath; } /// /// Gets the file path to the main assembly. /// public string MainAssemblyPath { get; } /// /// Gets a list of assemblies which should be treated as private. /// public ICollection PrivateAssemblies { get; } = new List(); /// /// Gets a list of assemblies which should be unified between the host and the plugin. /// /// what-are-shared-types public ICollection<(AssemblyName Name, bool Recursive)> SharedAssemblies { get; } = new List<(AssemblyName Name, bool Recursive)>(); /// /// Gets or sets a value indicating whether attempt to unify all types from a plugin with the host. /// /// This does not guarantee types will unify. /// /// what-are-shared-types /// public bool PreferSharedTypes { get; set; } /// /// Gets or sets the default used by the . /// Use this feature if the of the is not the Runtime's default load context. /// i.e. (AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly) != . /// public AssemblyLoadContext DefaultContext { get; set; } = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()) ?? AssemblyLoadContext.Default; /// /// Gets or sets a value indicating whether the plugin can be unloaded from memory. /// public bool IsUnloadable { get; set; } /// /// Gets or sets a value indicating whether to load assemblies into memory in order to not lock files. /// public bool LoadInMemory { get; set; } }