Skip to content

Commit f3807f7

Browse files
committed
ESPSharp can now be told where to look for master plugins
PluginDecompiler now uses PluginSearchLocations.csv to tell ESPSharp where to look for master plugins PluginSearchLocations.csv has 2 items per line, an absolute directory path and a boolean ('true' or 'false' only)
1 parent deda3c5 commit f3807f7

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

ESPSharp/ElderScrollsPlugin.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace ESPSharp
2020
public class ElderScrollsPlugin : IDisposable
2121
{
2222
public static List<ElderScrollsPlugin> LoadedPlugins = new List<ElderScrollsPlugin>();
23-
public static Dictionary<uint, List<RecordView>> LoadedRecordViews = new Dictionary<uint, List<RecordView>>();
23+
public static Dictionary<uint, List<RecordView>> LoadedRecordViews = new Dictionary<uint, List<RecordView>>();
24+
public static List<KeyValuePair<string, bool>> pluginLocations = new List<KeyValuePair<string, bool>>();
2425

2526
protected string name = "";
2627
public List<string> Masters = new List<string>();
@@ -203,13 +204,36 @@ protected void ReadMasters()
203204

204205
if (master == null)
205206
{
207+
string masterFile = FindMaster(masterData.FileName.Value);
208+
209+
if (masterFile == null) throw new FileNotFoundException(masterData.FileName.Value + " could not be found.");
210+
206211
master = new ElderScrollsPlugin(masterData.FileName.Value);
207-
master.Read(masterData.FileName.Value);
212+
master.Read(masterFile);
208213
}
209214

210215
Masters.Add(masterData.FileName.Value);
211216
}
212217
}
213218
}
219+
220+
protected string FindMaster(string masterToFind)
221+
{
222+
if (File.Exists(masterToFind))
223+
return masterToFind;
224+
225+
foreach (var kvp in pluginLocations)
226+
{
227+
string directory = kvp.Key;
228+
bool recursive = kvp.Value;
229+
230+
var file = Directory.EnumerateFiles(directory, masterToFind, recursive ? SearchOption.AllDirectories : SearchOption.AllDirectories).FirstOrDefault();
231+
232+
if (file != null)
233+
return file;
234+
}
235+
236+
return null;
237+
}
214238
}
215239
}

PluginDecompiler/Program.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,39 @@
66
using ESPSharp;
77
using System.IO;
88
using System.IO.MemoryMappedFiles;
9+
using Microsoft.Win32;
910

1011
class Program
1112
{
1213
static void Main(string[] args)
1314
{
15+
if (File.Exists("PluginSearchLocations.csv"))
16+
{
17+
using (FileStream stream = new FileStream("PluginSearchLocations.csv", FileMode.Open, FileAccess.Read))
18+
using (StreamReader reader = new StreamReader(stream))
19+
{
20+
string line;
21+
string file;
22+
bool recursive;
23+
24+
while(!reader.EndOfStream)
25+
{
26+
line = reader.ReadLine();
27+
var split = line.Split(',');
28+
if (split.Count() > 0)
29+
{
30+
file = split[0];
31+
if (split.Count() > 1)
32+
recursive = Boolean.Parse(split[1]);
33+
else
34+
recursive = false;
35+
36+
ElderScrollsPlugin.pluginLocations.Add(new KeyValuePair<string, bool>(file, recursive));
37+
}
38+
}
39+
}
40+
}
41+
1442
foreach (string file in args)
1543
{
1644
string outDir = Path.GetFileNameWithoutExtension(file);

0 commit comments

Comments
 (0)