Procházet zdrojové kódy

Make BepInDependency implement ICacheable and hide ICacheable implementations

ManlyMarco před 5 roky
rodič
revize
d41c90eb13
2 změnil soubory, kde provedl 26 přidání a 18 odebrání
  1. 17 10
      BepInEx/Contract/Attributes.cs
  2. 9 8
      BepInEx/Contract/PluginInfo.cs

+ 17 - 10
BepInEx/Contract/Attributes.cs

@@ -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>

+ 9 - 8
BepInEx/Contract/PluginInfo.cs

@@ -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;
 		}
 	}