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.

570 lines
25 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using IPA.Config;
  10. using IPA.Old;
  11. using IPA.Utilities;
  12. using Mono.Cecil;
  13. using UnityEngine;
  14. using Logger = IPA.Logging.Logger;
  15. using System.Threading.Tasks;
  16. #if NET4
  17. using TaskEx = System.Threading.Tasks.Task;
  18. using Task = System.Threading.Tasks.Task;
  19. #endif
  20. #if NET3
  21. using Net3_Proxy;
  22. using Path = Net3_Proxy.Path;
  23. using File = Net3_Proxy.File;
  24. using Directory = Net3_Proxy.Directory;
  25. #endif
  26. namespace IPA.Loader
  27. {
  28. /// <summary>
  29. /// The manager class for all plugins.
  30. /// </summary>
  31. public static class PluginManager
  32. {
  33. #pragma warning disable CS0618 // Type or member is obsolete (IPlugin)
  34. private static List<PluginExecutor> _bsPlugins;
  35. internal static IEnumerable<PluginExecutor> BSMetas => _bsPlugins;
  36. /// <summary>
  37. /// Gets info about the enabled plugin with the specified name.
  38. /// </summary>
  39. /// <param name="name">the name of the plugin to get (must be an exact match)</param>
  40. /// <returns>the plugin metadata for the requested plugin or <see langword="null"/> if it doesn't exist or is disabled</returns>
  41. public static PluginMetadata GetPlugin(string name)
  42. => BSMetas.Select(p => p.Metadata).FirstOrDefault(p => p.Name == name);
  43. /// <summary>
  44. /// Gets info about the enabled plugin with the specified ID.
  45. /// </summary>
  46. /// <param name="name">the ID name of the plugin to get (must be an exact match)</param>
  47. /// <returns>the plugin metadata for the requested plugin or <see langword="null"/> if it doesn't exist or is disabled</returns>
  48. public static PluginMetadata GetPluginFromId(string name)
  49. => BSMetas.Select(p => p.Metadata).FirstOrDefault(p => p.Id == name);
  50. /// <summary>
  51. /// Gets a disabled plugin's metadata by its name.
  52. /// </summary>
  53. /// <param name="name">the name of the disabled plugin to get</param>
  54. /// <returns>the metadata for the corresponding plugin</returns>
  55. public static PluginMetadata GetDisabledPlugin(string name) =>
  56. DisabledPlugins.FirstOrDefault(p => p.Name == name);
  57. /// <summary>
  58. /// Gets a disabled plugin's metadata by its ID.
  59. /// </summary>
  60. /// <param name="name">the ID of the disabled plugin to get</param>
  61. /// <returns>the metadata for the corresponding plugin</returns>
  62. public static PluginMetadata GetDisabledPluginFromId(string name) =>
  63. DisabledPlugins.FirstOrDefault(p => p.Id == name);
  64. /// <summary>
  65. /// Creates a new transaction for mod enabling and disabling mods simultaneously.
  66. /// </summary>
  67. /// <returns>a new <see cref="StateTransitionTransaction"/> that captures the current state of loaded mods</returns>
  68. public static StateTransitionTransaction PluginStateTransaction()
  69. => new StateTransitionTransaction(AllPlugins, DisabledPlugins);
  70. private static readonly object commitTransactionLockObject = new object();
  71. internal static Task CommitTransaction(StateTransitionTransaction transaction)
  72. {
  73. lock (commitTransactionLockObject)
  74. {
  75. if (transaction.CurrentlyEnabled.Except(AllPlugins)
  76. .Concat(AllPlugins.Except(transaction.CurrentlyEnabled)).Any()
  77. || transaction.CurrentlyDisabled.Except(DisabledPlugins)
  78. .Concat(DisabledPlugins.Except(transaction.DisabledPlugins)).Any())
  79. { // ensure that the transaction's base state reflects the current state, otherwise throw
  80. throw new InvalidOperationException("Transaction no longer resembles the current state of plugins");
  81. }
  82. var toEnable = transaction.ToEnable;
  83. var toDisable = transaction.ToDisable;
  84. transaction.Dispose();
  85. {
  86. // first enable the mods that need to be
  87. void DeTree(List<PluginMetadata> into, IEnumerable<PluginMetadata> tree)
  88. {
  89. foreach (var st in tree)
  90. if (toEnable.Contains(st) && !into.Contains(st))
  91. {
  92. DeTree(into, st.Dependencies);
  93. into.Add(st);
  94. }
  95. }
  96. var enableOrder = new List<PluginMetadata>();
  97. DeTree(enableOrder, toEnable);
  98. foreach (var meta in enableOrder)
  99. {
  100. var executor = runtimeDisabledPlugins.FirstOrDefault(e => e.Metadata == meta);
  101. if (executor != null)
  102. runtimeDisabledPlugins.Remove(executor);
  103. else
  104. executor = PluginLoader.InitPlugin(meta, AllPlugins);
  105. if (executor == null) continue; // couldn't initialize, skip to next
  106. PluginLoader.DisabledPlugins.Remove(meta);
  107. DisabledConfig.Instance.DisabledModIds.Remove(meta.Id ?? meta.Name);
  108. _bsPlugins.Add(executor);
  109. try
  110. {
  111. executor.Enable();
  112. }
  113. catch (Exception e)
  114. {
  115. Logger.loader.Error($"Error while enabling {meta.Id}:");
  116. Logger.loader.Error(e);
  117. // this should still be considered enabled, hence its position
  118. }
  119. }
  120. }
  121. Task result;
  122. {
  123. // then disable the mods that need to be
  124. static DisableExecutor MakeDisableExec(PluginExecutor e)
  125. => new DisableExecutor
  126. {
  127. Executor = e,
  128. Dependents = BSMetas.Where(f => f.Metadata.Dependencies.Contains(e.Metadata)).Select(MakeDisableExec)
  129. };
  130. var disableExecs = toDisable.Select(m => BSMetas.FirstOrDefault(e => e.Metadata == m)).NonNull().ToArray(); // eagerly evaluate once
  131. foreach (var exec in disableExecs)
  132. {
  133. runtimeDisabledPlugins.Add(exec);
  134. PluginLoader.DisabledPlugins.Add(exec.Metadata);
  135. DisabledConfig.Instance.DisabledModIds.Add(exec.Metadata.Id ?? exec.Metadata.Name);
  136. _bsPlugins.Remove(exec);
  137. }
  138. var disableStructure = disableExecs.Select(MakeDisableExec);
  139. static Task Disable(DisableExecutor exec, Dictionary<PluginExecutor, Task> alreadyDisabled)
  140. {
  141. if (alreadyDisabled.TryGetValue(exec.Executor, out var task))
  142. return task;
  143. else
  144. {
  145. var res = TaskEx.WhenAll(exec.Dependents.Select(d => Disable(d, alreadyDisabled)))
  146. .ContinueWith(t => TaskEx.WhenAll(t, exec.Executor.Disable())).Unwrap();
  147. // The WhenAll above allows us to wait for the executor to disable, but still propagate errors
  148. alreadyDisabled.Add(exec.Executor, res);
  149. return res;
  150. }
  151. }
  152. var disabled = new Dictionary<PluginExecutor, Task>();
  153. result = TaskEx.WhenAll(disableStructure.Select(d => Disable(d, disabled)));
  154. }
  155. DisabledConfig.Instance.Changed();
  156. return result;
  157. }
  158. }
  159. private struct DisableExecutor
  160. {
  161. public PluginExecutor Executor;
  162. public IEnumerable<DisableExecutor> Dependents;
  163. }
  164. // TODO: rewrite below
  165. /*
  166. /// <summary>
  167. /// Disables a plugin, and all dependents.
  168. /// </summary>
  169. /// <param name="plugin">the plugin to disable</param>
  170. /// <returns>whether or not it needs a restart to enable</returns>
  171. public static bool DisablePlugin(PluginInfo plugin)
  172. {
  173. if (plugin == null) return false;
  174. if (plugin.Metadata.IsBare)
  175. {
  176. Logger.loader.Warn($"Trying to disable bare manifest");
  177. return false;
  178. }
  179. if (IsDisabled(plugin.Metadata)) return false;
  180. var needsRestart = false;
  181. Logger.loader.Info($"Disabling {plugin.Metadata.Name}");
  182. var dependents = BSMetas.Where(m => m.Metadata.Dependencies.Contains(plugin.Metadata)).ToList();
  183. needsRestart = dependents.Aggregate(needsRestart, (b, p) => DisablePlugin(p) || b);
  184. DisabledConfig.Instance.DisabledModIds.Add(plugin.Metadata.Id ?? plugin.Metadata.Name);
  185. if (!needsRestart && plugin.Plugin is IDisablablePlugin disable)
  186. {
  187. try
  188. {
  189. disable.OnDisable();
  190. }
  191. catch (Exception e)
  192. {
  193. Logger.loader.Error($"Error occurred trying to disable {plugin.Metadata.Name}");
  194. Logger.loader.Error(e);
  195. }
  196. if (needsRestart)
  197. Logger.loader.Warn($"Disablable plugin has non-disablable dependents; some things may not work properly");
  198. }
  199. else needsRestart = true;
  200. runtimeDisabled.Add(plugin);
  201. _bsPlugins.Remove(plugin);
  202. try
  203. {
  204. PluginDisabled?.Invoke(plugin.Metadata, needsRestart);
  205. }
  206. catch (Exception e)
  207. {
  208. Logger.loader.Error($"Error occurred invoking disable event for {plugin.Metadata.Name}");
  209. Logger.loader.Error(e);
  210. }
  211. return needsRestart;
  212. }
  213. /// <summary>
  214. /// Disables a plugin, and all dependents.
  215. /// </summary>
  216. /// <param name="pluginId">the ID, or name if the ID is null, of the plugin to disable</param>
  217. /// <returns>whether a restart is needed to activate</returns>
  218. public static bool DisablePlugin(string pluginId) => DisablePlugin(GetPluginFromId(pluginId) ?? GetPlugin(pluginId));
  219. /// <summary>
  220. /// Enables a plugin that had been previously disabled.
  221. /// </summary>
  222. /// <param name="plugin">the plugin to enable</param>
  223. /// <returns>whether a restart is needed to activate</returns>
  224. public static bool EnablePlugin(PluginMetadata plugin)
  225. { // TODO: fix some of this behaviour, by adding better support for runtime enable/disable of mods
  226. if (plugin == null) return false;
  227. if (plugin.IsBare)
  228. {
  229. Logger.loader.Warn($"Trying to enable bare manifest");
  230. return false;
  231. }
  232. if (!IsDisabled(plugin)) return false;
  233. Logger.loader.Info($"Enabling {plugin.Name}");
  234. DisabledConfig.Instance.DisabledModIds.Remove(plugin.Id ?? plugin.Name);
  235. var needsRestart = true;
  236. var depsNeedRestart = plugin.Dependencies.Aggregate(false, (b, p) => EnablePlugin(p) || b);
  237. var runtimeInfo = runtimeDisabled.FirstOrDefault(p => p.Metadata == plugin);
  238. if (runtimeInfo != null && runtimeInfo.Plugin is IPlugin newPlugin)
  239. {
  240. try
  241. {
  242. newPlugin.OnEnable();
  243. }
  244. catch (Exception e)
  245. {
  246. Logger.loader.Error($"Error occurred trying to enable {plugin.Name}");
  247. Logger.loader.Error(e);
  248. }
  249. needsRestart = false;
  250. }
  251. else
  252. {
  253. PluginLoader.DisabledPlugins.Remove(plugin);
  254. if (runtimeInfo == null)
  255. {
  256. runtimeInfo = InitPlugin(plugin, AllPlugins.Select(i => i.Metadata));
  257. needsRestart = false;
  258. }
  259. }
  260. if (runtimeInfo != null)
  261. runtimeDisabled.Remove(runtimeInfo);
  262. _bsPlugins.Add(runtimeInfo);
  263. try
  264. {
  265. PluginEnabled?.Invoke(runtimeInfo, needsRestart || depsNeedRestart);
  266. }
  267. catch (Exception e)
  268. {
  269. Logger.loader.Error($"Error occurred invoking enable event for {plugin.Name}");
  270. Logger.loader.Error(e);
  271. }
  272. return needsRestart || depsNeedRestart;
  273. }
  274. /// <summary>
  275. /// Enables a plugin that had been previously disabled.
  276. /// </summary>
  277. /// <param name="pluginId">the ID, or name if the ID is null, of the plugin to enable</param>
  278. /// <returns>whether a restart is needed to activate</returns>
  279. public static bool EnablePlugin(string pluginId) =>
  280. EnablePlugin(GetDisabledPluginFromId(pluginId) ?? GetDisabledPlugin(pluginId));*/
  281. /// <summary>
  282. /// Checks if a given plugin is disabled.
  283. /// </summary>
  284. /// <param name="meta">the plugin to check</param>
  285. /// <returns><see langword="true"/> if the plugin is disabled, <see langword="false"/> otherwise.</returns>
  286. public static bool IsDisabled(PluginMetadata meta) => DisabledPlugins.Contains(meta);
  287. /// <summary>
  288. /// Checks if a given plugin is enabled.
  289. /// </summary>
  290. /// <param name="meta">the plugin to check</param>
  291. /// <returns><see langword="true"/> if the plugin is enabled, <see langword="false"/> otherwise.</returns>
  292. public static bool IsEnabled(PluginMetadata meta) => BSMetas.Any(p => p.Metadata == meta);
  293. /// <summary>
  294. /// Gets a list of disabled BSIPA plugins.
  295. /// </summary>
  296. /// <value>a collection of all disabled plugins as <see cref="PluginMetadata"/></value>
  297. public static IEnumerable<PluginMetadata> DisabledPlugins => PluginLoader.DisabledPlugins;
  298. private static readonly HashSet<PluginExecutor> runtimeDisabledPlugins = new HashSet<PluginExecutor>();
  299. /// <summary>
  300. /// An invoker for the <see cref="PluginEnabled"/> event.
  301. /// </summary>
  302. /// <param name="plugin">the plugin that was enabled</param>
  303. /// <param name="needsRestart">whether it needs a restart to take effect</param>
  304. public delegate void PluginEnableDelegate(PluginMetadata plugin, bool needsRestart);
  305. /// <summary>
  306. /// An invoker for the <see cref="PluginDisabled"/> event.
  307. /// </summary>
  308. /// <param name="plugin">the plugin that was disabled</param>
  309. /// <param name="needsRestart">whether it needs a restart to take effect</param>
  310. public delegate void PluginDisableDelegate(PluginMetadata plugin, bool needsRestart);
  311. /// <summary>
  312. /// Called whenever a plugin is enabled.
  313. /// </summary>
  314. public static event PluginEnableDelegate PluginEnabled;
  315. /// <summary>
  316. /// Called whenever a plugin is disabled.
  317. /// </summary>
  318. public static event PluginDisableDelegate PluginDisabled;
  319. /// <summary>
  320. /// Gets a list of all enabled BSIPA plugins.
  321. /// </summary>
  322. /// <value>a collection of all enabled plugins as <see cref="PluginMetadata"/>s</value>
  323. public static IEnumerable<PluginMetadata> AllPlugins => BSMetas.Select(p => p.Metadata);
  324. /// <summary>
  325. /// An <see cref="IEnumerable{T}"/> of old IPA plugins.
  326. /// </summary>
  327. /// <value>all legacy plugin instances</value>
  328. [Obsolete("I mean, IPlugin shouldn't be used, so why should this? Not renaming to extend support for old plugins.")]
  329. public static IEnumerable<Old.IPlugin> Plugins => _ipaPlugins;
  330. private static List<Old.IPlugin> _ipaPlugins;
  331. internal static IConfigProvider SelfConfigProvider { get; set; }
  332. internal static void Load()
  333. {
  334. string pluginDirectory = UnityGame.PluginsPath;
  335. // Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL,
  336. // so we need to resort to P/Invoke
  337. string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);
  338. _bsPlugins = new List<PluginExecutor>();
  339. _ipaPlugins = new List<Old.IPlugin>();
  340. if (!Directory.Exists(pluginDirectory)) return;
  341. string cacheDir = Path.Combine(pluginDirectory, ".cache");
  342. if (!Directory.Exists(cacheDir))
  343. {
  344. Directory.CreateDirectory(cacheDir);
  345. }
  346. else
  347. {
  348. foreach (string plugin in Directory.GetFiles(cacheDir, "*"))
  349. {
  350. File.Delete(plugin);
  351. }
  352. }
  353. // initialize BSIPA plugins first
  354. _bsPlugins.AddRange(PluginLoader.LoadPlugins());
  355. var metadataPaths = PluginLoader.PluginsMetadata.Select(m => m.File.FullName).ToList();
  356. var ignoredPaths = PluginLoader.ignoredPlugins.Select(m => m.Key.File.FullName).ToList();
  357. var disabledPaths = DisabledPlugins.Select(m => m.File.FullName).ToList();
  358. //Copy plugins to .cache
  359. string[] originalPlugins = Directory.GetFiles(pluginDirectory, "*.dll");
  360. foreach (string s in originalPlugins)
  361. {
  362. if (metadataPaths.Contains(s)) continue;
  363. if (ignoredPaths.Contains(s)) continue;
  364. if (disabledPaths.Contains(s)) continue;
  365. string pluginCopy = Path.Combine(cacheDir, Path.GetFileName(s));
  366. #region Fix assemblies for refactor
  367. var module = ModuleDefinition.ReadModule(Path.Combine(pluginDirectory, s));
  368. foreach (var @ref in module.AssemblyReferences)
  369. { // fix assembly references
  370. if (@ref.Name == "IllusionPlugin" || @ref.Name == "IllusionInjector")
  371. {
  372. @ref.Name = "IPA.Loader";
  373. }
  374. }
  375. foreach (var @ref in module.GetTypeReferences())
  376. { // fix type references
  377. if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
  378. if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
  379. if (@ref.FullName == "IllusionPlugin.IBeatSaberPlugin") { @ref.Namespace = "IPA"; @ref.Name = nameof(IPlugin); }
  380. if (@ref.FullName == "IllusionPlugin.IEnhancedBeatSaberPlugin") { @ref.Namespace = "IPA"; @ref.Name = nameof(IEnhancedPlugin); }
  381. if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  382. if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  383. if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  384. if (@ref.FullName == "IllusionPlugin.Utils.ReflectionUtil") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
  385. if (@ref.FullName == "IllusionPlugin.Logging.Logger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  386. if (@ref.FullName == "IllusionPlugin.Logging.LogPrinter") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  387. if (@ref.FullName == "IllusionInjector.PluginManager") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
  388. if (@ref.FullName == "IllusionInjector.PluginComponent") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
  389. if (@ref.FullName == "IllusionInjector.CompositeBSPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
  390. if (@ref.FullName == "IllusionInjector.CompositeIPAPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
  391. if (@ref.FullName == "IllusionInjector.Logging.UnityLogInterceptor") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  392. if (@ref.FullName == "IllusionInjector.Logging.StandardLogger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  393. if (@ref.FullName == "IllusionInjector.Updating.SelfPlugin") @ref.Namespace = "IPA.Updating"; //@ref.Name = "";
  394. if (@ref.FullName == "IllusionInjector.Updating.Backup.BackupUnit") @ref.Namespace = "IPA.Updating.Backup"; //@ref.Name = "";
  395. if (@ref.Namespace == "IllusionInjector.Utilities") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
  396. if (@ref.Namespace == "IllusionInjector.Logging.Printers") @ref.Namespace = "IPA.Logging.Printers"; //@ref.Name = "";
  397. }
  398. module.Write(pluginCopy);
  399. #endregion
  400. }
  401. //Load copied plugins
  402. string[] copiedPlugins = Directory.GetFiles(cacheDir, "*.dll");
  403. foreach (string s in copiedPlugins)
  404. {
  405. var result = LoadPluginsFromFile(s);
  406. if (result == null) continue;
  407. _ipaPlugins.AddRange(result.NonNull());
  408. }
  409. Logger.log.Info(exeName);
  410. Logger.log.Info($"Running on Unity {Application.unityVersion}");
  411. Logger.log.Info($"Game version {UnityGame.GameVersion}");
  412. Logger.log.Info("-----------------------------");
  413. Logger.log.Info($"Loading plugins from {Utils.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}");
  414. Logger.log.Info("-----------------------------");
  415. foreach (var plugin in _bsPlugins)
  416. {
  417. Logger.log.Info($"{plugin.Metadata.Name} ({plugin.Metadata.Id}): {plugin.Metadata.Version}");
  418. }
  419. Logger.log.Info("-----------------------------");
  420. foreach (var plugin in _ipaPlugins)
  421. {
  422. Logger.log.Info($"{plugin.Name}: {plugin.Version}");
  423. }
  424. Logger.log.Info("-----------------------------");
  425. }
  426. private static IEnumerable<Old.IPlugin> LoadPluginsFromFile(string file)
  427. {
  428. var ipaPlugins = new List<Old.IPlugin>();
  429. if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
  430. return ipaPlugins;
  431. T OptionalGetPlugin<T>(Type t) where T : class
  432. {
  433. if (t.FindInterfaces((t, o) => t == (o as Type), typeof(T)).Length > 0)
  434. {
  435. try
  436. {
  437. T pluginInstance = Activator.CreateInstance(t) as T;
  438. return pluginInstance;
  439. }
  440. catch (Exception e)
  441. {
  442. Logger.loader.Error($"Could not load plugin {t.FullName} in {Path.GetFileName(file)}! {e}");
  443. }
  444. }
  445. return null;
  446. }
  447. try
  448. {
  449. Assembly assembly = Assembly.LoadFrom(file);
  450. foreach (Type t in assembly.GetTypes())
  451. {
  452. var ipaPlugin = OptionalGetPlugin<Old.IPlugin>(t);
  453. if (ipaPlugin != null)
  454. {
  455. ipaPlugins.Add(ipaPlugin);
  456. }
  457. }
  458. }
  459. catch (ReflectionTypeLoadException e)
  460. {
  461. Logger.loader.Error($"Could not load the following types from {Path.GetFileName(file)}:");
  462. Logger.loader.Error($" {string.Join("\n ", e.LoaderExceptions?.Select(e1 => e1?.Message).StrJP() ?? new string[0])}");
  463. }
  464. catch (Exception e)
  465. {
  466. Logger.loader.Error($"Could not load {Path.GetFileName(file)}!");
  467. Logger.loader.Error(e);
  468. }
  469. return ipaPlugins;
  470. }
  471. internal static class AppInfo
  472. {
  473. [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = false)]
  474. private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
  475. private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
  476. public static string StartupPath
  477. {
  478. get
  479. {
  480. StringBuilder stringBuilder = new StringBuilder(260);
  481. GetModuleFileName(NullHandleRef, stringBuilder, stringBuilder.Capacity);
  482. return stringBuilder.ToString();
  483. }
  484. }
  485. }
  486. #pragma warning restore CS0618 // Type or member is obsolete (IPlugin)
  487. }
  488. }