Browse Source

Added checking of related files

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
19899412d8
4 changed files with 51 additions and 6 deletions
  1. +36
    -1
      IPA.Loader/Loader/PluginLoader.cs
  2. +2
    -5
      IPA.Loader/Loader/PluginManager.cs
  3. +3
    -0
      IPA.Loader/Loader/PluginManifest.cs
  4. +10
    -0
      IPA.Loader/Loader/PluginMetadata.cs

+ 36
- 1
IPA.Loader/Loader/PluginLoader.cs View File

@ -40,6 +40,7 @@ namespace IPA.Loader
Resolve();
ComputeLoadOrder();
FilterDisabled();
FilterWithoutFiles();
ResolveDependencies();
});
@ -232,6 +233,10 @@ namespace IPA.Loader
metadata.Manifest = JsonConvert.DeserializeObject<PluginManifest>(File.ReadAllText(manifest));
if (metadata.Manifest.Files.Length < 1)
Logger.loader.Warn($"Bare manifest {Path.GetFileName(manifest)} does not declare any files. " +
$"Dependency resolution and verification cannot be completed.");
Logger.loader.Debug($"Adding info for bare manifest {Path.GetFileName(manifest)}");
PluginsMetadata.Add(metadata);
}
@ -286,7 +291,8 @@ namespace IPA.Loader
internal enum Reason
{
Error, Duplicate, Conflict, Dependency,
Released, Feature, Unsupported
Released, Feature, Unsupported,
MissingFiles
}
internal struct IgnoreReason
{
@ -401,6 +407,35 @@ namespace IPA.Loader
PluginsMetadata = enabled;
}
private static void FilterWithoutFiles()
{
var enabled = new List<PluginMetadata>(PluginsMetadata.Count);
foreach (var meta in PluginsMetadata)
{
var passed = true;
foreach (var file in meta.AssociatedFiles)
{
if (!file.Exists)
{
passed = false;
ignoredPlugins.Add(meta, new IgnoreReason(Reason.MissingFiles)
{
ReasonText = $"File {Utils.GetRelativePath(file.FullName, UnityGame.InstallPath)} (declared by {meta.Name}) does not exist"
});
Logger.loader.Warn($"File {Utils.GetRelativePath(file.FullName, UnityGame.InstallPath)}" +
$" (declared by {meta.Name}) does not exist! Mod installation is incomplete, not loading it.");
break;
}
}
if (passed)
enabled.Add(meta);
}
PluginsMetadata = enabled;
}
internal static void ComputeLoadOrder()
{
#if DEBUG


+ 2
- 5
IPA.Loader/Loader/PluginManager.cs View File

@ -292,16 +292,15 @@ namespace IPA.Loader
else
{
foreach (string plugin in Directory.GetFiles(cacheDir, "*"))
{
File.Delete(plugin);
}
}
// initialize BSIPA plugins first
_bsPlugins.AddRange(PluginLoader.LoadPlugins());
var metadataPaths = PluginLoader.PluginsMetadata.Select(m => m.File.FullName).ToList();
var ignoredPaths = PluginLoader.ignoredPlugins.Select(m => m.Key.File.FullName).ToList();
var ignoredPaths = PluginLoader.ignoredPlugins.Select(m => m.Key.File.FullName)
.Concat(PluginLoader.ignoredPlugins.SelectMany(m => m.Key.AssociatedFiles.Select(f => f.FullName))).ToList();
var disabledPaths = DisabledPlugins.Select(m => m.File.FullName).ToList();
//Copy plugins to .cache
@ -328,8 +327,6 @@ namespace IPA.Loader
{ // fix type references
if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IBeatSaberPlugin") { @ref.Namespace = "IPA"; @ref.Name = nameof(IPlugin); }
if (@ref.FullName == "IllusionPlugin.IEnhancedBeatSaberPlugin") { @ref.Namespace = "IPA"; @ref.Name = nameof(IEnhancedPlugin); }
if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";


+ 3
- 0
IPA.Loader/Loader/PluginManifest.cs View File

@ -51,6 +51,9 @@ namespace IPA.Loader
[JsonProperty("icon", Required = Required.DisallowNull)]
public string IconPath = null;
[JsonProperty("files", Required = Required.DisallowNull)]
public string[] Files = Array.Empty<string>();
[Serializable]
public class LinksObject
{


+ 10
- 0
IPA.Loader/Loader/PluginMetadata.cs View File

@ -3,6 +3,7 @@ using IPA.Utilities;
using Mono.Cecil;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Version = SemVer.Version;
#if NET3
@ -61,6 +62,12 @@ namespace IPA.Loader
internal readonly List<Feature> InternalFeatures = new List<Feature>();
/// <summary>
/// A list of files (that aren't <see cref="File"/>) that are associated with this plugin.
/// </summary>
/// <value>a list of associated files</value>
public IReadOnlyList<FileInfo> AssociatedFiles { get; private set; }
internal bool IsSelf;
/// <summary>
@ -82,6 +89,9 @@ namespace IPA.Loader
Name = value.Name;
Version = value.Version;
Id = value.Id;
AssociatedFiles = value.Files
.Select(f => Path.Combine(UnityGame.InstallPath, f))
.Select(p => new FileInfo(p)).ToList();
}
}


Loading…
Cancel
Save