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.

108 lines
3.8 KiB

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