You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.7 KiB

4 years ago
4 years ago
  1. using IPA.Loader.Features;
  2. using IPA.Utilities;
  3. using Mono.Cecil;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Reflection;
  7. using Version = SemVer.Version;
  8. #if NET3
  9. using Net3_Proxy;
  10. #endif
  11. namespace IPA.Loader
  12. {
  13. /// <summary>
  14. /// A class which describes a loaded plugin.
  15. /// </summary>
  16. public class PluginMetadata
  17. {
  18. /// <summary>
  19. /// The assembly the plugin was loaded from.
  20. /// </summary>
  21. /// <value>the loaded Assembly that contains the plugin main type</value>
  22. public Assembly Assembly { get; internal set; }
  23. /// <summary>
  24. /// The TypeDefinition for the main type of the plugin.
  25. /// </summary>
  26. /// <value>the Cecil definition for the plugin main type</value>
  27. public TypeDefinition PluginType { get; internal set; }
  28. /// <summary>
  29. /// The human readable name of the plugin.
  30. /// </summary>
  31. /// <value>the name of the plugin</value>
  32. public string Name { get; internal set; }
  33. /// <summary>
  34. /// The BeatMods ID of the plugin, or null if it doesn't have one.
  35. /// </summary>
  36. /// <value>the updater ID of the plugin</value>
  37. public string Id { get; internal set; }
  38. /// <summary>
  39. /// The version of the plugin.
  40. /// </summary>
  41. /// <value>the version of the plugin</value>
  42. public Version Version { get; internal set; }
  43. /// <summary>
  44. /// The file the plugin was loaded from.
  45. /// </summary>
  46. /// <value>the file the plugin was loaded from</value>
  47. public FileInfo File { get; internal set; }
  48. // ReSharper disable once UnusedAutoPropertyAccessor.Global
  49. /// <summary>
  50. /// The features this plugin requests.
  51. /// </summary>
  52. /// <value>the list of features requested by the plugin</value>
  53. public IReadOnlyList<Feature> Features => InternalFeatures;
  54. internal readonly List<Feature> InternalFeatures = new List<Feature>();
  55. internal bool IsSelf;
  56. /// <summary>
  57. /// Whether or not this metadata object represents a bare manifest.
  58. /// </summary>
  59. /// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value>
  60. public bool IsBare { get; internal set; }
  61. private PluginManifest manifest;
  62. internal HashSet<PluginMetadata> Dependencies { get; } = new HashSet<PluginMetadata>();
  63. internal PluginManifest Manifest
  64. {
  65. get => manifest;
  66. set
  67. {
  68. manifest = value;
  69. Name = value.Name;
  70. Version = value.Version;
  71. Id = value.Id;
  72. }
  73. }
  74. /// <summary>
  75. /// The <see cref="IPA.RuntimeOptions"/> that the plugin specified in its <see cref="PluginAttribute"/>.
  76. /// </summary>
  77. public RuntimeOptions RuntimeOptions { get; internal set; }
  78. /// <summary>
  79. /// Whether the plugin referred to by this metadata object is a BSIPA 4 attribute plugin.
  80. /// </summary>
  81. /// <value><see langword="true"/> if the plugin is a BSIPA 4 plugin, <see langword="false"/> if it is a BSIPA 3 plugin.</value>
  82. public bool IsAttributePlugin { get; internal set; } = false;
  83. /// <summary>
  84. /// Gets all of the metadata as a readable string.
  85. /// </summary>
  86. /// <returns>the readable printable metadata string</returns>
  87. public override string ToString() => $"{Name}({Id}@{Version})({PluginType?.FullName}) from '{Utils.GetRelativePath(File?.FullName, UnityGame.InstallPath)}'";
  88. }
  89. }