Assembly resolving, fixes to crate dropping.

This commit is contained in:
Matthew Bowra-Dean
2010-03-19 17:50:27 +13:00
parent c2e9f41051
commit d471c602c7
4 changed files with 45 additions and 4 deletions

View File

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