Browse Source

Exposed a better API to check for currently installed mods

pull/46/head
Anairkoen Schno 6 years ago
parent
commit
25b19daccb
3 changed files with 74 additions and 17 deletions
  1. +40
    -13
      IPA.Loader/Loader/PluginManager.cs
  2. +33
    -3
      IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs
  3. +1
    -1
      IPA.Loader/Updating/ModsaberML/Updater.cs

+ 40
- 13
IPA.Loader/Loader/PluginManager.cs View File

@ -27,17 +27,23 @@ namespace IPA.Loader
{ {
#pragma warning disable CS0618 // Type or member is obsolete (IPlugin) #pragma warning disable CS0618 // Type or member is obsolete (IPlugin)
internal class BSPluginMeta
/// <summary>
/// A container object for all the data relating to a plugin.
/// </summary>
public class PluginInfo
{ {
public IBeatSaberPlugin Plugin { get; internal set; }
public string Filename { get; internal set; }
internal IBeatSaberPlugin Plugin { get; set; }
internal string Filename { get; set; }
/// <summary>
/// The Modsaber updating info for the mod, or null.
/// </summary>
public ModsaberModInfo ModsaberInfo { get; internal set; } public ModsaberModInfo ModsaberInfo { get; internal set; }
} }
/// <summary> /// <summary>
/// An <see cref="IEnumerable"/> of new Beat Saber plugins /// An <see cref="IEnumerable"/> of new Beat Saber plugins
/// </summary> /// </summary>
public static IEnumerable<IBeatSaberPlugin> BSPlugins
internal static IEnumerable<IBeatSaberPlugin> BSPlugins
{ {
get get
{ {
@ -48,8 +54,8 @@ namespace IPA.Loader
return _bsPlugins.Select(p => p.Plugin); return _bsPlugins.Select(p => p.Plugin);
} }
} }
private static List<BSPluginMeta> _bsPlugins = null;
internal static IEnumerable<BSPluginMeta> BSMetas
private static List<PluginInfo> _bsPlugins = null;
internal static IEnumerable<PluginInfo> BSMetas
{ {
get get
{ {
@ -60,10 +66,31 @@ namespace IPA.Loader
return _bsPlugins; return _bsPlugins;
} }
} }
/// <summary>
/// Gets info about the plugin with the specified name.
/// </summary>
/// <param name="name">the name of the plugin to get (must be an exact match)</param>
/// <returns>the plugin info for the requested plugin or null</returns>
public static PluginInfo GetPlugin(string name)
{
return BSMetas.Where(p => p.Plugin.Name == name).FirstOrDefault();
}
/// <summary>
/// Gets info about the plugin with the specified modsaber name.
/// </summary>
/// <param name="name">the modsaber name of the plugin to get (must be an exact match)</param>
/// <returns>the plugin info for the requested plugin or null</returns>
public static PluginInfo GetPluginFromModsaberName(string name)
{
return BSMetas.Where(p => p.ModsaberInfo.InternalName == name).FirstOrDefault();
}
/// <summary> /// <summary>
/// An <see cref="IEnumerable"/> of old IPA plugins /// An <see cref="IEnumerable"/> of old IPA plugins
/// </summary> /// </summary>
[Obsolete("I mean, IPlugin shouldn't be used, so why should this? Not renaming to extend support for old plugins.")]
public static IEnumerable<IPlugin> Plugins public static IEnumerable<IPlugin> Plugins
{ {
get get
@ -88,7 +115,7 @@ namespace IPA.Loader
// Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL, // Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL,
// so we need to resort to P/Invoke // so we need to resort to P/Invoke
string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath); string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);
_bsPlugins = new List<BSPluginMeta>();
_bsPlugins = new List<PluginInfo>();
_ipaPlugins = new List<IPlugin>(); _ipaPlugins = new List<IPlugin>();
if (!Directory.Exists(pluginDirectory)) return; if (!Directory.Exists(pluginDirectory)) return;
@ -155,7 +182,7 @@ namespace IPA.Loader
#endregion #endregion
} }
var selfPlugin = new BSPluginMeta
var selfPlugin = new PluginInfo
{ {
Filename = Path.Combine(Environment.CurrentDirectory, "IPA.exe"), Filename = Path.Combine(Environment.CurrentDirectory, "IPA.exe"),
Plugin = SelfPlugin.Instance Plugin = SelfPlugin.Instance
@ -194,13 +221,13 @@ namespace IPA.Loader
Logger.log.Info("-----------------------------"); Logger.log.Info("-----------------------------");
} }
private static Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>> LoadPluginsFromFile(string file, string exeName)
private static Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>> LoadPluginsFromFile(string file, string exeName)
{ {
List<BSPluginMeta> bsPlugins = new List<BSPluginMeta>();
List<PluginInfo> bsPlugins = new List<PluginInfo>();
List<IPlugin> ipaPlugins = new List<IPlugin>(); List<IPlugin> ipaPlugins = new List<IPlugin>();
if (!File.Exists(file) || !file.EndsWith(".dll", true, null)) if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
return new Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
T OptionalGetPlugin<T>(Type t) where T : class T OptionalGetPlugin<T>(Type t) where T : class
{ {
@ -280,7 +307,7 @@ namespace IPA.Loader
init.Invoke(bsPlugin, initArgs.ToArray()); init.Invoke(bsPlugin, initArgs.ToArray());
} }
bsPlugins.Add(new BSPluginMeta
bsPlugins.Add(new PluginInfo
{ {
Plugin = bsPlugin, Plugin = bsPlugin,
Filename = file.Replace("\\.cache", ""), // quick and dirty fix Filename = file.Replace("\\.cache", ""), // quick and dirty fix
@ -308,7 +335,7 @@ namespace IPA.Loader
Logger.loader.Error($"Could not load {Path.GetFileName(file)}! {e}"); Logger.loader.Error($"Could not load {Path.GetFileName(file)}! {e}");
} }
return new Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
} }
internal class AppInfo internal class AppInfo


+ 33
- 3
IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs View File

@ -14,11 +14,41 @@ namespace IPA
/// <summary> /// <summary>
/// The name the mod uses on ModSaber as an identifier. /// The name the mod uses on ModSaber as an identifier.
/// </summary> /// </summary>
public string InternalName { get; set; }
public string InternalName
{
get => _InternalName;
set
{
if (_InternalName == null)
{
_InternalName = value;
}
else
{
throw new Exception("Cannot change name one it has been set!");
}
}
}
private string _InternalName = null;
/// <summary> /// <summary>
/// The version of the currently installed mod. Used to compare to the version on ModSaber. Should be a valid SemVer version. /// The version of the currently installed mod. Used to compare to the version on ModSaber. Should be a valid SemVer version.
/// </summary> /// </summary>
public string CurrentVersion { get; set; }
public string CurrentVersion
{
get => _CurrentVersion;
set
{
if (_CurrentVersion == null)
{
_CurrentVersion = value;
}
else
{
throw new Exception("Cannot change version one it has been set!");
}
}
}
private string _CurrentVersion = null;
} }
} }

+ 1
- 1
IPA.Loader/Updating/ModsaberML/Updater.cs View File

@ -65,7 +65,7 @@ namespace IPA.Updating.ModsaberML
public bool MetaRequestFailed { get; set; } = false; public bool MetaRequestFailed { get; set; } = false;
public BSPluginMeta LocalPluginMeta { get; set; } = null;
public PluginInfo LocalPluginMeta { get; set; } = null;
public override string ToString() public override string ToString()
{ {


Loading…
Cancel
Save