-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleLoader.cs
More file actions
41 lines (33 loc) · 1.1 KB
/
ModuleLoader.cs
File metadata and controls
41 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Mono.Cecil;
namespace FEZStripGen
{
internal class ModuleLoader
{
private string workingDirectory;
public ModuleLoader(string workingDir)
{
workingDirectory = workingDir;
}
public bool ModuleExists(string name)
{
return File.Exists(Path.Combine(workingDirectory, name));
}
public ModuleDefinition LoadModule(string name)
{
var path = Path.Combine(workingDirectory, name);
DefaultAssemblyResolver asmResolver = new DefaultAssemblyResolver();
asmResolver.AddSearchDirectory(Path.GetDirectoryName(path));
var readerParams = new ReaderParameters()
{
AssemblyResolver = asmResolver
};
return ModuleDefinition.ReadModule(path, readerParams);
}
public void SaveModule(ModuleDefinition module, string name)
{
var path = Path.Combine(workingDirectory, name);
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? "");
module.Write(path);
}
}
}