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.

144 lines
5.3 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 version of the plugin.
  48. /// </summary>
  49. /// <value>the version of the plugin</value>
  50. public Version Version { get; internal set; }
  51. /// <summary>
  52. /// The file the plugin was loaded from.
  53. /// </summary>
  54. /// <value>the file the plugin was loaded from</value>
  55. public FileInfo File { get; internal set; }
  56. // ReSharper disable once UnusedAutoPropertyAccessor.Global
  57. /// <summary>
  58. /// The features this plugin requests.
  59. /// </summary>
  60. /// <value>the list of features requested by the plugin</value>
  61. public IReadOnlyList<Feature> Features => InternalFeatures;
  62. internal readonly List<Feature> InternalFeatures = new List<Feature>();
  63. /// <summary>
  64. /// A list of files (that aren't <see cref="File"/>) that are associated with this plugin.
  65. /// </summary>
  66. /// <value>a list of associated files</value>
  67. public IReadOnlyList<FileInfo> AssociatedFiles { get; private set; } = new List<FileInfo>();
  68. /// <summary>
  69. /// The name of the resource in the plugin assembly containing the plugin's icon.
  70. /// </summary>
  71. /// <value>the name of the plugin's icon</value>
  72. public string IconName { get; private set; }
  73. /// <summary>
  74. /// A link to this plugin's home page, if any.
  75. /// </summary>
  76. /// <value>the <see cref="Uri"/> of the plugin's home page</value>
  77. public Uri PluginHomeLink { get; private set; }
  78. /// <summary>
  79. /// A link to this plugin's source code, if avaliable.
  80. /// </summary>
  81. /// <value>the <see cref="Uri"/> of the plugin's source code</value>
  82. public Uri PluginSourceLink { get; private set; }
  83. /// <summary>
  84. /// A link to a donate page for the author of this plugin, if avaliable.
  85. /// </summary>
  86. /// <value>the <see cref="Uri"/> of the author's donate page</value>
  87. public Uri DonateLink { get; private set; }
  88. internal bool IsSelf;
  89. /// <summary>
  90. /// Whether or not this metadata object represents a bare manifest.
  91. /// </summary>
  92. /// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value>
  93. public bool IsBare { get; internal set; }
  94. private PluginManifest manifest;
  95. internal HashSet<PluginMetadata> Dependencies { get; } = new HashSet<PluginMetadata>();
  96. internal PluginManifest Manifest
  97. {
  98. get => manifest;
  99. set
  100. {
  101. manifest = value;
  102. Name = value.Name;
  103. Version = value.Version;
  104. Id = value.Id;
  105. Author = value.Author;
  106. IconName = value.IconPath;
  107. PluginHomeLink = value.Links.ProjectHome;
  108. PluginSourceLink = value.Links.ProjectSource;
  109. DonateLink = value.Links.Donate;
  110. AssociatedFiles = value.Files
  111. .Select(f => Path.Combine(UnityGame.InstallPath, f))
  112. .Select(p => new FileInfo(p)).ToList();
  113. }
  114. }
  115. /// <summary>
  116. /// The <see cref="IPA.RuntimeOptions"/> that the plugin specified in its <see cref="PluginAttribute"/>.
  117. /// </summary>
  118. public RuntimeOptions RuntimeOptions { get; internal set; }
  119. /// <summary>
  120. /// Gets all of the metadata as a readable string.
  121. /// </summary>
  122. /// <returns>the readable printable metadata string</returns>
  123. public override string ToString() => $"{Name}({Id}@{Version})({PluginType?.FullName}) from '{Utils.GetRelativePath(File?.FullName, UnityGame.InstallPath)}'";
  124. }
  125. }