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.

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