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.

151 lines
5.6 KiB

4 years ago
  1. using IPA.Loader.Features;
  2. using IPA.Utilities;
  3. using Mono.Cecil;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using Version = SemVer.Version;
  10. #if NET3
  11. using Net3_Proxy;
  12. using Path = Net3_Proxy.Path;
  13. #endif
  14. namespace IPA.Loader
  15. {
  16. /// <summary>
  17. /// A class which describes a loaded plugin.
  18. /// </summary>
  19. public class PluginMetadata
  20. {
  21. /// <summary>
  22. /// The assembly the plugin was loaded from.
  23. /// </summary>
  24. /// <value>the loaded Assembly that contains the plugin main type</value>
  25. public Assembly Assembly { get; internal set; }
  26. /// <summary>
  27. /// The TypeDefinition for the main type of the plugin.
  28. /// </summary>
  29. /// <value>the Cecil definition for the plugin main type</value>
  30. public TypeDefinition PluginType { get; internal set; }
  31. /// <summary>
  32. /// The human readable name of the plugin.
  33. /// </summary>
  34. /// <value>the name of the plugin</value>
  35. public string Name { get; internal set; }
  36. /// <summary>
  37. /// The BeatMods ID of the plugin, or null if it doesn't have one.
  38. /// </summary>
  39. /// <value>the updater ID of the plugin</value>
  40. public string Id { get; internal set; }
  41. /// <summary>
  42. /// The name of the author that wrote this plugin.
  43. /// </summary>
  44. /// <value>the name of the plugin's author</value>
  45. public string Author { get; private set; }
  46. /// <summary>
  47. /// The description of this plugin.
  48. /// </summary>
  49. /// <value>the description of the plugin</value>
  50. public string Description { get; private set; }
  51. /// <summary>
  52. /// The version of the plugin.
  53. /// </summary>
  54. /// <value>the version of the plugin</value>
  55. public Version Version { get; internal set; }
  56. /// <summary>
  57. /// The file the plugin was loaded from.
  58. /// </summary>
  59. /// <value>the file the plugin was loaded from</value>
  60. public FileInfo File { get; internal set; }
  61. // ReSharper disable once UnusedAutoPropertyAccessor.Global
  62. /// <summary>
  63. /// The features this plugin requests.
  64. /// </summary>
  65. /// <value>the list of features requested by the plugin</value>
  66. public IReadOnlyList<Feature> Features => InternalFeatures;
  67. internal readonly List<Feature> InternalFeatures = new List<Feature>();
  68. /// <summary>
  69. /// A list of files (that aren't <see cref="File"/>) that are associated with this plugin.
  70. /// </summary>
  71. /// <value>a list of associated files</value>
  72. public IReadOnlyList<FileInfo> AssociatedFiles { get; private set; } = new List<FileInfo>();
  73. /// <summary>
  74. /// The name of the resource in the plugin assembly containing the plugin's icon.
  75. /// </summary>
  76. /// <value>the name of the plugin's icon</value>
  77. public string IconName { get; private set; }
  78. /// <summary>
  79. /// A link to this plugin's home page, if any.
  80. /// </summary>
  81. /// <value>the <see cref="Uri"/> of the plugin's home page</value>
  82. public Uri PluginHomeLink { get; private set; }
  83. /// <summary>
  84. /// A link to this plugin's source code, if avaliable.
  85. /// </summary>
  86. /// <value>the <see cref="Uri"/> of the plugin's source code</value>
  87. public Uri PluginSourceLink { get; private set; }
  88. /// <summary>
  89. /// A link to a donate page for the author of this plugin, if avaliable.
  90. /// </summary>
  91. /// <value>the <see cref="Uri"/> of the author's donate page</value>
  92. public Uri DonateLink { get; private set; }
  93. internal bool IsSelf;
  94. /// <summary>
  95. /// Whether or not this metadata object represents a bare manifest.
  96. /// </summary>
  97. /// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value>
  98. public bool IsBare { get; internal set; }
  99. private PluginManifest manifest;
  100. internal HashSet<PluginMetadata> Dependencies { get; } = new HashSet<PluginMetadata>();
  101. internal PluginManifest Manifest
  102. {
  103. get => manifest;
  104. set
  105. {
  106. manifest = value;
  107. Name = value.Name;
  108. Version = value.Version;
  109. Id = value.Id;
  110. Description = value.Description;
  111. Author = value.Author;
  112. IconName = value.IconPath;
  113. PluginHomeLink = value.Links?.ProjectHome;
  114. PluginSourceLink = value.Links?.ProjectSource;
  115. DonateLink = value.Links?.Donate;
  116. AssociatedFiles = value.Files
  117. .Select(f => Path.Combine(UnityGame.InstallPath, f))
  118. .Select(p => new FileInfo(p)).ToList();
  119. }
  120. }
  121. /// <summary>
  122. /// The <see cref="IPA.RuntimeOptions"/> that the plugin specified in its <see cref="PluginAttribute"/>.
  123. /// </summary>
  124. public RuntimeOptions RuntimeOptions { get; internal set; }
  125. /// <summary>
  126. /// Gets all of the metadata as a readable string.
  127. /// </summary>
  128. /// <returns>the readable printable metadata string</returns>
  129. public override string ToString() => $"{Name}({Id}@{Version})({PluginType?.FullName}) from '{Utils.GetRelativePath(File?.FullName, UnityGame.InstallPath)}'";
  130. }
  131. }