From 3b918e89728f6ddf1bb291236656c4b9fa21cdb8 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sun, 8 Nov 2020 12:41:09 +0100 Subject: [PATCH] removed old, naive way of loading the last modified binds file by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (or linking them to the plugin directory …) --- bindED.cs | 64 +++++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/bindED.cs b/bindED.cs index 2e60512..1f5f678 100644 --- a/bindED.cs +++ b/bindED.cs @@ -11,7 +11,7 @@ public class bindEDPlugin { private static Dictionary _map = null; - public static string VERSION = "2.0"; + public static string VERSION = "3.0"; public static string VA_DisplayName() => $"bindED Plugin v{VERSION}-alterNERDtive"; @@ -19,9 +19,9 @@ public class bindEDPlugin 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() { } @@ -29,7 +29,7 @@ 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"); @@ -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