Assembly resolving, fixes to crate dropping.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
@@ -134,5 +135,34 @@ namespace OpenRA.FileFormats
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static Dictionary<string, Assembly> assemblyCache = new Dictionary<string, Assembly>();
|
||||
|
||||
public static Assembly ResolveAssembly(object sender, ResolveEventArgs e)
|
||||
{
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (assembly.FullName == e.Name)
|
||||
return assembly;
|
||||
}
|
||||
|
||||
string[] frags = e.Name.Split(',');
|
||||
var filename = frags[0] + ".dll";
|
||||
Assembly a;
|
||||
if (assemblyCache.TryGetValue(filename, out a))
|
||||
return a;
|
||||
|
||||
if (FileSystem.Exists(filename))
|
||||
using (Stream s = FileSystem.Open(filename))
|
||||
{
|
||||
byte[] buf = new byte[s.Length];
|
||||
s.Read(buf, 0, buf.Length);
|
||||
a = Assembly.Load(buf);
|
||||
assemblyCache.Add(filename, a);
|
||||
return a;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user