private static void GetKeyBindings(Object threadContext) { if (KeyBindingWatcherStartPreset != null) { KeyBindingWatcherStartPreset.StopWatching(); KeyBindingWatcherStartPreset.Dispose(); KeyBindingWatcherStartPreset = null; } var bindingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings"); if (!Directory.Exists(bindingsPath)) { Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {bindingsPath}"); } var startPresetPath = Path.Combine(bindingsPath, "StartPreset.4.start"); if (!File.Exists(startPresetPath)) { startPresetPath = Path.Combine(bindingsPath, "StartPreset.start"); } //Logger.Instance.LogMessage(TracingLevel.INFO, "bindings path " + bindingsPath); var bindsNames = ReadStartPreset(startPresetPath); Logger.Instance.LogMessage(TracingLevel.INFO, "key bindings " + string.Join(",", bindsNames)); var keyBindingPath = Path.GetDirectoryName(startPresetPath); Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #1 " + keyBindingPath); var keyBindingFileName = Path.GetFileName(startPresetPath); Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding file name #1 " + keyBindingFileName); KeyBindingWatcherStartPreset = new KeyBindingWatcher(keyBindingPath, keyBindingFileName); KeyBindingWatcherStartPreset.KeyBindingUpdated += HandleKeyBindingEvents; KeyBindingWatcherStartPreset.StartWatching(); if (bindsNames.Length == 4) // odyssey { Logger.Instance.LogMessage(TracingLevel.INFO, "odyssey key bindings"); HandleKeyBinding(BindingType.General, bindingsPath, bindsNames[0]); HandleKeyBinding(BindingType.Ship, bindingsPath, bindsNames[1]); HandleKeyBinding(BindingType.Srv, bindingsPath, bindsNames[2]); HandleKeyBinding(BindingType.OnFoot, bindingsPath, bindsNames[3]); } else // horizon { Logger.Instance.LogMessage(TracingLevel.INFO, "horizon key bindings"); HandleKeyBinding(BindingType.General, bindingsPath, bindsNames.First()); HandleKeyBinding(BindingType.Ship, bindingsPath, bindsNames.First()); HandleKeyBinding(BindingType.Srv, bindingsPath, bindsNames.First()); HandleKeyBinding(BindingType.OnFoot, bindingsPath, bindsNames.First()); } }
public static void GetKeyBindings() { if (KeyBindingWatcher1 != null) { KeyBindingWatcher1.StopWatching(); KeyBindingWatcher1.Dispose(); KeyBindingWatcher1 = null; } if (KeyBindingWatcher2 != null) { KeyBindingWatcher2.StopWatching(); KeyBindingWatcher2.Dispose(); KeyBindingWatcher2 = null; } var bindingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings"); if (!Directory.Exists(bindingsPath)) { Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {bindingsPath}"); } var startPresetPath = Path.Combine(bindingsPath, "StartPreset.start"); //Logger.Instance.LogMessage(TracingLevel.INFO, "bindings path " + bindingsPath); var bindsName = File.ReadAllText(startPresetPath); var keyBindingPath = Path.GetDirectoryName(startPresetPath); Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #1 " + keyBindingPath); var keyBindingFileName = Path.GetFileName(startPresetPath); Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding file name #1 " + keyBindingFileName); KeyBindingWatcher1 = new KeyBindingWatcher(keyBindingPath, keyBindingFileName); KeyBindingWatcher1.KeyBindingUpdated += HandleKeyBindingEvents; KeyBindingWatcher1.StartWatching(); var fileName = Path.Combine(bindingsPath, bindsName + ".3.0.binds"); if (!File.Exists(fileName)) { Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName); fileName = fileName.Replace(".3.0.binds", ".binds"); if (!File.Exists(fileName)) { Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName); bindingsPath = SteamPath.FindSteamEliteDirectory(); if (!string.IsNullOrEmpty(bindingsPath)) { fileName = Path.Combine(bindingsPath, bindsName + ".3.0.binds"); if (!File.Exists(fileName)) { Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName); fileName = fileName.Replace(".3.0.binds", ".binds"); if (!File.Exists(fileName)) { Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName); } } } } } if (File.Exists(fileName)) { var serializer = new XmlSerializer(typeof(UserBindings)); //Logger.Instance.LogMessage(TracingLevel.INFO, "using " + fileName); var reader = new StreamReader(fileName); Bindings = (UserBindings)serializer.Deserialize(reader); reader.Close(); keyBindingPath = Path.GetDirectoryName(fileName); Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #2 " + keyBindingPath); keyBindingFileName = Path.GetFileName(fileName); Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding file name #2 " + keyBindingFileName); KeyBindingWatcher2 = new KeyBindingWatcher(keyBindingPath, keyBindingFileName); KeyBindingWatcher2.KeyBindingUpdated += HandleKeyBindingEvents; KeyBindingWatcher2.StartWatching(); } }