Skip to content

Commit

Permalink
ESPSharp can now be told where to look for master plugins
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
CGarrison89 committed Jul 23, 2015
1 parent deda3c5 commit f3807f7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
28 changes: 26 additions & 2 deletions ESPSharp/ElderScrollsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace ESPSharp
public class ElderScrollsPlugin : IDisposable
{
public static List<ElderScrollsPlugin> LoadedPlugins = new List<ElderScrollsPlugin>();
public static Dictionary<uint, List<RecordView>> LoadedRecordViews = new Dictionary<uint, List<RecordView>>();
public static Dictionary<uint, List<RecordView>> LoadedRecordViews = new Dictionary<uint, List<RecordView>>();
public static List<KeyValuePair<string, bool>> pluginLocations = new List<KeyValuePair<string, bool>>();

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

if (master == null)
{
string masterFile = FindMaster(masterData.FileName.Value);

if (masterFile == null) throw new FileNotFoundException(masterData.FileName.Value + " could not be found.");

master = new ElderScrollsPlugin(masterData.FileName.Value);
master.Read(masterData.FileName.Value);
master.Read(masterFile);
}

Masters.Add(masterData.FileName.Value);
}
}
}

protected string FindMaster(string masterToFind)
{
if (File.Exists(masterToFind))
return masterToFind;

foreach (var kvp in pluginLocations)
{
string directory = kvp.Key;
bool recursive = kvp.Value;

var file = Directory.EnumerateFiles(directory, masterToFind, recursive ? SearchOption.AllDirectories : SearchOption.AllDirectories).FirstOrDefault();

if (file != null)
return file;
}

return null;
}
}
}
28 changes: 28 additions & 0 deletions PluginDecompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,39 @@
using ESPSharp;
using System.IO;
using System.IO.MemoryMappedFiles;
using Microsoft.Win32;

class Program
{
static void Main(string[] args)
{
if (File.Exists("PluginSearchLocations.csv"))
{
using (FileStream stream = new FileStream("PluginSearchLocations.csv", FileMode.Open, FileAccess.Read))
using (StreamReader reader = new StreamReader(stream))
{
string line;
string file;
bool recursive;

while(!reader.EndOfStream)
{
line = reader.ReadLine();
var split = line.Split(',');
if (split.Count() > 0)
{
file = split[0];
if (split.Count() > 1)
recursive = Boolean.Parse(split[1]);
else
recursive = false;

ElderScrollsPlugin.pluginLocations.Add(new KeyValuePair<string, bool>(file, recursive));
}
}
}
}

foreach (string file in args)
{
string outDir = Path.GetFileNameWithoutExtension(file);
Expand Down

0 comments on commit f3807f7

Please sign in to comment.