Skip to content

Commit

Permalink
removed old, naive way of loading the last modified binds file by def…
Browse files Browse the repository at this point in the history
…ault

(or linking them to the plugin directory …)
  • Loading branch information
alterNERDtive committed Nov 8, 2020
1 parent 998b48d commit 3b918e8
Showing 1 changed file with 22 additions and 42 deletions.
64 changes: 22 additions & 42 deletions bindED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ public class bindEDPlugin
{
private static Dictionary<String, int> _map = null;

public static string VERSION = "2.0";
public static string VERSION = "3.0";

public static string VA_DisplayName() => $"bindED Plugin v{VERSION}-alterNERDtive";

public static string VA_DisplayInfo() => "bindED Plugin\r\n\r\n2016 VoiceAttack.com\r\n2020 alterNERDtive";

public static Guid VA_Id() => new Guid("{524B4B9A-3965-4045-A39A-A239BF6E2838}");

public static void VA_Init1(dynamic vaProxy) => LoadBinds(vaProxy, false);
public static void VA_Init1(dynamic vaProxy) => LoadBinds(vaProxy);

public static void VA_Invoke1(dynamic vaProxy) => LoadBinds(vaProxy, true);
public static void VA_Invoke1(dynamic vaProxy) => LoadBinds(vaProxy);

public static void VA_StopCommand() { }

public static void VA_Exit1(dynamic vaProxy) { }

private static String GetPluginPath(dynamic vaProxy) => Path.GetDirectoryName(vaProxy.PluginPath());

public static void LoadBinds(dynamic vaProxy, Boolean fromInvoke)
public static void LoadBinds(dynamic vaProxy)
{
String strDir = GetPluginPath(vaProxy);
string layout = vaProxy.GetText("bindED.layout");
Expand Down Expand Up @@ -74,51 +74,31 @@ public static void LoadBinds(dynamic vaProxy, Boolean fromInvoke)

String[] files = null;

if (fromInvoke)
if (!String.IsNullOrWhiteSpace(vaProxy.Context))
{
if (!String.IsNullOrWhiteSpace(vaProxy.Context))
{
files = ((String)vaProxy.Context).Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
}
else
{
String strBindsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings");
if (System.IO.Directory.Exists(strBindsDir))
{
FileInfo[] bindFiles = null;

string startFile = Path.Combine(strBindsDir, "StartPreset.start");
DirectoryInfo dirInfo = new DirectoryInfo(strBindsDir);
if (File.Exists(startFile))
{
bindFiles = dirInfo.GetFiles().Where(i => Regex.Match(i.Name, $@"{File.ReadAllText(startFile)}(\.3\.0)?\.binds$").Success).OrderByDescending(p => p.LastWriteTime).ToArray();
}

if ((bindFiles?.Count() ?? 0) == 0)
{
bindFiles = dirInfo.GetFiles().Where(i => i.Extension == ".binds").OrderByDescending(p => p.LastWriteTime).ToArray();
}

if (bindFiles.Count() > 0)
files = new string[] { bindFiles[0].FullName };
}
}
files = ((String)vaProxy.Context).Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
}
else
{
try
String strBindsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings");
if (System.IO.Directory.Exists(strBindsDir))
{
files = System.IO.Directory.GetFiles(strDir, "*.lnk", SearchOption.TopDirectoryOnly);
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
for (int i = 0; i < files.Count(); i++)
FileInfo[] bindFiles = null;

string startFile = Path.Combine(strBindsDir, "StartPreset.start");
DirectoryInfo dirInfo = new DirectoryInfo(strBindsDir);
if (File.Exists(startFile))
{
files[i] = ((IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(files[i])).TargetPath;
bindFiles = dirInfo.GetFiles().Where(i => Regex.Match(i.Name, $@"{File.ReadAllText(startFile)}(\.3\.0)?\.binds$").Success).OrderByDescending(p => p.LastWriteTime).ToArray();
}
}
catch (Exception ex)
{
vaProxy.WriteToLog("bindED Error - " + ex.Message, "red");
return;

if ((bindFiles?.Count() ?? 0) == 0)
{
bindFiles = dirInfo.GetFiles().Where(i => i.Extension == ".binds").OrderByDescending(p => p.LastWriteTime).ToArray();
}

if (bindFiles.Count() > 0)
files = new string[] { bindFiles[0].FullName };
}
}
try
Expand Down

0 comments on commit 3b918e8

Please sign in to comment.