mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Make BepInDependency implement ICacheable and hide ICacheable implementations
This commit is contained in:
1 parent
28e02654c4
commit
d41c90eb13
2 files changed
+26
-18
No files matched your search
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BepInEx.Logging;
|
||||
using BepInEx.Bootstrap;
|
||||
using Mono.Cecil;
|
||||
using Mono.Collections.Generic;
|
||||
|
||||
namespace BepInEx
|
||||
{
|
||||
@@ -66,7 +65,7 @@ namespace BepInEx
|
||||
/// This attribute specifies any dependencies that this plugin has on other plugins.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class BepInDependency : Attribute
|
||||
public class BepInDependency : Attribute, ICacheable
|
||||
{
|
||||
public enum DependencyFlags
|
||||
{
|
||||
@@ -120,12 +119,6 @@ namespace BepInEx
|
||||
MinimumVersion = new Version(MinimumDependencyVersion);
|
||||
}
|
||||
|
||||
internal BepInDependency(string DependencyGUID, DependencyFlags Flags, string MinimumDependencyVersion) : this(DependencyGUID, Flags)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(MinimumDependencyVersion))
|
||||
MinimumVersion = new Version(MinimumDependencyVersion);
|
||||
}
|
||||
|
||||
internal static IEnumerable<BepInDependency> FromCecilType(TypeDefinition td)
|
||||
{
|
||||
var attrs = MetadataHelper.GetCustomAttributes<BepInDependency>(td, true);
|
||||
@@ -137,6 +130,20 @@ namespace BepInEx
|
||||
return new BepInDependency(dependencyGuid, (DependencyFlags)secondArg);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
void ICacheable.Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(DependencyGUID);
|
||||
bw.Write((int)Flags);
|
||||
bw.Write(MinimumVersion.ToString());
|
||||
}
|
||||
|
||||
void ICacheable.Load(BinaryReader br)
|
||||
{
|
||||
DependencyGUID = br.ReadString();
|
||||
Flags = (DependencyFlags)br.ReadInt32();
|
||||
MinimumVersion = new Version(br.ReadString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace BepInEx.Contract
|
||||
|
||||
internal string TypeName { get; set; }
|
||||
|
||||
public void Save(BinaryWriter bw)
|
||||
void ICacheable.Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(TypeName);
|
||||
|
||||
@@ -35,14 +35,10 @@ namespace BepInEx.Contract
|
||||
var depList = Dependencies.ToList();
|
||||
bw.Write(depList.Count);
|
||||
foreach (var bepInDependency in depList)
|
||||
{
|
||||
bw.Write(bepInDependency.DependencyGUID);
|
||||
bw.Write((int)bepInDependency.Flags);
|
||||
bw.Write(bepInDependency.MinimumVersion.ToString());
|
||||
}
|
||||
((ICacheable)bepInDependency).Save(bw);
|
||||
}
|
||||
|
||||
public void Load(BinaryReader br)
|
||||
void ICacheable.Load(BinaryReader br)
|
||||
{
|
||||
TypeName = br.ReadString();
|
||||
|
||||
@@ -57,7 +53,12 @@ namespace BepInEx.Contract
|
||||
var depCount = br.ReadInt32();
|
||||
var depList = new List<BepInDependency>(depCount);
|
||||
for (int i = 0; i < depCount; i++)
|
||||
depList.Add(new BepInDependency(br.ReadString(), (BepInDependency.DependencyFlags) br.ReadInt32(), br.ReadString()));
|
||||
{
|
||||
var dep = new BepInDependency("");
|
||||
((ICacheable)dep).Load(br);
|
||||
depList.Add(dep);
|
||||
}
|
||||
|
||||
Dependencies = depList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user